Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KawkahUtils

Hierarchy

  • KawkahUtils

Index

Constructors

constructor

Properties

argsert

argsert: IArgsert

Private core

lokales

lokales: Lokales

Accessors

__

  • get __(): any

__n

  • get __n(): any

assert

  • get assert(): assert

Private options

Methods

arrayCompare

  • arrayCompare(source: any, compare: any): object
  • Inspects two arrays finding elements that are missing that are matches and those excluded from source.

    Parameters

    • source: any

      the source array.

    • compare: any

      the array to compare.

    Returns object

    • excluded: any
    • matched: any[]
    • missing: any

arrayEquals

  • arrayEquals(values: string[], compare: string[]): number
  • Array equals compares two arrays for matches then ensures same length.

    Parameters

    • values: string[]

      the array containing matchable values.

    • compare: string[]

      the comparator array containing actual values.

    Returns number

arrayExtend

  • Extends target array with source values if not already exists.

    Parameters

    • target: any

      the target array.

    • source: any

      the source array.

    • Optional filter: any[] | KawkahReduceCallback

      optional array of filters.

    • Optional fn: KawkahReduceCallback

      optional function called to normalize values.

    Returns any

arrayMatch

  • arrayMatch(source: any, compare: any): any[]
  • Compares two arrays returning matches.

    Parameters

    • source: any

      the source array to find matches from.

    • compare: any

      the array to compare for matches.

    Returns any[]

arrayPurge

  • arrayPurge(map: IKawkahMap<any>, key: string, ...items: string[]): any[]
  • Removes items from an array in a nested object.

    Parameters

    • map: IKawkahMap<any>

      an object to remove/purge from.

    • key: string

      the key of the array to purge items from.

    • Rest ...items: string[]

      a list of keys to be removed.

    Returns any[]

arrayUnique

  • arrayUnique(arr: any): any
  • Inspects array removing duplicates.

    Parameters

    • arr: any

      an array to inspect.

    Returns any

