Options
All
  • Public
  • Public/Protected
  • All
Menu

Kawkah Parser

Index

Type aliases

KawkahParserType

KawkahParserType: keyof IKawkahParserToTypes

KawkahParserTypeHandler

KawkahParserTypeHandler<T>: (val: any) => T

Type parameters

  • T

Type declaration

    • (val: any): T
    • Parameters

      • val: any

      Returns T

Variables

Const ABORT_CHAR

ABORT_CHAR: "--" = '--'

Const ARG_DOT_NOTA

ARG_DOT_NOTA: RegExp = ...

Const ARG_OPT

ARG_OPT: RegExp = ...

Const ARG_OPT_ANY

ARG_OPT_ANY: RegExp = ...

Const ARG_REQ

ARG_REQ: RegExp = ...

Const ARG_REQ_ANY

ARG_REQ_ANY: RegExp = ...

Const DEFAULT_TYPE_VALUES

DEFAULT_TYPE_VALUES: { array: any[]; boolean: boolean; number: any; string: string } = ...

Type declaration

  • array: any[]
  • boolean: boolean
  • number: any
  • string: string

Const FLAG_COUNT

FLAG_COUNT: RegExp = ...

Const FLAG_DOT_NOTA

FLAG_DOT_NOTA: RegExp = ...

Const FLAG_EXP

FLAG_EXP: RegExp = ...

Const FLAG_EXP_ANY

FLAG_EXP_ANY: RegExp = ...

Const FLAG_SHORT

FLAG_SHORT: RegExp = ...

Const LIKE_BOOLEAN

LIKE_BOOLEAN: RegExp = ...

Const LIKE_HEX_NUMBER

LIKE_HEX_NUMBER: RegExp = ...

Const LIKE_NUMBER

LIKE_NUMBER: RegExp = ...

Const NEGATE_CHAR

NEGATE_CHAR: "no-" = 'no-'

Const PARSER_DEFAULTS

PARSER_DEFAULTS: IKawkahParserOptions = ...

Const SUPPORTED_TYPES

SUPPORTED_TYPES: string[] = ...

Const VARIADIC_CHAR

VARIADIC_CHAR: "..." = '...'

Const isType

isType: IKawkahParserIsType = ...

Const toType

toType: IKawkahParserToTypes = ...

Functions

