core3-utils

npm version @wixc3/common on Github

Home > @wixc3/common

common package

Useful utils for strings, iterables, objects, maps, promises and other commonly used structures

Classes

Class Description
[ErrorWithCode](/core3-utils/common.errorwithcode.html) Creates an error with error code. Helpful when `instanceof` can't be used because the error was serialized and then deserialized.
[UnreachableCaseError](/core3-utils/common.unreachablecaseerror.html) Allows the type checker to detect non-exhaustive switch statements.

Enumerations

Enumeration Description
[NamingConvention](/core3-utils/common.namingconvention.html)

Functions

</tbody></table> ## Variables
Function Description
[addToSet(target, source)](/core3-utils/common.addtoset.html)
[assertIsString(value, errorMessage)](/core3-utils/common.assertisstring.html) Throws if value is not a string
[asyncNoop()](/core3-utils/common.asyncnoop.html)
[at(iterable, index)](/core3-utils/common.at.html) Finds element by index, including negative index
[awaitRecord(obj)](/core3-utils/common.awaitrecord.html) Awaits a record of promises, and returns a record of their results.
[capitalizeFirstLetter(val)](/core3-utils/common.capitalizefirstletter.html) Capitalize the first letter of a string
[chain(value)](/core3-utils/common.chain.html) Chain iterable operations, each acting on the output of the previous step
[chain(value)](/core3-utils/common.chain_1.html) Chain iterable operations, each acting on the output of the previous step
[clamp(value, min, max)](/core3-utils/common.clamp.html)
[concat(iterables)](/core3-utils/common.concat.html)
[createRandomIntWithSeed(seed)](/core3-utils/common.createrandomintwithseed.html)
[defaults(\_source, \_defaultValues, deep, shouldUseDefault)](/core3-utils/common.defaults.html) Returns an object where missing keys and values/keys that satisfy shouldUseDefault to the value in shouldUseDefault.
[delayed(fn, wait)](/core3-utils/common.delayed.html) Ensures `func` will be called with at least `wait` ms between runs.
[enforceSequentialExecution(fn)](/core3-utils/common.enforcesequentialexecution.html) Ensures that when the async function `fn` is called twice in a row, the second call only begins after the first one has finished (successfully or not).
[enumValues(enumObj)](/core3-utils/common.enumvalues.html)
[enumValues(enumObj)](/core3-utils/common.enumvalues_1.html)
[equalIdents(reference, modified, newline)](/core3-utils/common.equalidents.html) Matches the indentation of modified to the one of reference
[errorToPlainObject(error)](/core3-utils/common.errortoplainobject.html)
[escapeCSS(str)](/core3-utils/common.escapecss.html) Replaced non alphanumeric character with [CSS unicode representation](https://drafts.csswg.org/cssom/#escape-a-character-as-code-point)
[escapeRegExp(str)](/core3-utils/common.escaperegexp.html) Returns a string safe to be used in RegExp
[every(iterable, predicate)](/core3-utils/common.every.html)
[exclude(excluded)](/core3-utils/common.exclude.html)
[filter(iterable, predicate)](/core3-utils/common.filter.html)
[find(iterable, predicate)](/core3-utils/common.find.html)
[first(iterable)](/core3-utils/common.first.html) Picks the first element of an iterable
[flat(iterable, deep)](/core3-utils/common.flat.html)
[flatMap(iterable, mapFn)](/core3-utils/common.flatmap.html)
[forEach(iterable, fn)](/core3-utils/common.foreach.html)
[get(obj, key)](/core3-utils/common.get.html) Similar to Map.get, but works for plain objects, and returns undefined for null maps and missing keys
[get(obj, key)](/core3-utils/common.get_1.html)
[getCartesianProduct(arrays)](/core3-utils/common.getcartesianproduct.html)
[getErrorCode(error)](/core3-utils/common.geterrorcode.html) Returns error.code property if the error object has it, otherwise returns undefined.
[getIn(obj, path)](/core3-utils/common.getin.html)
[getOs()](/core3-utils/common.getos.html)
[getValue(map, key, errorMessage)](/core3-utils/common.getvalue.html) Returns a value by key, throws if the value is missing or the map null
[getValue(map, key, errorMessage)](/core3-utils/common.getvalue_1.html)
[getValue(map, key, errorMessage)](/core3-utils/common.getvalue_2.html)
[groupBy(elements, property)](/core3-utils/common.groupby.html) Groups elements by the value of a property
[has(obj, key)](/core3-utils/common.has.html) Similar to Map.has, but works for plain objects, and returns false for null maps
[has(obj, key)](/core3-utils/common.has_1.html) Similar to Map.has, but works for plain objects, and returns false for null maps
[has(obj, key)](/core3-utils/common.has_2.html)
[histogram(iterable)](/core3-utils/common.histogram.html) Calculate a histogram of iterable elements
[includes(iterable, item)](/core3-utils/common.includes.html)
[includesCaseInsensitive(str, substr)](/core3-utils/common.includescaseinsensitive.html) Checks if str contains substr ignoring capitalization
[indexToLineAndColumn(content, pos, newline)](/core3-utils/common.indextolineandcolumn.html) Finds line an column by position index
[isDefined(value)](/core3-utils/common.isdefined.html) Given a value of type Nullable, validates value is T </td></tr>
[isEmpty(iterable)](/core3-utils/common.isempty.html) Checks if an iterable is empty
[isErrorLikeObject(error)](/core3-utils/common.iserrorlikeobject.html) Checks if the `error` is an object compatible with the Error interface; that is, it has properties 'name' and 'message' of type string. The object could be an instance of an Error, or it could be some other kind of object that has these properties.
[isIterable(x)](/core3-utils/common.isiterable.html)
[isMap(m)](/core3-utils/common.ismap.html) Validates s is an instance of Map
[isObject(value)](/core3-utils/common.isobject.html) Checks if value is an object, e.g. a plain object, an array, a function, a regex, but not a primitive value. Common usage scenario: ```ts isObject(value) && value.foo === 'bar'; // Instead of: typeof value === 'object' && value !== null && 'foo' in value && value.foo === 'bar'; ```
[isPlainObject(value)](/core3-utils/common.isplainobject.html) Checks that value is a POJO
[isSet(s)](/core3-utils/common.isset.html) Validates s is an instance of Set
[isString(value)](/core3-utils/common.isstring.html) Checks is value is a string
[isValidNamingConvention(namingConvention)](/core3-utils/common.isvalidnamingconvention.html) Checks if namingConvention is supported
[join(iterable, separator)](/core3-utils/common.join.html)
[keys(map)](/core3-utils/common.keys.html)
[keys(map)](/core3-utils/common.keys_1.html)
[last(iterable)](/core3-utils/common.last.html) Picks the last element of an iterable
[map(iterable, mapFn)](/core3-utils/common.map.html) Map iterable elements
[mapKeys(obj, mapping)](/core3-utils/common.mapkeys.html) Maps values of a plain object
[mapObject(obj, mapping)](/core3-utils/common.mapobject.html) Maps key value pairs of a plain object
[mapValues(obj, mapping)](/core3-utils/common.mapvalues.html) Maps values of a plain object
[memoize(fn, argsHash)](/core3-utils/common.memoize.html)
[minimalIndent(str)](/core3-utils/common.minimalindent.html) Shifts all indentation to the left using the line with the least indentation as a baseline
[mulberry32(a)](/core3-utils/common.mulberry32.html)
[newMacrotask()](/core3-utils/common.newmacrotask.html)
[next(iterable, item)](/core3-utils/common.next.html) Find the element following an item
[noIdents(modified, separator)](/core3-utils/common.noidents.html) Remove line indentation (heading whitespace)
[noop()](/core3-utils/common.noop.html)
[normToRage(normal, min, max)](/core3-utils/common.normtorage.html)
[noWhiteSpace(str)](/core3-utils/common.nowhitespace.html) Remove white spaces including empty lines
[once(fn)](/core3-utils/common.once.html) Make a function executable only once, following calls are ignored
[partition(data, bucketsCount, predicate)](/core3-utils/common.partition.html) Partition unordered data into buckets of similar total weight
[pick(record, keys)](/core3-utils/common.pick.html) returns an object composed of the picked object properties
[prev(iterable, item)](/core3-utils/common.prev.html) Find the element before an item
[randomizedOrder(size)](/core3-utils/common.randomizedorder.html)
[reduce(iterable, reducer, initial)](/core3-utils/common.reduce.html)
[reportError\_2(ex)](/core3-utils/common.reporterror_2.html) Logs an error
[reverseObject(obj)](/core3-utils/common.reverseobject.html) Reverses keys-values of an object, ignoring falsy values. First takes on value collisions.
[same(a, b, unordered)](/core3-utils/common.same.html) Deep comparison of two objects
[seededRandomInt(min, max)](/core3-utils/common.seededrandomint.html)
[shuffle(array)](/core3-utils/common.shuffle.html) Shuffles an array
[size(iterable)](/core3-utils/common.size.html) Evaluate the size of an iterable
[skip(iterable, count)](/core3-utils/common.skip.html) Skips the first elements of an iterable
[some(iterable, predicate)](/core3-utils/common.some.html)
[sort(iterable, by)](/core3-utils/common.sort.html)
[splitIntoWords(str)](/core3-utils/common.splitintowords.html) Breaks down a string to words, dropping non letters and numbers
[stringifyErrorStack(error)](/core3-utils/common.stringifyerrorstack.html)
[swap(array, i, j)](/core3-utils/common.swap.html) Swaps elements of an array in place
[templateCompilerProvider(context)](/core3-utils/common.templatecompilerprovider.html) Similar to templated string, given a fixed context object returns a function that parses strings in it
[toCamelCase(str)](/core3-utils/common.tocamelcase.html) Converts a string to camelCase
[toCSSCamelCase(str)](/core3-utils/common.tocsscamelcase.html) like [toCamelCase()](/core3-utils/common.tocamelcase.html), but capitalizes first character if input starts with '-'
[toCSSKebabCase(str)](/core3-utils/common.tocsskebabcase.html) like [toKebabCase()](/core3-utils/common.tokebabcase.html), but prepends '-' if first character of input is UpperCase
[toError(value)](/core3-utils/common.toerror.html) Convert any kind of value to an error instance. Unless the value is already an error instance, it's stringified and used as the error message.
[toKebabCase(str)](/core3-utils/common.tokebabcase.html) Converts a string to kebab-case
[toMap(obj)](/core3-utils/common.tomap.html) Coverts and object into a Map
[toNamingConvention(str, namingConvention)](/core3-utils/common.tonamingconvention.html) Converts string formatting to a naming convention
[toPascalCase(str)](/core3-utils/common.topascalcase.html) Converts a string to PascalCase
[toPascalCaseJsIdentifier(str)](/core3-utils/common.topascalcasejsidentifier.html) Similar to [toPascalCase()](/core3-utils/common.topascalcase.html), but drops heading non-letters
[unique(iterable, by)](/core3-utils/common.unique.html) Creates iterable of unique elements
[values(map)](/core3-utils/common.values.html)
[values(map)](/core3-utils/common.values_1.html)
Variable Description
[isElectronRendererProcess](/core3-utils/common.iselectronrendererprocess.html)
[isMac](/core3-utils/common.ismac.html)
[isWindows](/core3-utils/common.iswindows.html)
[remap](/core3-utils/common.remap.html) remaps keys of obj based on rename map object,
## Type Aliases
Type Alias Description
[Awaited\_2](/core3-utils/common.awaited_2.html) The resolved value of T (if a promise, otherwise simply T)
[Chain](/core3-utils/common.chain.html)
[Flat](/core3-utils/common.flat.html)
[Iter](/core3-utils/common.iter.html)
[IterableChain](/core3-utils/common.iterablechain.html)
[Mapping](/core3-utils/common.mapping.html)
[MapValue](/core3-utils/common.mapvalue.html)
[NotIterable](/core3-utils/common.notiterable.html)
[Nullable](/core3-utils/common.nullable.html) T or null/undefined
[ObjValue](/core3-utils/common.objvalue.html)
[Predicate](/core3-utils/common.predicate.html)
[Remap](/core3-utils/common.remap.html)
[RemapFunc](/core3-utils/common.remapfunc.html)
[Remapped](/core3-utils/common.remapped.html)
[UnionToIntersection](/core3-utils/common.uniontointersection.html) Make an intersection type from union
[ValueChain](/core3-utils/common.valuechain.html)
[ValueOf](/core3-utils/common.valueof.html) union of all fields of T