Home Manual Reference Source
public class | source

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 .jsx or .ts.

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).

Params:

NameTypeAttributeDescription
filepath string

The path for the file.

extension string
  • optional
  • default: 'js'

The extension to validate.

Return:

string

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".

Params:

NameTypeAttributeDescription
list Array

A list of strings to format.

conjunction string
  • optional
  • default: 'or'

The conjunction to be added between the last two items.

Return:

string

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:

NameTypeAttributeDescription
string string

The target string where the placeholders will be replaced.

placeholders Object

A dictionary with its placholders and their values.

beforePlaceholder String
  • optional

Optional. The left limiter for the placeholder. This will end up on a regular expression, so if it includes special symbols ([]{}/.), they neeed to be escaped. The default value is \\[.

afterPlaceholder String
  • optional

Optional. The right limiter for the placeholder. This will end up on a regular expression, so if it includes special symbols ([]{}/.), they neeed to be escaped. The default value is \\[.

Return:

string