@barchart/common-js
Version:
Library of common JavaScript utilities
73 lines (72 loc) • 2.22 kB
TypeScript
/**
* Utility functions for strings.
*
* @public
* @module lang/string
*/
/**
* Adjusts a string, replacing the first character of each word with an uppercase
* character and all subsequent characters in the word with lowercase characters.
*
* @public
* @static
* @param {string} s
* @returns {string}
*/
export function startCase(s: string): string;
/**
* Adjust a string to use camel case, where the first letter of each word is replaced
* with a lower case character.
*
* @public
* @static
* @param {string} s
* @returns {string}
*/
export function camelCase(s: string): string;
/**
* If a string exceeds a desired length, it is truncated and a poor man's
* ellipsis (i.e. three periods) is appended. Otherwise, the original
* string is returned.
*
* @public
* @static
* @param {string} s
* @param {number} length
* @returns {string}
*/
export function truncate(s: string, length: number): string;
/**
* Adds leading characters to a string, until the string length is a desired size.
*
* @public
* @static
* @param {string} s - The string to pad.
* @param {number} length - The desired overall length of the string.
* @param {string} character - The character to use for padding.
* @returns {string}
*/
export function padLeft(s: string, length: number, character: string): string;
/**
* Replaces starting characters of a string with a mask character and optionally
* truncates the string.
*
* @public
* @static
* @param {string} s - The string to format.
* @param {string} mask - The character to use for masking.
* @param {number} show - The number of characters to preserve (of the left).
* @param {number=} length - The final length of the string (truncating characters of the right).
*/
export function mask(s: string, mask: string, show: number, length?: number | undefined): string;
/**
* Performs a simple token replacement on a string; where the tokens
* are braced numbers (e.g. {0}, {1}, {2}).
*
* @public
* @static
* @param {string} s - The string to format (e.g. 'my first name is {0} and my last name is {1}')
* @param {Array<string>} data - The replacement data
* @returns {string}
*/
export function format(s: string, ...data: Array<string>): string;