@hgargg-0710/one
Version:
A tiny npm library purposed for providing beautiful solutions to frequent miniature (one-line/one-expression) tasks for various JS datatypes.
56 lines (55 loc) • 2.06 kB
TypeScript
/**
* Returns a new string based off `x`, in which the first character is put through `.toUpperCase()`,
* and the remainder are put through `.toLowerCase()`
*
* If `x` is empty, returns empty string
*/
export declare const capitalize: (x?: string) => string;
/**
* Splits the string using `toExtract`, then joins it using `toReplaceWith`.
*
* `toReplaceWith` defaults to `""`
*/
export declare const extract: (string: string, toExtract: string | RegExp, toReplaceWith?: string) => string;
/**
* Counts the number of (non-intersecting) occurences of `substring` inside `string`
*/
export declare const count: (string: string, substring: string | RegExp) => number;
/**
* Creates a function for limiting the `string` with `maxlength` length,
* and (if the `.length` exceeds the `maxlength`), replacing the end with
* the `limitor`
*/
export declare const limit: (maxlength: number, limitor?: string) => (string?: string) => string;
/**
* Returns the entirety of the string, except for the last symbol
*/
export declare const lastOut: (x: string) => string;
/**
* Concatenates the `strings`, and returns the result
*/
export declare const concat: (...strings: string[]) => string;
/**
* Performs an algorithm of "covering" on the given strings, and returns the result.
*
* Covering on two strings `a, b` returns `a + b.slice(a.length)`,
* that is, replacing the first `a.length` characters of `b` with `a`,
* and concatenating the remainder.
*/
export declare const cover: (...strings: string[]) => string;
/**
* A function returning whether the given string is empty.
*/
export declare const isEmpty: (x: string) => boolean;
/**
* Returns the last index of a given string
*/
export declare const lastIndex: (x: string) => number;
/**
* Returns `x.charCodeAt(i)`. `i` defaults to 0
*/
export declare const charCodeAt: (x: string, i?: number) => number;
/**
* Consequently splits the given string `x` using `splitBy` delimiters, and returns the result.
*/
export declare const multiSplit: (x: string, splitBy: string[]) => string[];