Interface UtilModule

{@link http://gruntjs.com/api/grunt.util}

Index

Properties

Methods

Properties

public linefeed: string

The linefeed character, normalized for the current operating system. (\r\n on Windows, \n otherwise)

public namespace: any

public task: any

Methods

public callbackify(syncOrAsyncFunction: () => R): (callback: (result: R) => void) => void

Normalizes both "returns a value" and "passes result to a callback" functions to always pass a result to the specified callback. If the original function returns a value, that value will now be passed to the callback, which is specified as the last argument, after all other predefined arguments. If the original function passed a value to a callback, it will continue to do so.

Parameters

  • syncOrAsyncFunction: () => R

Returns

(callback: (result: R) => void) => void

public callbackify(syncOrAsyncFunction: (a: A) => R): (a: A, callback: (result: R) => void) => void

Parameters

  • syncOrAsyncFunction: (a: A) => R

Returns

(a: A, callback: (result: R) => void) => void

public callbackify(syncOrAsyncFunction: (a: A, b: B) => R): (a: A, b: B, callback: (result: R) => void) => void

Parameters

  • syncOrAsyncFunction: (a: A, b: B) => R

Returns

(a: A, b: B, callback: (result: R) => void) => void

public callbackify(syncOrAsyncFunction: (a: A, b: B, c: C) => R): (a: A, b: B, c: C, callback: (result: R) => void) => void

Parameters

  • syncOrAsyncFunction: (a: A, b: B, c: C) => R

Returns

(a: A, b: B, c: C, callback: (result: R) => void) => void

public callbackify(syncOrAsyncFunction: (a: A, b: B, c: C, d: D) => R): (a: A, b: B, c: C, d: D, callback: (result: R) => void) => void

Parameters

  • syncOrAsyncFunction: (a: A, b: B, c: C, d: D) => R

Returns

(a: A, b: B, c: C, d: D, callback: (result: R) => void) => void

public error(message: string, origError?: Error): Error

Return a new Error instance (that can be thrown) with the appropriate message. If an Error object is specified instead of message that object will be returned. Also, if an Error object is specified for origError and Grunt was run with the --debug 9 option, the original Error stack will be dumped.

Parameters

  • message: string
  • origError?: Error optional

Returns

Error

public error(error: Error, origError?: Error): Error

Parameters

  • error: Error
  • origError?: Error optional

Returns

Error

public error(error: any, origError?: Error): Error

Parameters

  • error: any
  • origError?: Error optional

Returns

Error

public kindOf(value: any): string

Return the "kind" of a value. Like typeof but returns the internal Class value. Possible results are "number", "string", "boolean", "function", "regexp", "array", "date", "error", "null", "undefined" and the catch-all "object".

Parameters

  • value: any

Returns

string

public normalizelf(str: string): string

Given a string, return a new string with all the linefeeds normalized for the current operating system. (\r\n on Windows, \n otherwise)

Parameters

  • str: string

Returns

string

public pluralize(n: number, str: string, separator?: string): string

Given str of "a/b", If n is 1, return "a" otherwise "b". You can specify a custom separator if '/' doesn't work for you.

Parameters

  • n: number
  • str: string
  • separator?: string optional

Returns

string

public recurse(object: any, callbackFunction: (value: any) => void, continueFunction: (objOrValue: any) => boolean)

Recurse through nested objects and arrays, executing callbackFunction for each non-object value. If continueFunction returns false, a given object or value will be skipped.

Parameters

  • object: any
  • callbackFunction: (value: any) => void
  • continueFunction: (objOrValue: any) => boolean

public repeat(n: number, str: string): string

Return string str repeated n times.

Parameters

  • n: number
  • str: string

Returns

string

public spawn(options: ISpawnOptions, done: (error: Error, result: grunt.util.ISpawnResult, code: number) => void): ISpawnedChild

Spawn a child process, keeping track of its stdout, stderr and exit code. The method returns a reference to the spawned child. When the child exits, the done function is called.

Parameters

  • options: ISpawnOptions
  • done: (error: Error, result: grunt.util.ISpawnResult, code: number) => void

    a function with arguments: error - If the exit code was non-zero and a fallback wasn't specified, an Error object, otherwise null. result - The result object is an code - The numeric exit code.

Returns

ISpawnedChild

public toArray(arrayLikeObject: any): Array<T>

Given an array or array-like object, return an array. Great for converting arguments objects into arrays.

Parameters

  • arrayLikeObject: any

Returns

Array<T>