default

  • Parses provided arguments or uses process.argv.

    example

    .parse('install /some/path --force);

    example

    .parse('sip show log -vvvvv) >> { v: 5 }

    example

    .parse('--user.name=Jim') >> { user: { name: 'Jim' } }

    Parameters

    • Optional argv: string | any[]

      string or array to be parsed.

    • Optional options: IKawkahParserOptions

      parser options.

    Returns IKawkahParserResult

ensureDefault

  • ensureDefault(val: any, def: any): any
  • Ensures a default value when current is undefined.

    Parameters

    • val: any

      the current value.

    • def: any

      the default value.

    Returns any

expandArgs

  • expandArgs(val: string | string[], match?: string[], safe?: string[]): string[]
  • Expand argument string into an array respecting space between special characters.

    NOTE: use \ to escape inner quotes.

    example

    'install --dir "/some/path" -f' >> ['install', '--dir', '/some/path', '-f']

    Parameters

    • val: string | string[]

      the arg string to split to array.

    • Optional match: string[]

      chars when matched ignore spaces withing these chars.

    • Optional safe: string[]

      same as match except these chars will be included in result.

    Returns string[]

expandOptions

  • expandOptions(val: string[], allowValues?: boolean): any[]
  • Expands options arguments into multiple singular arguments.

    example

    [-abc] becomes [-a, '-b', '-c']

    Parameters

    • val: string[]

      the value to be expanded.

    • Optional allowValues: boolean

      when true short flag groups can have values.

    Returns any[]

hasOwn

  • hasOwn(obj: object, key: string | number): boolean
  • Checks if object has own property key.

    Parameters

    • obj: object

      the object the key belongs to.

    • key: string | number

      the key to inspect.

    Returns boolean

isArg

  • isArg(val: any): boolean
  • Checks if a value contains arg tokens.

    example

    >> true

    example

    [arg] >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgAny

  • isArgAny(val: any): boolean
  • Checks globally if any in string is an arg expression.

    example

    'some string ' >> true

    example

    'other with string [arg]' >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgDotNotation

  • isArgDotNotation(val: any): boolean
  • Checks if argument contans dot notation.

    example

    [arg.a] >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgOptional

  • isArgOptional(val: any): boolean
  • Check if argument contains optional argument tokens.

    example

    [arg] >> true

    example

    >> false

    Parameters

    • val: any

      the value to be inspected.

    Returns boolean

isArgOptionalAny

  • isArgOptionalAny(val: any): boolean
  • Checks globally if any in string is an optional arg.

    example

    'some string [arg]' >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgRequired

  • isArgRequired(val: any): boolean
  • Checks if an argument contains required tokens.

    example

    >> true

    example

    [arg] >> false

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgRequiredAny

  • isArgRequiredAny(val: any): boolean
  • Checks globally if any in string is a required arg.

    example

    'some string ' >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isArgVariadic

  • isArgVariadic(val: any, variadic: string): any
  • Checks if an argument contains variadic characters.

    example

    [arg...] >> true

    Parameters

    • val: any

      the value to be inspected.

    • variadic: string

      the variadic char to check if exists.

    Returns any

isArgVariadicRequired

  • isArgVariadicRequired(val: any, variadic: string): any
  • Checks if an argument is variadic and also contains required tokens.

    example

    <arg...> >> true

    Parameters

    • val: any

      the value to inspect.

    • variadic: string

      the char representing variadic arguments.

    Returns any

isDotNotationFlag

  • isDotNotationFlag(val: any): boolean
  • Check if a flag option contains dot notation.

    example

    --config.cfg.c >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isFlag

  • isFlag(val: any): boolean
  • Checks if value is a flag option.

    example

    --flag or -f

    Parameters

    • val: any

      the value to inpsect.

    Returns boolean

isFlagAny

  • isFlagAny(val: any): boolean
  • Checks globally if any in string is a flag expression.

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isFlagCount

  • isFlagCount(val: any): boolean
  • Checks if a flag option is of type count.

    example

    -vvvvv >> true

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isFlagNext

  • isFlagNext(arr: string[], index: number): boolean
  • Checks if argument array contains a flag option next.

    example

    ['install', '--force'] index = 0 >> true

    Parameters

    • arr: string[]

      an array containing flags or arguments.

    • index: number

      the current index to inspect from.

    Returns boolean

isFlagPrev

  • isFlagPrev(arr: string[], index: number): boolean
  • Checks if the previous argument is a flag option.

    example

    ['--flag', ''] index = 1 >> true

    Parameters

    • arr: string[]

      an array containing flag and/or argument options.

    • index: number

      the current index to inspect from.

    Returns boolean

isFlagShort

  • isFlagShort(val: any): boolean
  • Checks if a flag option is of the short variety.

    example

    -f

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isLikeBoolean

  • isLikeBoolean(val: any): boolean
  • Checks if a val is boolean like.

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isLikeNumber

  • isLikeNumber(val: any): boolean
  • Checks if value is number like.

    Parameters

    • val: any

      the value to inspect.

    Returns boolean

isNegateFlag

  • isNegateFlag(val: any, negate: string): boolean
  • Checks if flag is that of negation.

    example

    --no-force >> true

    example

    --force >> false

    Parameters

    • val: any

      the value to inspect.

    • negate: string

      the negation char to check if exists.

    Returns boolean

isTruthyVariadic

  • isTruthyVariadic(val: any): boolean
  • Inspect variadic config value returning bool if truthy.

    Parameters

    • val: any

      the value to check.

    Returns boolean

parse

  • Parses provided arguments or uses process.argv.

    example

    .parse('install /some/path --force);

    example

    .parse('sip show log -vvvvv) >> { v: 5 }

    example

    .parse('--user.name=Jim') >> { user: { name: 'Jim' } }

    Parameters

    • Optional argv: string | any[]

      string or array to be parsed.

    • Optional options: IKawkahParserOptions

      parser options.

    Returns IKawkahParserResult

stripFlag

  • stripFlag(val: any, negate: string): any
  • Strips a flag of all tokens.

    example

    --user.name >> user.name

    example

    --no-force >> force (removes negation also)

    Parameters

    • val: any

      the value containing flag tokens to be stripped.

    • negate: string

      the negation char defined in options.

    Returns any

stripNegate

  • stripNegate(val: any, negate?: string): any
  • Strips negate chars from flag.

    Parameters

    • val: any

      the value to be stripped.

    • Optional negate: string

      the characters denoting negate.

    Returns any

stripTokens

  • stripTokens(val: any, negate?: string, variadic?: string): string
  • Strips all tokens from string.

    example

    'install

    [filename]' >> 'install dir filename'

    Parameters

    • val: any

      the val containing tokens to be stripped.

    • Optional negate: string

      the negation char used.

    • Optional variadic: string

      the variadic char used.

    Returns string

stripVariadic

  • stripVariadic(val: any, variadic?: string): any
  • Strips variadic chars from flag.

    Parameters

    • val: any

      the value to be stripped.

    • Optional variadic: string

    Returns any

toCamelcase

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

    Parameters

    • val: string

      the value to camelize

    • strict: boolean = true

      when true dot notation values ignored.

    Returns string

Generated using TypeDoc