Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
sillvva/utilsA module containing general purpose utility functions
This package works with Node.js, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers, Deno




JSR Score
100%
Published
2 weeks ago (0.5.0)
A module containing general purpose utility functions and types
Abortable Promise
Abortable Promise
import { AbortablePromise } from "@sillvva/utils"; const promise = new AbortablePromise((resolve, reject) => { setTimeout(() => { resolve("Hello World"); }, 1000); }, { signal: AbortSignal.timeout(500) }); promise.then((result) => { console.log(result); // Hello World }).catch((error) => { console.log(error); // Error: The operation was aborted. });
Debounce
Debounce
import { debounce } from "@sillvva/utils"; const debouncedSearch = debounce((query: string) => { console.log("Searching for:", query); return `Results for ${query}`; }, 300); // Only the last call executes after 300ms debouncedSearch.call("hello").then(result => { console.log(result); // "Results for hello" });
isDefined
isDefined
import { isDefined } from "@sillvva/utils"; const values = [1, null, 2, undefined, 3]; // (number | null | undefined)[] const defined = values.filter(isDefined); // number[] console.log(defined); // [1, 2, 3]
Slugify
Slugify
import { slugify } from "@sillvva/utils"; const slug = slugify("Hello World"); console.log(slug); // hello-world
Sorter
Sorter
import { sorter } from "@sillvva/utils"; const fruits = ["apple", "Banana", "Orange", "banana"]; const sorted = fruits.toSorted(sorter); console.log(sorted); // ["apple", "banana", "Banana", "Orange"] const arrObjs = [{ id: 3 }, { id: 1 }, { id: 2 }]; const sortedObjs = arrObjs.toSorted((a, b) => sorter(a.id, b.id)); console.log(sortedObjs); // [{ id: 1 }, { id: 2 }, { id: 3 }]
Substring Count
Substring Count
import { substrCount } from "@sillvva/utils"; const text = "hello world hello"; const count = substrCount(text, "hello"); console.log(count); // 2 // With overlapping matches const overlapping = substrCount("aaaa", "aa", true); console.log(overlapping); // 3
Wait
Wait
import { wait } from "@sillvva/utils"; async function example() { console.log("Starting..."); await wait(1000); console.log("1 second later!"); }
Utility Types
Utility Types
import type { MapKeys, Prettify, Falsy, DictOrArray } from "@sillvva/utils"; // MapKeys - Extract key type from Map type MyMap = Map<string, number>; type Keys = MapKeys<MyMap>; // string // Prettify - Flatten intersection types type Ugly = { a: string } & { b: number }; type Pretty = Prettify<Ugly>; // { a: string; b: number } // Falsy - Type guard for falsy values function isFalsy(value: unknown): value is Falsy { return !value; } // DictOrArray - Handle objects or arrays function processData(data: DictOrArray) { if (Array.isArray(data)) { console.log("Processing array with", data.length, "items"); } else { console.log("Processing object with keys:", Object.keys(data)); } }
Built and signed on
GitHub Actions
Add Package
deno add jsr:@sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";
Import directly with a jsr specifier
import * as utils from "jsr:@sillvva/utils";
Add Package
pnpm i jsr:@sillvva/utils
pnpm dlx jsr add @sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";
Add Package
yarn add jsr:@sillvva/utils
yarn dlx jsr add @sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";
Add Package
vlt install jsr:@sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";
Add Package
npx jsr add @sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";
Add Package
bunx jsr add @sillvva/utils
Import symbol
import * as utils from "@sillvva/utils";