Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "type-descriptions"

Index

Functions

isBasicObject

  • isBasicObject(suspect: unknown): boolean
  • Returns true if suspect is truthy and typeof suspect === 'object' or 'function'.

    Parameters

    • suspect: unknown

      Value of any type to check.

    Returns boolean

isBasicTypeName

  • isBasicTypeName(suspect: string): boolean
  • Returns true if suspect is a string, that may be returned by application of typeof operator (e.g. 'number', 'undefined', 'function')

    Parameters

    • suspect: string

      Value af any type to check.

    Returns boolean

isBsonObjectIdString

  • isBsonObjectIdString(suspect: unknown): boolean
  • Returns true if suspect is a string of BSON object id format.

    remarks

    BSON format is the format used by MongoDB documents. This function doesn't depend on any libarary at all. You can safely validate id's even on the client side. The RegExp for this fucntion was taken from 'bson' npm package.

    Parameters

    • suspect: unknown

      Value of unknown type to validate.

    Returns boolean

isInEnum

  • isInEnum<TEnum>(typeScriptStringEnum: TEnum): isInTheGivenEnumeration
  • Returns a TypePredicate that checks whether given string enum values include its suspect.

    remarks

    Beware that this function accepts only string enums, e.g.:

    import * as Vts from 'vee-type-safe';
    enum UserRole {
         Guest    = 'guest',
         Standart = 'standart',
         Admin    = 'admin'
    }
    enum UserRoleNumber {
         Guest, Standart, Admin // implicit values: 0, 1, 2
    }
    
    Vts.mismatch({ role: 'guest' }, { role: Vts.isInEnum(UserRole) }); // ok
    Vts.mismatch({ role: 0 }, { role: Vts.isInEnum(UserRoleNumber) }); // compile error
    

    Type parameters

    Parameters

    • typeScriptStringEnum: TEnum

    Returns isInTheGivenEnumeration

isInteger

  • isInteger(suspect: unknown): boolean
  • Returns true if suspect is integer, i.e. doesn't have decimal part.

    Parameters

    • suspect: unknown

    Returns boolean

isIntegerGreaterOrEq

  • isIntegerGreaterOrEq(target: number): isNumberGreaterOrEqToTheGivenTarget
  • Returns a predicate that checks its suspect to be an integer, such that suspect >= target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberGreaterOrEqToTheGivenTarget

isIntegerGreaterThan

  • isIntegerGreaterThan(target: number): isIntegerGreaterThanTheGivenTarget
  • Returns a predicate that checks its suspect to be an integer, such that suspect > target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isIntegerGreaterThanTheGivenTarget

isIntegerLessOrEq

  • isIntegerLessOrEq(target: number): isIntegerLessOrEqToTheGivenTarget
  • Returns a predicate that checks its suspect to be an integer, such that suspect <= target.

    Parameters

    • target: number

      Number to check inequality to.

    Returns isIntegerLessOrEqToTheGivenTarget

isIntegerLessThan

  • isIntegerLessThan(target: number): isIntegerLessThanTheGivenTarget
  • Returns a predicate that checks its suspect to be an integer, such that suspect < target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isIntegerLessThanTheGivenTarget

isIntegerNotEqual

  • isIntegerNotEqual(target: number): isIntegerNotEqualToTheGivenTarget
  • Returns a predicate that checks its suspect to be an integer, such that suspect !== target.

    Parameters

    • target: number

      Number to check inequality to.

    Returns isIntegerNotEqualToTheGivenTarget

isIntegerWithinRange

  • isIntegerWithinRange(min: number, max: number): isIntegerWithinTheGivenRange
  • Returns a predicate which checks its suspect to be an integer within the range [min, max].

    Parameters

    • min: number

      Minimum value suspect can be.

    • max: number

      Maximum value suspect can be.

    Returns isIntegerWithinTheGivenRange

isIsoDateString

  • isIsoDateString(suspect: unknown): boolean
  • Checks that suspect is a string and it conforms to ISO 8601 format.

    Parameters

    • suspect: unknown

      Value of unknown type to check.

    Returns boolean

    True if suspect is a string containing a date in ISO 8601 format. Internally uses 'is-iso-date' npm package.

isNegativeInteger

  • isNegativeInteger(suspect: unknown): boolean
  • Returns true if suspect is integer, and suspect < 0

    Parameters

    • suspect: unknown

    Returns boolean

isNegativeNumber

  • isNegativeNumber(suspect: unknown): boolean
  • Returns true if suspect is number, and suspect < 0

    Parameters

    • suspect: unknown

    Returns boolean

isNilOr

isNull

  • isNull(suspect: unknown): boolean

isNullOr

  • isNullOr<TTypeDescr>(typeDescr: TTypeDescr): Set<TTypeDescr | isNull>

