@empathyco/x-components
Version:
Empathy X Components
49 lines (47 loc) • 1.18 kB
JavaScript
/**
* Util used to return true if the string is empty, undefined or null.
*
* @param str - String value.
* @returns Returns true if str is an empty string, undefined or null.
* @public
*/
function isStringEmpty(str) {
return !str || str.length === 0;
}
/**
* Util to transform string a into kebab case.
*
* @example
* Transforms `camelCase` into `camel-case`
* Transforms `PascalCase` into `pascal-case`
* Transforms `snake_case` into `snake-case`
* Transforms `space space multispaces` into `space-space-multiplespaces`
* Transforms `kebab-case` into `kebab-case`
*
* @param str - String value.
* @returns Returns the string in kebab case.
* @public
*/
function toKebabCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/\s+|_/g, '-')
.toLowerCase();
}
/**
* Util to capitalize a string .
*
* @example
* Transforms `query` into `Query`
*
* @param str - String value.
*
* @returns Returns the string capitalized.
*
* @public
*/
function capitalize(str) {
return (str.charAt(0).toUpperCase() + str.slice(1));
}
export { capitalize, isStringEmpty, toKebabCase };
//# sourceMappingURL=string.js.map