@untemps/utils
v4.0.0
Published
Utils for @untemps packages
Readme
@untemps/utils
Utils for @untemps packages.
Documentation
A complete documentation of utils is available here: Docs
Installation
yarn add @untemps/utilsThis package ships with full TypeScript declarations. No additional @types/* package needed.
Requirements: Node.js >= 20.
Usage
ESM / TypeScript
import { isNil, interpolate, createElement } from '@untemps/utils'Per-module (tree-shakeable)
import { isNil } from '@untemps/utils/lang/isNil'
import { interpolate } from '@untemps/utils/string/interpolate'CommonJS
const { isNil } = require('@untemps/utils')Available utilities
Every utility is exported both from the package root and per-module at @untemps/utils/<category>/<name>. See the Docs for full signatures, parameters, and examples.
array
extractByIndices— extract values from an array at the given indices
async
debounce— delay invocation until after a quiet period; returns a function with.cancel()standby— return a promise that resolves after the given delaythrottle— invoke at most once per interval (leading + trailing); returns a function with.cancel()
dom
createElement— create a DOM element from a configuration object. Attributes whose value isnullorundefinedare ignored (no-op for those keys), mirroringmodifyElementdoElementsOverlap— check whether two DOM elements overlap on screengetCSSDeclaration— find a CSS rule by class name acrossdocument.styleSheets. Returns a snapshotRecord<string, string>of the declared properties (kebab-case keys, mirroring the CSS Object Model); mutating it has no effect on the live stylesheet. PassreturnText = trueto get the rawcssTextstring instead.getElement— query a DOM element by selectorisElement— check whether a value is a DOM elementmodifyElement— set attributes on a DOM element (by reference or selector). An attribute whose value isnullorundefinedis removed instead of being set, allowing the same call to add and remove attributes in one pass. ThrowsReferenceErrorwhen a selector matches nothing.removeElement— remove a DOM element (by reference or selector)resolveClassName— aggregate class names from strings or[condition, ifTrue, ifFalse]tuples
function
isFunction— check whether a value is a function
lang
isNil— check whether a value isnullorundefined
number
clamp— clamp a number between two boundsgetRandomInteger— return a pseudo-random integer in[min, max]normalizeMinMax— return{ min, max }withmin <= max, swapping the inputs if needed
object
deepClone— structured-clone deep copy. ThrowsDataCloneErroron functions, DOM nodes, or other non-cloneable values. UsedeepMergeif you need a lenient clone that keeps such values by reference.deepMerge— recursively mergesourceintotargetwith circular-reference support. Passtrueas the third argument to merge intotargetin place instead of producing a new object.isObject— check whether a value is a plain object
string
generateText— generate a string from a dictionary using configurable rulesgenerateTokenizedText— likegenerateTextbut also returns token indicesinterpolate— replace%key%-style tokens in a stringinterpolateLiteral— replace${key}-style tokens in a literal-like stringisString— check whether a value is a string
Development
The development toolchain targets Node 24, pinned via .nvmrc:
nvm useConsumers only need Node >= 20 (see Installation); the higher floor is for working on the project itself.