Private checkArgVariadicRequired

  • checkArgVariadicRequired(tokens: string[]): boolean
  • Checks if required variadic arg was erroneously specified.

    example

    .checkArgVariadicRequired('<tags...>);

    Parameters

    • tokens: string[]

      the expanded tokens.

    Returns boolean

Private checkDotnotationArg

  • checkDotnotationArg(tokens: string[]): boolean
  • Checks if has dot notation arg.

    Parameters

    • tokens: string[]

      the tokens to be inspected.

    Returns boolean

Private checkInvalidSequence

  • checkInvalidSequence(tokens: string[]): boolean
  • Ensures that required args do not follow optional ones.

    example

    .checkInvalidSequence('install

    [filename] ') >> true;

    Parameters

    • tokens: string[]

      array of matching arg types.

    Returns boolean

Private checkMultipleCommand

  • checkMultipleCommand(tokens: string[]): boolean
  • Checks if tokens contain multiple command args.

    example

    .checkMultipleCommand('command1 command2 [arg]');

    Parameters

    • tokens: string[]

      the tokens expanded into an array.

    Returns boolean

colorize

  • colorize(val: string, ...styles: AnsiStyles[]): string
  • Colorize with ansi styles.

    Parameters

    • val: string

      the value to apply styles to.

    • Rest ...styles: AnsiStyles[]

      the ansi styles to be applied.

    Returns string

copy

  • copy(obj: any, ...filter: string[]): object
  • Simple method to copy properties to new object (no deep). For ex: an Error object where stack/message aren't cloned.

    example

    .copy({ name: 'Joe', email: 'joe@mail.com' }, 'name');

    Parameters

    • obj: any

      an object which you want to copy properties of.

    • Rest ...filter: string[]

      an array of keys to filter if any.

    Returns object

datetime

  • datetime(format: string, utc?: boolean): string
  • datetime(date: Date, format?: string, utc?: boolean): string

expandArgs

  • expandArgs(tokens: string | string[]): string[]
  • Parameters

    • tokens: string | string[]

    Returns string[]

expandTokens

  • expandTokens(tokens: string | string[], ...filter: any[]): any[]
  • Normalize array expands args to an array and spreads single flag options.

    example

    .normalizeTokens(' -abc') >> ['', '-a', '-b', '-c']

    Parameters

    • tokens: string | string[]

      the token string to be normalized.

    • Rest ...filter: any[]

      an array of items to filter out.

    Returns any[]

flagHasValue

  • flagHasValue(arr: string[], index: number): string
  • Takes and array and inspects if flag is boolean or has a value.

    Parameters

    • arr: string[]

      the array of values to inspect.

    • index: number

      the index of the flag to inspect.

    Returns string

formatMessage

  • formatMessage(message: any, ...args: any[]): any
  • Formats message with string format tokens, objects or templates strings.

    Parameters

    • message: any

      the string or object to be formatted.

    • Rest ...args: any[]

      arguments used for format strings or templates.

    Returns any

getStyle

getSymbols

  • getSymbols(): object
  • Gets log symbols.

    Returns object

    • error: string
    • notify: string
    • ok: string
    • warning: string

hasTokens

  • hasTokens(val: string): boolean
  • Checks if a string contains tokens used in commands or options.

    example

    .hasTokens('--flag:f [value]') >> true

    Parameters

    • val: string

      the value to inspect.

    Returns boolean

isArgVariadic

  • isArgVariadic(val: any): any
  • Checks if token is an arg and has variadic tokens ([arg...]).

    Parameters

    • val: any

      the value to inspect.

    Returns any

isArgVariadicRequired

  • isArgVariadicRequired(val: any): any
  • Checks if token is an arg and has required variadic tokens (<arg...>).

    Parameters

    • val: any

      the value to inspect.

    Returns any

isExecutable

  • isExecutable(path: string): boolean
  • Checks if a path is executable.

    Parameters

    • path: string

      the path to be inspected.

    Returns boolean

isNegateFlag

  • isNegateFlag(val: any): boolean
  • Checks if flag is negated (--no-flag).

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isType

  • isType(type: string, val: any): any
  • Checks if value is a given type.

    Parameters

    • type: string

      the type key for inspecting.

    • val: any

      the value to inspect.

    Returns any

loadConfig

  • loadConfig(path: string, type?: "json" | "yaml"): any
  • Loads/reads a yaml or json configuration file.

    Parameters

    • path: string

      the path to the config file.

    • Optional type: "json" | "yaml"

      forces a specific file type.

    Returns any

parseArg

  • parseArg(arg: string, key?: string): object | object
  • Parses arg into options arguments.

    Parameters

    • arg: string

      the argument to be parsed.

    • Optional key: string

      the argument's key.

    Returns object | object

parseFlag

  • parseFlag(opt: string): object
  • Parses an option into a configuration object.

    Parameters

    • opt: string

      the option to be parsed.

    Returns object

    • alias: string[]
    • default: undefined
    • describe: undefined
    • name: string
    • required: boolean
    • token: undefined
    • type: undefined
    • value: object | object
    • variadic: boolean

parseName

  • parseName(name: string): string
  • Strips tokens and ensures camelcase.

    Parameters

    • name: string

      the name to be normalized.

    Returns string

parseTokens

  • parseTokens(tokens: string | string[], command?: string | boolean): object
  • Parses all tokens in string or array expanding into configurable options objects.

    Parameters

    • tokens: string | string[]

      the token string or array to be parsed.

    • Optional command: string | boolean

      the token command name.

    Returns object

    • _aliases: undefined[]
    • _args: undefined[]
    • _error: null
    • _keys: undefined[]
    • _name: undefined
    • _targs: undefined[]

pluralize

  • pluralize(val: string, count: number): string
  • pluralize(val: string, pluralizer: string, count: number): string
  • Pluralizes a string.

    Parameters

    • val: string

      the value to pluralize.

    • count: number

      the count to be inspected.

    Returns string

  • Pluralizes a string with custom pluralizer.

    Parameters

    • val: string

      the value to pluralize.

    • pluralizer: string

      the string to use to pluralize.

    • count: number

      the count to be inspected.

    Returns string

splitUsage

  • splitUsage(tokens: string): object
  • Splits usage string or tokens array separating the prefix from the actual usage string.

    Parameters

    • tokens: string

      the tokens containing usage.

    Returns object

    • prefix: any
    • usage: any

stripAnsi

  • stripAnsi(str: any): any
  • Strips ansi characters.

    Parameters

    • str: any

      the value to be stripped.

    Returns any

stripColors

  • stripColors(val: string): any
  • Strips colurs from string.

    Parameters

    • val: string

      the value to strip.

    Returns any

stripFlag

  • stripFlag(val: any): any
  • Removes flag tokens from value.

    Parameters

    • val: any

      the value to strip.

    Returns any

stripTokens

  • stripTokens(val: any): string
  • Strips all tokens from string.

    Parameters

    • val: any

      the value to strip.

    Returns string

toArg

  • toArg(val: string, required?: boolean, variadic?: number | boolean): string
  • Converts to arg token.

    Parameters

    • val: string

      the value to convert to arg token.

    • Optional required: boolean

      when true wraps arg as required token.

    • Optional variadic: number | boolean

    Returns string

toCamelcase

  • toCamelcase(val: string, strict?: boolean): string
  • Camelize string, ignore dot notation strings when strict.

    Parameters

    • val: string

      the value to camelize

    • Default value strict: boolean = true

      when true dot notation values ignored.

    Returns string

toFlag

  • toFlag(val: string): string
  • Converts a string to a flag token.

    Parameters

    • val: string

      the value to convert to flag token.

    Returns string

toNodeCallback

  • toNodeCallback(fn: Function): Function
  • Ensures a function has a callback.

    Parameters

    • fn: Function

      the function to normalize.

    Returns Function

toType

  • toType(type: any, val: any): any
  • Casts value to type.

    Parameters

    • type: any

      the type key to get.

    • val: any

      the value to be cast to type.

    Returns any

validateTokens

  • validateTokens(tokens: string[], command?: string): any
  • Validate tokens iterates checks ensuring the tokens are valid format and sequencing.

    example

    .isInvalidTokens('<required...>') >> false (no required variadic args) .isInvalidTokens('<arg.a>') >> false (no arg dot notation) .isInvalidTokens('[optional] ') >> false (required arg after optional) .isInvalidTokens('blog [tags...] [authors...]) >> false dupe variadic args. .isInvalidTokens('blog [tags...] [name]) >> variadic not last arg.

    Parameters

    • tokens: string[]

      the string or array of tokens to validate.

    • Optional command: string

    Returns any

Generated using TypeDoc