Options
All
  • Public
  • Public/Protected
  • All
Menu

Module convert

Convert Functions

convertToError

  • convertToError(error: any): Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError
  • name

    convertToError

    description

    Converts anything to error.

    summary

    import { convertToError } from "@corefunc/corefunc/convert/to/error";

    since

    0.3.47

    Parameters

    • error: any

      Any value to convert to error.

    Returns Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError

Convert BigInt Functions

convertBigIntToJson

  • convertBigIntToJson(integer: BigInt): number | string
  • name

    convertBigIntToJson

    description

    Convert BigInt to JSON acceptable value.

    summary

    import { convertBigIntToJson } from '@corefunc/corefunc/convert/bigint/json';

    since

    0.1.67

    Parameters

    • integer: BigInt

    Returns number | string

    Number or string.

Convert Error Functions

convertErrorToJson

  • convertErrorToJson(error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>, shouldRemoveStackTrace?: boolean): Record<string, string>
  • name

    convertErrorToJson

    description

    Converts Error type to plain JSON object.

    since

    0.1.40

    Parameters

    • error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>
    • shouldRemoveStackTrace: boolean = false

    Returns Record<string, string>

convertErrorToObject

  • convertErrorToObject(error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>, shouldRemoveStackTrace?: boolean, shouldBeJson?: boolean): Record<string, any>
  • name

    convertErrorToObject

    description

    Converts Error type to plain object.

    since

    0.1.40

    Parameters

    • error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>
    • shouldRemoveStackTrace: boolean = true
    • shouldBeJson: boolean = false

    Returns Record<string, any>

convertErrorToString

  • convertErrorToString(error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>): string
  • name

    convertErrorToString

    description

    Converts error like object to string

    summary

    import { convertErrorToString } from "@corefunc/corefunc/convert/error/string";

    since

    0.3.4

    example

    convertErrorToString({ "message": "Undefined Error" }); ➜ "Undefined Error"

    Parameters

    • error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError | Record<string, any>

    Returns string

errorToCaller

  • errorToCaller(error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError): string
  • name

    errorToCaller

    description

    Converts Error type to caller name.

    summary

    import { errorToCaller } from "@corefunc/corefunc/convert/error/caller";

    since

    0.3.44

    Parameters

    • error: Error | EvalError | RangeError | ReferenceError | SyntaxError | TypeError | URIError

    Returns string

    • Function, class and method name. Or 'Module._compile' and 'ModuleJob.run' if root.

errorToMessage

  • errorToMessage(error: any, defaultMessage?: string): string
  • name

    errorToMessage

    description

    Transform value to string, extracts message from error, forces error message to be string.

    summary

    import { errorToMessage } from "@corefunc/corefunc/convert/error/message";

    since

    0.3.43

    Parameters

    • error: any

      Any value, but intended to be error.

    • Optional defaultMessage: string

      Default message.

    Returns string

    • Error message as string.

Convert Map Functions

convertMapToObject

  • convertMapToObject(map: Map<any, any>): Record<string, any>
  • name

    convertMapToObject

    description

    Convert Map to plain object.

    summary

    import { convertMapToObject } from '@corefunc/corefunc/convert/map/object';

    Parameters

    • map: Map<any, any>

    Returns Record<string, any>

    Plain object.

Convert Number Functions

convertNumberToJson

  • convertNumberToJson(value: BigInt | number | string, onFailure?: number | string): number | string
  • name

    convertNumberToJson

    description

    Convert BigInt, number or string to JSON acceptable value.

    summary

    import { convertNumberToJson } from '@corefunc/corefunc/convert/number/json';

    since

    0.1.70

    Parameters

    • value: BigInt | number | string
    • onFailure: number | string = 0

    Returns number | string

    Number or string.

Convert To Functions

convertToSingleLine

  • convertToSingleLine(record: any, prettify?: boolean): string
  • name

    convertToSingleLine

    description

    Convert any value to single line string.

    summary

    import { convertToSingleLine } from "@corefunc/corefunc/convert/to/single-line";

    since

    0.3.10

    Parameters

    • record: any

      Any plain value

    • prettify: boolean = false

    Returns string

    Single line string

Other Functions

convertArrayBufferToString

  • convertArrayBufferToString(buffer: ArrayBuffer): string
  • Parameters

    • buffer: ArrayBuffer

    Returns string

convertArrayToObject

  • convertArrayToObject(array: any[]): object
  • Converts Array to Object

    Parameters

    • array: any[]

    Returns object

convertStringToArrayBuffer

  • convertStringToArrayBuffer(text: string): ArrayBuffer
  • Parameters

    • text: string

    Returns ArrayBuffer

convertToFlag

  • convertToFlag(value: any, onEmpty?: boolean, onUnParsable?: boolean): boolean
  • name

    convertToFlag

    description

    Turns: undefined, null, 0, "0", "", "false", "FALSE", "n", "no", "of" to boolean false. Turns: 1, 1n, "1", "true", "TRUE", "on", "y", "yes" to boolean true.

    summary

    import { convertToFlag } from "@corefunc/corefunc/convert/to/flag";

    Parameters

    • value: any
    • onEmpty: boolean = false
    • onUnParsable: boolean = ...

    Returns boolean

convertToHash

  • convertToHash(value: any, asString: false, seed: number): number
  • convertToHash(value: any, asString: "true", seed: number): string
  • Parameters

    • value: any
    • asString: false
    • seed: number

    Returns number

  • Parameters

    • value: any
    • asString: "true"
    • seed: number

    Returns string

convertToJsonData

  • convertToJsonData(value: any, returnsUndefined?: boolean): boolean | null | number | string | undefined | unknown[] | Record<string, unknown>
  • name

    convertToJsonData

    description

    Convert to JSON-only valid data type: boolean, null, number, string, array, plain object

    since

    0.0.88

    Parameters

    • value: any
    • returnsUndefined: boolean = true

    Returns boolean | null | number | string | undefined | unknown[] | Record<string, unknown>

convertToPlainObject

  • convertToPlainObject(object: object): object
  • Parameters

    • object: object

    Returns object

Generated using TypeDoc