Common
Cross-cutting utilities to compose functions, handle promises, manipulate wrappers/kinds, and apply runtime conversions shared by the whole library.
How to import?
All functions are exported from the main entry or via direct import (tree-shaking friendly).
import { pipe, when, clone } from "@duplojs/utils";
import * as DCommon from "@duplojs/utils/common";
import * as C from "@duplojs/utils/common";
import { pipe, when, clone } from "@duplojs/utils/common";Composition and piping
pipe
Composes synchronous functions by chaining a single input.
pipeCall
Neutralizes the first-argument inference of a function inside a pipe.
innerPipe
Prepares a reusable pipe that returns a function to apply later.
asyncPipe
Composes promises or FutureEither sequentially and returns a Promise.
asyncInnerPipe
Curried version of asyncPipe that returns a function ready to accept a value (sync or async).
forward
Convenient identity function in a chain to pass the value through unchanged.
forwardLog
Logs the value (tap) then returns it to continue the flow.
justReturn
Builds a constant function that always returns the same value.
Conditional control and predicates
when
Applies a transformation if the predicate is true (or if the type guard passes), otherwise returns the input.
whenNot
Inverts the condition and runs a function only when the predicate fails.
whenElse
Two typed branches (if/else) that return distinct outputs without losing the input type.
and
Combines multiple type guards / predicates into an intersection.
or
Combines multiple predicates into a union, handy to filter discriminated unions.
equal
Compares to one or multiple literal values with support for type guards on primitives.
isType
Type guard based on typeof, Array.isArray, iterables, etc.
instanceOf
Type guard based on one or more constructors (typed instanceof).
hasKinds
Type guard that checks a value carries all expected kinds.
hasSomeKinds
Type guard that checks a value carries at least one expected kind.
truthy
Type guard that keeps only truthy values.
falsy
Type guard that keeps only falsy values.
Loops
loop
Loop controlled by next / exit callbacks with access to the counter and the previous output.
asyncLoop
Async version of loop that accepts iterations returning promises.
Promises
externalPromise
Creates a promise with its resolve/reject methods exposed to be controlled from the outside.
promiseObject
Transforms an object of promises into a promise of an object with resolved, typed values.
Others
asyncRetry
Retries an async function until a condition is met (max retries, delay, optional logging).
sleep
Async pause to wait for a certain time.
memo
Evaluates a function only once and reuses the result (lazy memoization).
toJSON
Prepares a value for JSON serialization.
toTransform
Recursively applies toTransform methods to obtain a model ready to be transported.
toString
Converts a literal (number, boolean, bigint, etc.) into a typed template string.
stringToMillisecond
Parses durations ("10s", "2h", "1.5d", etc.) into milliseconds, with typed errors.
stringToBytes
Converts sizes ("10mb", "2gb", …) into a number of bytes.
escapeRegExp
Escapes special characters to build a regex from a safe string.
interpolation
Generates typed templates with {id} placeholders and a strict mapping of replacements.
wrapValue
Wraps a value in a marked container to identify it or avoid collisions.
isWrappedValue
Type guard to check whether a value is a WrappedValue.
isRuntimeWrappedValueKey
Checks whether a string key matches the runtime marker of a WrappedValue.
toWrappedValue
Ensures a value is wrapped (idempotent if already wrapped).
unwrap
Retrieves the inner value of a wrapper.
addWrappedProperties
Dynamically adds derived properties to a wrapped value.
clone
Deep, typed clone of a value (objects, arrays, etc.).
simpleClone
Light clone to quickly duplicate a value without advanced logic.
createEnum
Creates an immutable string enum with has and toTuple helpers.
globalStore
Typed global store (singleton per key) with read/write access.
builder
Helper to create immutable builders with typed accumulation and missing-method checks.
override
Defines named overrides (methods or default values) and applies them to an interface.
