Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Utils

Index

Type aliases

AllowArray<T>: T | T[]

Type parameters

  • T

AllowReadonlyArray<T>: T | readonly T[]

Type parameters

  • T

AnyFunction: (...args: any[]) => any

Type declaration

    • (...args: any[]): any
    • Parameters

      • Rest ...args: any[]

      Returns any

DeepWriteable<T>: { -readonly [ P in keyof T]: DeepWriteable<T[P]> }

Type parameters

  • T

FinderOptions<TAttributes>: { attributes?: string[]; where?: WhereOptions<TAttributes> }

Type parameters

  • TAttributes

Type declaration

  • Optional attributes?: string[]
  • Optional where?: WhereOptions<TAttributes>
MakeNullishOptional<T>: Optional<T, NullishPropertiesOf<T>>

Makes all shallow properties of an object optional if they accept undefined or null as a value.

example
type MyOptionalType = MakeUndefinedOptional<{
id: number | undefined,
firstName: string,
lastName: string | null,
}>;

// is equal to

type MyOptionalType = {
// this property is optional.
id?: number | undefined,
firstName: string,
// this property is optional.
lastName?: string | null,
};

Type parameters

  • T: object

MappedFinderOptions<TAttributes>: Omit<FinderOptions<TAttributes>, "attributes"> & { attributes?: ([columnName: string, attributeName: string] | string)[] }

Type parameters

  • TAttributes

Nullish<T>: T | null | undefined

Makes the type accept null & undefined

Type parameters

  • T

NullishPropertiesOf<T>: { [ P in keyof T]-?: undefined extends T[P] ? P : null extends T[P] ? P : never }[keyof T]

Returns all shallow properties that accept undefined or null. Does not include Optional properties, only undefined or null.

example
type UndefinedProps = NullishPropertiesOf<{
id: number | undefined,
createdAt: string | undefined,
firstName: string | null, // nullable properties are included
lastName?: string, // optional properties are not included.
}>;

// is equal to

type UndefinedProps = 'id' | 'createdAt' | 'firstName';

Type parameters

  • T

PartlyRequired<T, K>: Omit<T, K> & Required<Pick<T, K>>

Type parameters

  • T

  • K: keyof T

Variables

TICK_CHAR: "`" = "`"

