Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "util"

Index

Type aliases

AnyVal

AnyVal: unknown

Utility constants and functions

CompareResult

CompareResult: -1 | 0 | 1

Container

Container: RawObject | RawArray

HashFunction

HashFunction: (v: AnyVal) => string

Custom function to hash values to improve faster comparaisons

Type declaration

RawArray

RawArray: Array<AnyVal>

RawObject

RawObject: Record<string, AnyVal>

Variables

Const JS_SIMPLE_TYPES

JS_SIMPLE_TYPES: JsType[] = [JsType.NULL,JsType.UNDEFINED,JsType.BOOLEAN,JsType.NUMBER,JsType.STRING,JsType.DATE,JsType.REGEXP,]

Const MAX_ARRAY_PUSH

MAX_ARRAY_PUSH: 50000 = 50000

Const MAX_INT

MAX_INT: 2147483647 = 2147483647

Const MAX_LONG

MAX_LONG: number = Number.MAX_SAFE_INTEGER

Const MIN_INT

MIN_INT: -2147483648 = -2147483648

Const MIN_LONG

MIN_LONG: number = Number.MIN_SAFE_INTEGER

Const MISSING

MISSING: {}

Type declaration

Const OBJECT_PROTOTYPE

OBJECT_PROTOTYPE: unknown = Object.getPrototypeOf({}) as AnyVal

Const OBJECT_TAG

OBJECT_TAG: "[object Object]" = "[object Object]"

Const OBJECT_TYPE_RE

OBJECT_TYPE_RE: RegExp = /^\[object ([a-zA-Z0-9]+)\]$/

Const OPERATOR_NAME_PATTERN

OPERATOR_NAME_PATTERN: RegExp = /^\$[a-zA-Z0-9_]+$/

Const inArray

inArray: (Anonymous function) = (() => {// if Array.includes is not supportedif (!Array.prototype.includes) {return (arr: RawArray, item: AnyVal): boolean =>isNaN(item as number) && !isString(item)? arr.some((v) => isNaN(v as number) && !isString(v)): arr.indexOf(item) > -1;}// defaultreturn (arr: Array<AnyVal>, item: AnyVal): boolean => arr.includes(item);})()

Const isArray

isArray: (Anonymous function) = Array.isArray || ((v) => v instanceof Array)

Functions

Const DEFAULT_HASH_FUNC

  • DEFAULT_HASH_FUNC(value: AnyVal): string

assert

  • assert(condition: boolean, message: string): void
  • Parameters

    • condition: boolean
    • message: string

    Returns void

cloneDeep

compare

encode

  • encode(value: AnyVal): string
  • Encode value to string using a simple non-colliding stable scheme.

    Parameters

    Returns string

ensureArray

filterMissing

  • Filter out all MISSING values from the object in-place

    Parameters

    Returns void

flatten

  • Flatten the array

    Parameters

    • xs: RawArray

      The array to flatten

    • depth: number

      The number of nested lists to iterate

    Returns RawArray

getType

  • Returns the name of type as specified in the tag returned by a call to Object.prototype.toString

    Parameters

    Returns string

Private getValue

groupBy

has

hashCode

  • Generate hash code This selected function is the result of benchmarking various hash functions. This version performs well and can hash 10^6 documents in ~3s with on average 100 collisions.

    Parameters

    Returns string | null

intersection

  • Returns the intersection between two arrays

    Parameters

    • a: RawArray

      The first array

    • b: RawArray

      The second array

    • Optional hashFunction: HashFunction

      Custom function to hash values, default the hashCode method

    Returns RawArray

    Result array

into

isBoolean

  • isBoolean(v: AnyVal): v is boolean

isDate

  • isDate(v: AnyVal): v is Date

isEmpty

isEqual

  • Determine whether two values are the same or strictly equivalent

    Parameters

    Returns boolean

    Result of comparison

isFunction

  • isFunction(v: AnyVal): boolean

isNil

isNull

isNumber

  • isNumber(v: AnyVal): v is number

isObject

  • isObject(v: AnyVal): boolean

isObjectLike

  • isObjectLike(v: AnyVal): boolean

isOperator

  • isOperator(name: string): boolean
  • Check whether the given name passes for an operator. We assume AnyVal field name starting with '$' is an operator. This is cheap and safe to do since keys beginning with '$' should be reserved for internal use.

    Parameters

    • name: string

    Returns boolean

isRegExp

  • isRegExp(v: AnyVal): v is RegExp

isString

  • isString(v: AnyVal): v is string

isUndefined

  • isUndefined(v: AnyVal): boolean

memoize

  • This is a generic memoization function

    This implementation uses a cache independent of the function being memoized to allow old values to be garbage collected when the memoized function goes out of scope.

    Parameters

    Returns Callback<AnyVal>

merge

  • Deep merge objects or arrays. When the inputs have unmergeable types, the source value (right hand side) is returned. If inputs are arrays of same length and all elements are mergable, elements in the same position are merged together. If AnyVal of the elements are unmergeable, elements in the source are appended to the target.

    Parameters

    Returns Container

normalize

notInArray

objectMap

removeValue

  • removeValue(obj: Container, selector: string): void
  • Removes an element from the container. If the selector resolves to an array and the leaf is a non-numeric key, the remove operation will be performed on objects of the array.

    Parameters

    • obj: Container

      object or array

    • selector: string

      dot separated path to element to remove

    Returns void

resolve

  • Resolve the value of the field (dot separated) on the given object

    Parameters

    Returns AnyVal

resolveGraph

  • Returns the full object to the resolved value given by the selector. This function excludes empty values as they aren't practically useful.

    Parameters

    Returns Container

setValue

  • Set the value of the given object field

    Parameters

    • obj: RawObject

      the object context

    • selector: string

      path to field

    • value: AnyVal

      the value to set

    Returns void

sortBy

  • Returns a (stably) sorted copy of list, ranked in ascending order by the results of running each value through iteratee

    This implementation treats null/undefined sort keys as less than every other type

    Parameters

    • collection: RawArray
    • keyFn: Callback<AnyVal>

      The sort key function used to resolve sort keys

    • Optional comparator: Comparator<AnyVal>

      The comparator function to use for comparing keys. Defaults to standard comparison via compare(...)

    Returns RawArray

    Returns a new sorted array by the given key and comparator function

traverse

  • traverse(obj: Container, selector: string, fn: Callback<void>, force?: boolean): void
  • Walk the object graph and execute the given transform function

    Parameters

    • obj: Container

      The object to traverse

    • selector: string

      The selector

    • fn: Callback<void>

      Function to execute for value at the end the traversal

    • Optional force: boolean

      Force generating missing parts of object graph

    Returns void

truthy

  • truthy(arg: AnyVal): boolean

union

unique

unwrap

Generated using TypeDoc