isNumberGreaterOrEq

  • isNumberGreaterOrEq(target: number): isNumberGreaterOrEqToTheGivenTarget
  • Returns a predicate that checks its suspect to be a number, such that suspect >= target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberGreaterOrEqToTheGivenTarget

isNumberGreaterThan

  • isNumberGreaterThan(target: number): isNumberGreaterThanTheGivenTarget
  • Returns a predicate that checks its suspect to be a number, such that suspect > target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberGreaterThanTheGivenTarget

isNumberLessOrEq

  • isNumberLessOrEq(target: number): isNumberLessOrEqToTheGivenTarget
  • Returns a predicate that checks its suspect to be a number, such that suspect <= target.

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberLessOrEqToTheGivenTarget

isNumberLessThan

  • isNumberLessThan(target: number): isNumberLessThanTheGivenTarget
  • Returns a predicate that checks its suspect to be a number, such that suspect < target

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberLessThanTheGivenTarget

isNumberNotEqual

  • isNumberNotEqual(target: number): isNumberNotEqualToTheGivenTarget
  • Returns a predicate that checks its suspect to be a number, such that suspect !== target.

    Parameters

    • target: number

      Number to check inequality to.

    Returns isNumberNotEqualToTheGivenTarget

isNumberWithinRange

  • isNumberWithinRange(min: number, max: number): isNumberWithinTheGivenRange
  • Returns a predicate which checks its suspect to be a number within the range [min, max].

    Parameters

    • min: number

      Minimum value suspect can be.

    • max: number

      Maximum value suspect can be.

    Returns isNumberWithinTheGivenRange

isOneOf

  • isOneOf<T>(possibleValues: T[]): isOneOfTheGivenPossibleValues
  • Returns a predicate that accepts a suspect of any type and matches it to one of the provided possible values by

    possibleValues.includes(suspect)

    Type parameters

    • T

    Parameters

    • possibleValues: T[]

      Array with values of any type, suspect is matched to.

    Returns isOneOfTheGivenPossibleValues

isPositiveInteger

  • isPositiveInteger(suspect: unknown): boolean
  • Returns true if suspect is integer, and suspect > 0

    Parameters

    • suspect: unknown

    Returns boolean

isPositiveNumber

  • isPositiveNumber(suspect: unknown): boolean
  • Returns true if suspect is number, and suspect > 0

    Parameters

    • suspect: unknown

    Returns boolean

isUndefined

  • isUndefined(suspect: unknown): boolean

isZero

  • isZero(suspect: unknown): boolean
  • Returns true if suspect is number and suspect === 0

    Parameters

    • suspect: unknown

    Returns boolean

isZeroOrNegativeInteger

  • isZeroOrNegativeInteger(suspect: unknown): boolean
  • Returns true if suspect is integer, and suspect <= 0

    Parameters

    • suspect: unknown

    Returns boolean

isZeroOrNegativeNumber

  • isZeroOrNegativeNumber(suspect: unknown): boolean
  • Returns true if suspect is number, and suspect <= 0

    Parameters

    • suspect: unknown

    Returns boolean

isZeroOrPositiveInteger

  • isZeroOrPositiveInteger(suspect: unknown): boolean
  • Returns true if suspect is integer, and suspect >= 0

    Parameters

    • suspect: unknown

    Returns boolean

isZeroOrPositiveNumber

  • isZeroOrPositiveNumber(suspect: unknown): boolean
  • Returns true if suspect is number, and suspect >= 0

    Parameters

    • suspect: unknown

    Returns boolean

optional

  • optional<TTypeDescr>(typeDescr: TTypeDescr): Set<"undefined" | TTypeDescr>
  • Retuns tdSet(['undefined', typeDescr]))

    Type parameters

    Parameters

    • typeDescr: TTypeDescr

      TypeDescription that will be united with 'undefined' TD.

    Returns Set<"undefined" | TTypeDescr>

td

  • td<TTypeDescr>(typeDescr: TTypeDescr): TTypeDescr
  • A noop function, that leverages literal strings of BasicTypeName shape to be of string literal types.

    Type parameters

    Parameters

    • typeDescr: TTypeDescr

      Type description to return.

    Returns TTypeDescr

tdSet

  • tdSet<TTypeDescrs>(typeDescrs: TTypeDescrs[]): Set<TTypeDescrs>
  • A shorthand for new Set([...typeDescrs]). It also makes TypeScript to preserve BasicTypeName string literal types.

    Type parameters

    Parameters

    • typeDescrs: TTypeDescrs[]

      TypeDescriptions that define a union of types that suspect may have.

    Returns Set<TTypeDescrs>

Generated using TypeDoc