Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "utils/helpers"

Index

Variables

Const cwd

cwd: string = process.cwd()

Alias for process.cwd().

Const isYarn

isYarn: any = commandExists.sync('yarn')

Checks if "yarn" is available.

Const pkgmgr

pkgmgr: "yarn" | "npm" = isYarn ? 'yarn' : 'npm'

Gets the current package manager.

Const spawn

spawn: spawn = cs

Cross spawn instance.

Const spawnSync

spawnSync: spawnSync = cs.sync

Cross spawn sync instance.

Functions

buildExample

  • buildExample(examples: string[], name?: string): string
  • Formats example menu items replacing {{name}} with provided value.

    Parameters

    • examples: string[]

      array of examples for help menu.

    • Default value name: string = "gobu"

      the name to replace {{name}} with.

    Returns string

buildMenu

  • Builds simple string for help menu.

    Parameters

    • obj: IMap<ICommand> | ICommand[] | ICommandItem[]

      object of commands or array of options to build menu for.

    • Default value name: string = "Gobu"

      name to replace in strings.

    • Default value tabs: number = 8

      the number of tabs after key name.

    Returns string

combineMenuItem

  • Reduces nested command key to single array.

    Type parameters

    • T

    Parameters

    • obj: IMap<ICommand>

      object containing commands.

    • key: keyof ICommand

      the nested array key to reduce.

    • Default value filter: string[] = []

    Returns T[]

filterModules

  • filterModules(modules: IMap<string>, filters?: string[]): { matched: string[]; unmatched: string[] }
  • Parses modules object building install/add string for modules to be installed.

    Parameters

    • modules: IMap<string>

      the object containing the modules to be installed.

    • Default value filters: string[] = []

      string array containing filters.

    Returns { matched: string[]; unmatched: string[] }

    • matched: string[]
    • unmatched: string[]

formatTemplate

  • formatTemplate(template: string, map: IMap<string>): string
  • Simple template format, uses "g" RegExp flag to replace all instances found.

    Parameters

    • template: string

      the template to be formatted.

    • map: IMap<string>

      the map containing key values to replace

    Returns string

getScopeByDir

  • Gets scope by matching directory.

    Parameters

    • dir: string

      the directory to use to match loaded scope.

    • scopes: IMap<IScope>

      object containing loaded scopes.

    Returns IScope

getScopeByName

  • Gets scope from collection by name.

    Parameters

    • name: string

      the scope name to be found.

    • scopes: IMap<IScope>

      the object collection of scopes.

    Returns IScope

getScopesByDir

  • Gets scope by matching directory.

    Parameters

    • dirs: string[]

      the directories to use to match loaded scope.

    • scopes: IMap<IScope>

      object containing loaded scopes.

    Returns IScope[]

getScopesByName

  • Gets scopes filtering by name.

    Parameters

    • names: string[]

      the names to compare for filtering scopes.

    • scopes: IMap<IScope>

      the scopes collection.

    Returns IScope[]

getScriptsByDir

  • Gets scripts for the provided scope.

    Parameters

    • dir: string

      the path to compare to known package paths.

    • scopes: IMap<IScope>

      the loaded scopes.

    Returns IMap<string>

getValueByKey

  • getValueByKey<T>(key: keyof T, val: string, map: IMap<any>): T
  • Gets scope by matching key and value.

    Type parameters

    • T

    Parameters

    • key: keyof T

      the key in the scope to match against.

    • val: string

      the value of the key to use to compare.

    • map: IMap<any>

      object containing values.

    Returns T

isScope

  • isScope(compare: string[], dir?: string): string
  • isScope(compare: string, dir?: string): string
  • Checks if a directory path is a known package directory.

    Parameters

    • compare: string[]

      array of known package paths.

    • Optional dir: string

      the directory path to inspect if is known.

    Returns string

  • Checks if a directory path is a known package directory.

    Parameters

    • compare: string

      a known package path.

    • Optional dir: string

      the directory path to inspect if is known.

    Returns string

merge

  • merge<T, S>(defaults: boolean, target: T, ...sources: T[]): T
  • merge<T, S>(target: T, ...sources: T[]): T
  • Merges object literals.

    Type parameters

    • T: object

    • S: object

    Parameters

    • defaults: boolean

      when true respects defaults.

    • target: T

      the target object to merge to.

    • Rest ...sources: T[]

      the source objects to merge from.

    Returns T

  • Merges object literals.

    Type parameters

    • T: object

    • S: object

    Parameters

    • target: T

      the target object to merge to.

    • Rest ...sources: T[]

      the source objects to merge from.

    Returns T

normalizeScopes

  • normalizeScopes(scopes?: string | string[]): string[]
  • Normalizes scopes to array ensuring correct format.

    Parameters

    • Default value scopes: string | string[] = []

      the scope or array of scopes passed from command.

    Returns string[]

parseArgv

  • parseArgv(): IKawkahParserResult

promise

  • promise<T>(prom: Promise<T>): Promise<{ data: T; err: Error }>
  • Wraps Promise returning object containing resulting data and/or Error.

    Type parameters

    • T

    Parameters

    • prom: Promise<T>

      the Promise to be wrapped.

    Returns Promise<{ data: T; err: Error }>

randomNumber

  • randomNumber(min: any, max: any, exclude?: number[]): any
  • Gets number within range.

    Parameters

    • min: any

      the minimum number

    • max: any

      the maximum number

    • Optional exclude: number[]

      numbers to exclude.

    Returns any

simpleClone

  • simpleClone<T>(obj: T): any
  • Simple usings JSON to clone a simple object.

    Type parameters

    • T: object

    Parameters

    • obj: T

      the object to be cloned

    Returns any

Generated using TypeDoc