Utils
A set of generic utilities that can be used in any context.
Static Method Summary
Static Public Methods | ||
public static |
ensureExtension(filepath: string, extension: string): string This a helper for when projext deals with non-JS files, like |
|
public static |
humanReadableList(list: Array, conjunction: string): string Formats a list of strings into a _"human readable list". |
|
public static |
replacePlaceholders(string: string, placeholders: Object, beforePlaceholder: String, afterPlaceholder: String): string Replace a dictionary of given placeholders on a string. |
Static Public Methods
public static ensureExtension(filepath: string, extension: string): string source
This a helper for when projext deals with non-JS files, like .jsx
or .ts
. Given a path for
a file, the method will make sure that the extension used is the one specified (`js by
default).
Example:
console.log(Utils.ensureExtension('my/file/path.ts');
// Will output `my/file/path.js`
public static humanReadableList(list: Array, conjunction: string): string source
Formats a list of strings into a _"human readable list".
Example:
console.log(Utils.humanReadableList(['one', 'two', 'three']));
// Will output 'one, two or three'
console.log(Utils.humanReadableList(['one', 'two', 'three'], 'and'));
// Will output 'one, two and three'
public static replacePlaceholders(string: string, placeholders: Object, beforePlaceholder: String, afterPlaceholder: String): string source
Replace a dictionary of given placeholders on a string.
Params:
Name | Type | Attribute | Description |
string | string | The target string where the placeholders will be replaced. |
|
placeholders | Object | A dictionary with its placholders and their values. |
|
beforePlaceholder | String |
|
Optional. The left limiter for the placeholder. This will
end up on a regular expression, so if it includes special
symbols ( |
afterPlaceholder | String |
|
Optional. The right limiter for the placeholder. This will
end up on a regular expression, so if it includes special
symbols ( |