Options
All
  • Public
  • Public/Protected
  • All
Menu

Module cast

Cast To Functions

castToFloat

  • castToFloat<OnFailType>(value: any, onFail?: OnFailType | number, toFixed?: number): OnFailType | number
  • name

    castToFloat

    description

    Typecast variable to float

    summary

    import { castToFloat } from "@corefunc/corefunc/cast/to/float";

    example

    castToFloat("16.5"); // => 16.5

    Type parameters

    • OnFailType

    Parameters

    • value: any
    • onFail: OnFailType | number = 0
    • Optional toFixed: number

    Returns OnFailType | number

castToFloatOrNull

  • castToFloatOrNull(variable: any, toFixed?: number): null | number
  • name

    castToFloatOrNull

    description

    Typecast variable to float or null if failed

    summary

    import { castToFloatOrNull } from "@corefunc/corefunc/cast/to/float-or-null";

    example

    castToFloatOrNull("16.5"); // => 16.5

    Parameters

    • variable: any
    • Optional toFixed: number

    Returns null | number

castToInt

  • castToInt(value: unknown, returnOnFail?: number, isNanFail?: boolean, shouldBeSafe?: boolean): number
  • name

    castToInt

    description

    Typecast variable to integer.

    Parameters

    • value: unknown
    • returnOnFail: number = 0
    • isNanFail: boolean = true
    • shouldBeSafe: boolean = true

    Returns number

    Any number.

castToIntOrNan

  • castToIntOrNan(value: any): number | typeof NaN
  • name

    castToIntOrNan

    description

    Typecast variable to integer or NaN if failed.

    summary

    import { castToIntOrNan } from "@corefunc/corefunc/cast/to/int-or-nan";

    example

    castToIntOrNan("16.5"); // => 16

    since

    0.3.21

    Parameters

    • value: any

    Returns number | typeof NaN

castToIntOrNull

  • castToIntOrNull(value: any): null | number
  • name

    castToIntOrNull

    description

    Typecast variable to integer or null if failed.

    summary

    import { castToIntOrNull } from "@corefunc/corefunc/cast/to/int-or-null";

    example

    castToIntOrNull("16.5"); // => 16

    Parameters

    • value: any

    Returns null | number

castToPercentOrNull

  • castToPercentOrNull(value: any): null | number
  • name

    castToPercentOrNull

    description

    Typecast variable to float or null if failed

    summary

    import { castToPercentOrNull } from "@corefunc/corefunc/cast/to/percent-or-null";

    example

    castToPercentOrNull("16.501"); // => 16.50

    Parameters

    • value: any

    Returns null | number

castToString

  • castToString(value: any): string
  • name

    castToString

    description

    Cast any value to string.

    example
    castToString(undefined) ➜ ""
    
    castToString(-0) ➜ "-0"
    

    Parameters

    • value: any

      Value to transform

    Returns string

    Value transformed into string

Other Functions

castMapToArray

  • castMapToArray(map: Map<any, any>): any[]
  • Parameters

    • map: Map<any, any>

    Returns any[]

castSetToArray

  • castSetToArray(set: Set<any>): any[]
  • Parameters

    • set: Set<any>

    Returns any[]

castToArray

  • castToArray(value: any): any[]
  • Creates a new Array instance from an array-like or iterable object This has different behaviour from Array.from.

    Parameters

    • value: any

    Returns any[]

castToRegExp

  • castToRegExp(pattern: RegExp | [string, string] | string): RegExp | undefined
  • Parameters

    • pattern: RegExp | [string, string] | string

    Returns RegExp | undefined

Generated using TypeDoc