Functions

  • addTicks(s: string, tickChar?: string): string
  • Parameters

    • s: string
    • Optional tickChar: string

    Returns string

  • camelize(str: string): string
  • Parameters

    • str: string

    Returns string

  • camelizeIf(str: string, condition: boolean): string
  • Parameters

    • str: string
    • condition: boolean

    Returns string

  • camelizeObjectKeys(obj: {}): {}
  • Parameters

    • obj: {}
      • [key: string]: any

    Returns {}

    A new object with camel-cased keys

    • [key: string]: any
  • canTreatArrayAsAnd(arr: unknown[]): arr is (object | Where<typeof eq>)[]
  • Parameters

    • arr: unknown[]

    Returns arr is (object | Where<typeof eq>)[]

  • classToInvokable<Class>(constructor: Class): Callable<Class>
  • Wraps a constructor to not need the new keyword using a proxy. Only used for data types.

    Type parameters

    • Class: new (...args: any[]) => any

    Parameters

    • constructor: Class

      The class instance to wrap as invocable.

    Returns Callable<Class>

    Wrapped class instance.

  • cloneDeep<T>(obj: T, onlyPlain?: boolean): T
  • Type parameters

    • T: object

    Parameters

    • obj: T
    • Optional onlyPlain: boolean

    Returns T

  • combineTableNames(tableName1: string, tableName2: string): string
  • Parameters

    • tableName1: string
    • tableName2: string

    Returns string

  • Determine if the default value provided exists and can be described in a db schema using the DEFAULT directive.

    Parameters

    Returns boolean

  • defaults(objectIn: {}, ...sources: {}[]): object
  • Assigns own and inherited enumerable string and symbol keyed properties of source objects to the destination object.

    https://lodash.com/docs/4.17.4#defaults

    Note: This method mutates object.

    Parameters

    • objectIn: {}

      The destination object.

      • [key: string]: any
    • Rest ...sources: {}[]

      The source objects.

    Returns object

    Returns object.

  • flattenObjectDeep<T>(value: T): T extends object ? Flatten<T> : T
  • Receives a tree-like object and returns a plain object which depth is 1.

    • Input:

    { name: 'John', address: { street: 'Fake St. 123', coordinates: { longitude: 55.6779627, latitude: 12.5964313 } } }

    • Output:

    { name: 'John', address.street: 'Fake St. 123', address.coordinates.latitude: 55.6779627, address.coordinates.longitude: 12.5964313 }

    Type parameters

    • T

    Parameters

    • value: T

      an Object

    Returns T extends object ? Flatten<T> : T

    a flattened object

  • generateEnumName(tableName: string, columnName: string): string
  • Returns ENUM name by joining table and column name

    Parameters

    • tableName: string
    • columnName: string

    Returns string

  • getComplexKeys(obj: object): (string | symbol)[]
  • getComplexKeys

    Parameters

    • obj: object

    Returns (string | symbol)[]

    All keys including operators

  • getComplexSize(obj: object | any[]): number
  • getComplexSize

    Parameters

    • obj: object | any[]

    Returns number

    Length of object properties including operators if obj is array returns its length

  • getOperators(obj: object): symbol[]
  • getOperators

    Parameters

    • obj: object

    Returns symbol[]

    All operators properties of obj

  • intersects<T>(arr1: T[], arr2: T[]): boolean
  • Checks if 2 arrays intersect.

    Type parameters

    • T

    Parameters

    • arr1: T[]
    • arr2: T[]

    Returns boolean

  • isColString(value: string): boolean
  • Returns whether value is using the nested syntax for attributes.

    example
    isColString('$id$'); // true
    isColString('$project.name$'); // true
    isColString('name'); // false

    Parameters

    • value: string

      The attribute reference to check.

    Returns boolean

  • isPrimitive(val: any): val is string | number | boolean
  • Parameters

    • val: any

    Returns val is string | number | boolean

  • isWhereEmpty(obj: object): boolean
  • Returns true if a where clause is empty, even with Symbols

    Parameters

    • obj: object

    Returns boolean

  • joinSQLFragments(array: SQLFragment[]): string
  • Joins an array with a single space, auto trimming when needed.

    Certain elements do not get leading/trailing spaces.

    Parameters

    • array: SQLFragment[]

      The array to be joined. Falsy values are skipped. If an element is another array, this function will be called recursively on that array. Otherwise, if a non-string, non-falsy value is present, a TypeError will be thrown.

    Returns string

    The joined string.

  • mapValueFieldNames(dataValues: Record<string, any>, attributeNames: string[], ModelClass: ModelStatic<Model<any, any>>): Record<string, any>
  • Used to map field names in values

    Parameters

    • dataValues: Record<string, any>
    • attributeNames: string[]
    • ModelClass: ModelStatic<Model<any, any>>

    Returns Record<string, any>

  • mapWhereFieldNames(where: Record<string | symbol, any>, Model: ModelStatic<Model<any, any>>): object
  • Parameters

    Returns object

  • merge(...args: object[]): object
  • An alternative to _.merge, which doesn't clone its arguments.

    Does not mutate parameters.

    Cloning is a bad idea because options arguments may contain references to sequelize models - which again reference database libs which don't like to be cloned (in particular pg-native)

    Parameters

    • Rest ...args: object[]

    Returns object

  • mergeDefaults<T>(a: T, b: Partial<T>): T
  • Deeply merges object b into a. Mutates a.

    Same concept as _.merge, but doesn't overwrite properties that have already been assigned.

    Type parameters

    • T

    Parameters

    • a: T
    • b: Partial<T>

    Returns T

  • nameIndex(index: NameIndexIndex, tableName: NameIndexTableName): NameIndexIndex
  • Parameters

    • index: NameIndexIndex
    • tableName: NameIndexTableName

    Returns NameIndexIndex

  • now(dialect: string): Date
  • Parameters

    • dialect: string

    Returns Date

  • pluralize(str: string): string
  • Parameters

    • str: string

    Returns string

  • removeNullishValuesFromHash(hash: Record<string, any>, omitNull: boolean, options?: { allowNull?: string[] }): Record<string, any>
  • Removes entries from hash whose value is either null or undefined, unless omitNull is false or allowNull includes that key.

    Keys ending with 'Id' are never removed.

    Parameters

    • hash: Record<string, any>

      the object from which entries with nullish values will be removed.

    • omitNull: boolean

      if false, this method returns the object as-is

    • Optional options: { allowNull?: string[] }
      • Optional allowNull?: string[]

        A list of keys that must be preserved even if their value is null or undefined.

    Returns Record<string, any>

  • removeTicks(s: string, tickChar?: string): string
  • Parameters

    • s: string
    • Optional tickChar: string

    Returns string

  • removeTrailingSemicolon(str: string): string
  • Parameters

    • str: string

    Returns string

  • safeStringifyJson(stringifyTarget: any): string
  • Stringify a value as JSON with some differences:

    Parameters

    • stringifyTarget: any

      the value to stringify.

    Returns string

    the resulting json.

  • singularize(str: string): string
  • Parameters

    • str: string

    Returns string

  • spliceStr(str: string, index: number, count: number, add: string): string
  • Parameters

    • str: string
    • index: number
    • count: number
    • add: string

    Returns string

  • toDefaultValue(value: unknown, dialect: string): unknown
  • Parameters

    • value: unknown
    • dialect: string

    Returns unknown

  • underscore(str: string): string
  • Parameters

    • str: string

    Returns string

  • underscoredIf(str: string, condition: boolean): string
  • Parameters

    • str: string
    • condition: boolean

    Returns string

  • useInflection(newInflection: Inflection): void
  • Parameters

    • newInflection: Inflection

    Returns void

Generated using TypeDoc