Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser.
Intended to be used in conjunction with @sv443-network/userutils and @sv443-network/djsutils, but can be used independently as well.
Documentation β’ Features β’ Installation β’ License β’ Changelog
- Array:
- π£
function randomItem()- Returns a random item from the given array - π£
function randomItemIndex()- Returns a random array item and index as a tuple - π£
function randomizeArray()- Returns a new array with the items in random order - π£
function takeRandomItem()- Returns a random array item and mutates the array to remove it - π£
function takeRandomItemIndex()- Returns a random array item and index as a tuple and mutates the array to remove it - π·
type NonEmptyArray- Non-empty array type
- π£
- Colors:
- π£
function darkenColor()- Darkens the given color by the given percentage - π£
function hexToRgb()- Converts a hex color string to an RGB object - π£
function lightenColor()- Lightens the given color by the given percentage - π£
function rgbToHex()- Converts an RGB object to a hex color string
- π£
- Crypto:
- π£
function abtoa()- Converts an ArrayBuffer to a string - π£
function atoab()- Converts a string to an ArrayBuffer - π£
function compress()- Compresses the given string using the given algorithm and encoding - π£
function decompress()- Decompresses the given string using the given algorithm and encoding - π£
function computeHash()- Computes a string's hash using the given algorithm - π£
function randomId()- Generates a random ID of the given length
- π£
- DataStore: - Cross-platform, general-purpose, sync/async hybrid, JSON-serializable database infrastructure:
- π§
class DataStore- The main class for the data store- π·
type DataStoreOptions- Options for the data store - π·
type DataMigrationsDict- Dictionary of data migration functions - π·
type DataStoreData- The type of the serializable data
- π·
- π§
class DataStoreSerializer- Serializes and deserializes data for multiple DataStore instances- π·
type DataStoreSerializerOptions- Options for the DataStoreSerializer - π·
type LoadStoresDataResult- Result of callingloadStoresData() - π·
type SerializedDataStore- Meta object and serialized data of a DataStore instance - π·
type StoreFilter- Filter for selecting data stores
- π·
- π§
class DataStoreEngine- Base class for DataStore storage engines, which handle the data storage- π·
type DataStoreEngineDSOptions- Reduced version ofDataStoreOptions
- π·
- Storage Engines:
- π§
class BrowserStorageEngine- Storage engine for browser environments (localStorage, sessionStorage)- π·
type BrowserStorageEngineOptions- Options for the browser storage engine
- π·
- π§
class FileStorageEngine- File-based storage engine for Node.js and Deno- π·
type FileStorageEngineOptions- Options for the file storage engine
- π·
- π§
- π§
- Debouncer:
- π£
function debounce()- Function wrapper for theDebouncerclass - π§
class Debouncer- Class that manages listeners whose calls are rate-limited- π·
type DebouncerType- The triggering type for the debouncer - π·
type DebouncedFunction- Function type that is returned by thedebounce()function - π·
type DebouncerEventMap- Event map type for theDebouncerclass
- π·
- π£
- Errors:
- π§
class DatedError- Base error class with adateproperty- π§
class ChecksumMismatchError- Error thrown when two checksums don't match - π§
class MigrationError- Error thrown in a failed data migration - π§
class ValidationError- Error while validating data
- π§
- π§
- Math:
- π£
function bitSetHas()- Checks if a bit is set in a bitset - π£
function clamp()- Clamps a number between a given range - π£
function digitCount()- Returns the number of digits in a number - π£
function formatNumber()- Formats a number to a string using the given locale and format identifier- π·
type NumberFormat- Number format identifier
- π·
- π£
function mapRange()- Maps a number from one range to another - π£
function overflowVal()- Makes sure a number is in a range by over- & underflowing it - π£
function randRange()- Returns a random number in the given range - π£
function roundFixed()- Rounds the given number to the given number of decimal places - π£
function valsWithin()- Checks if the given numbers are within a certain range of each other
- π£
- Misc:
- π£
function consumeGen()- Consumes aValueGenobject- π·
type ValueGen- A value that can be either type T, or a sync or async function that returns T
- π·
- π£
function consumeStringGen()- Consumes aStringGenobject- π·
type StringGen- A value that can be either of type string, or a sync or async function that returns a string
- π·
- π£
function fetchAdvanced()- Wrapper aroundfetch()with options like a timeout- π·
type FetchAdvancedOpts- Options for thefetchAdvanced()function
- π·
- π£
function getListLength()- Returns the length of aListLikeobject- π·
type ListLike- Any value with a quantifiablelength,countorsizeproperty
- π·
- π£
function pauseFor()- Pauses async execution for the given amount of time - π£
function pureObj()- Applies an object's props to a null object (object without prototype chain) or just returns a new null object - π£
function setImmediateInterval()- LikesetInterval(), but instantly calls the callback and supports passing anAbortSignal - π£
function setImmediateTimeoutLoop()- Like a recursivesetTimeout()loop, but instantly calls the callback and supports passing anAbortSignal - π£
function scheduleExit()- Schedules a process exit after the next event loop tick, to allow operations like IO writes to finish.
- π£
- NanoEmitter:
- π§
class NanoEmitter- Simple, lightweight event emitter class that can be used in both FP and OOP, inspired byEventEmitterfromnode:events, based onnanoevents- π·
type NanoEmitterOptions- Options for theNanoEmitterclass
- π·
- π§
- Text:
- π£
function autoPlural()- Turns the given term into its plural form, depending on the given number or list length - π£
function capitalize()- Capitalizes the first letter of the given string - π£
function createProgressBar()- Creates a progress bar string with the given percentage and length- π©
const defaultPbChars- Default characters for the progress bar - π·
type ProgressBarChars- Type for the progress bar characters object
- π©
- π£
function joinArrayReadable()- Joins the given array into a string, using the given separators and last separator - π£
function secsToTimeStr()- Turns the given number of seconds into a string in the format(hh:)mm:sswith intelligent zero-padding - π£
function truncStr()- Truncates the given string to the given length
- π£
- Misc. Types:
- π·
type LooseUnion- A union type that allows for autocomplete suggestions as well as substitutions of the same type - π·
type ListLike- Any value with a quantifiablelength,countorsizeproperty - π·
type Newable- Any class reference that can be instantiated withnew - π·
type NonEmptyArray- Non-empty array type - π·
type NonEmptyString- String type with at least one character - π·
type NumberFormat- Number format identifier - π·
type Prettify- Makes the structure of a type more readable by fully expanding it (recursively) - π·
type SerializableVal- Any value that can be serialized to JSON - π·
type StringGen- A value that can be either of type string, or a sync or async function that returns a string - π·
type ValueGen- A value that can be either the generic type T, or a sync or async function that returns T - π·
type Stringifiable- Any value that can be implicitly converted to a string
- π·
Note
π£ = function
π§ = class
π· = type
π© = const
- If you are using Node.js or Deno, install the package from NPM or JSR via your favorite package manager:
npm i @sv443-network/coreutils
pnpm i @sv443-network/coreutils
yarn add @sv443-network/coreutils
npx jsr install @sv443-network/coreutils
deno add jsr:@sv443-network/coreutils- If you are in a DOM environment, you can include the UMD bundle using your favorite CDN (after inserting the version number):
<script src="https://cdn.jsdelivr.net/npm/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
<script src="https://unpkg.com/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
<script src="https://esm.sh/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>- Then, import parts of the library as needed:
// >> EcmaScript Modules (ESM):
// - import parts of the library:
import { randomItem } from "@sv443-network/coreutils";
// - or import the full library:
import * as CoreUtils from "@sv443-network/coreutils";
// - or import raw TS files, after installing via JSR:
import { DataStore } from "jsr:@sv443-network/coreutils/lib/DataStore.ts";
// >> CommonJS (CJS):
// - import parts of the library:
const { debounce } = require("@sv443-network/coreutils");
// - or import the full library:
const CoreUtils = require("@sv443-network/coreutils");
// >> Universal Module Definition (UMD):
// - to make the global variable `CoreUtils` available, import this file:
// "@sv443-network/coreutils/dist/CoreUtils.min.umd.js"
// - or import the library on your HTML page:
// <script src="https://cdn.jsdelivr.net/npm/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
// (make sure to insert the version number above. Use 'latest' (not recommended) or a specific version, e.g. '9.4.3')Made with β€οΈ by Sv443
If you like this userscript, please consider supporting the development
Β© 2025 Sv443 & Sv443 Network
MIT license