atomic-fns
Version:
Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.
191 lines (185 loc) • 4.93 kB
TypeScript
/**
* This module includes utilities for working with strings.
*
* @module string
*/
/**
* Converts only the first character of the given string to upper case. Note that the rest of the characters are preserved.
* @param {string} s The string
* @returns {string} Returns the sentence string.
* @example
```js
sentenceCase('a test')
// 'A test'
sentenceCase('TEST')
// 'TEST'
```
* @see {@link capitalize}
*/
export declare function sentenceCase(s: string): string;
/**
* Converts the first character of the given string to upper case and the rest to lower case.
* @param {string} s The string to capitalize
* @returns {string} Returns the capitalized string.
* @example
```js
capitalize('TEST')
// 'Test'
```
* @see {@link titleCase}
*/
export declare function capitalize(s: string): string;
/**
* Split a string into an array of its words.
* @param {string} s The string to split
* @param {RegExp | string} [pattern] The pattern to match words
* @returns {string[]} Returns the words array.
* @example
```js
words('lord of the rings')
// ['lord', 'of', 'the', 'rings']
```
*/
export declare function words(s: string, pattern?: RegExp | string): string[];
/**
* Create a new string which is the concatenation of the words in the given input.
* @param {string} s The string to join
* @param {string} [sep=' '] The separator to use
* @returns {string} Returns the joined string.
* @example
```js
join('Lord Of The Rings', '-')
// 'Lord-Of-The-Rings'
```
*/
export declare function join(s: string, sep?: string): string;
/**
* Checks if a string contains only alphanumeric characters.
* @param {string} s The string
* @returns {boolean} Returns `true` if the string contains only alphanumeric.
* @example
```js
isAlnum('alpha1234')
// true
isAlnum('oops!')
// false
```
*/
export declare function isAlnum(s: string): boolean;
/**
* Checks if a string contains only alphabetic characters.
* @param {string} s The string
* @returns {boolean} Returns `true` if the string contains only alphabetic.
* @example
```js
isAlpha('alpha1234')
// false
isAlpha('letters')
// true
```
*/
export declare function isAlpha(s: string): boolean;
/**
* Checks if a string contains only numeric characters.
* @param {string} s The string
* @returns {boolean} Returns `true` if the string contains only numeric.
* @example
```js
isNumeric('alpha1234')
// false
isNumeric('1234')
// true
```
*/
export declare function isNumeric(s: string): boolean;
/**
* Returns a new string with only valid ASCII characters
* @param {string} s The string
* @returns {string} The ASCII characters in the given string
* @example
```js
asciify('äÄçÇéÉêPHP-MySQLöÖÐþúÚ')
// 'PHP-MySQL'
```
*/
export declare function asciify(s: string): string;
/**
* Replaces any accent characters in the string with non accents.
* @param {string} s The string
* @returns {string} The new string without accents
* @example
```js
removeAccents('Antoine de Saint-Exupéry')
// 'Antoine de Saint-Exupery'
```
*/
export declare function removeAccents(s: string): string;
/**
* Capitalizes the first letter of every word in the string.
* @param {string} s The string to capitalize
* @returns {string} Returns the title cased string.
* @example
```js
titleCase('lord of the rings')
// 'Lord Of The Rings'
```
@see {@link capitalize}
*/
export declare function titleCase(s: string): string;
/**
* Converts the string to camel case.
* @param {string} s The string to convert
* @returns {string} Returns the camel cased string.
* @example
```js
camelCase('Equipment class name')
// 'equipmentClassName'
```
*/
export declare function camelCase(s: string): string;
/**
* Converts the string to Pascal case.
* @param {string} s The string to convert
* @returns {string} Returns the Pascal cased string.
* @example
```js
pascalCase('equipment class name')
// 'EquipmentClassName'
```
*/
export declare function pascalCase(s: string): string;
/**
* Converts the string to snake case.
* @param {string} s The string to convert
* @returns {string} Returns the snake cased string.
* @example
```js
snakeCase('Equipment Class Name')
// 'equipment_class_name'
```
*/
export declare function snakeCase(s: string): string;
/**
* Converts a string to kebab case.
* @param {string} s The string
* @returns {string} Returns the kebab cased string.
* @example
```js
kebabCase('Equipment Class Name')
// 'equipment-class-name'
kebabCase('equipment_class_name')
// 'equipment-class-name'
```
*/
export declare function kebabCase(s: string): string;
/**
* Returns a url-safe slug for the given string. Note that by default it will preserve any capitalization in the given string.
* @param {string} s The string
* @returns {string} A url-safe slug version of the string
* @example
```js
slugify('Antoine de Saint-Exupéry')
// 'Antoine-de-Saint-Exupery'
```
*/
export declare function slugify(s: string): string;