string-transform
v21.9.19
Published
String-transform module from Glize library.
Downloads
49,577
Readme
String Transform
String transform module from Glize library.
Usage
npm install string-transform --save
import {
capitalize,
hash,
toCamelCase,
toKebabCase,
toPascalCase,
toSnakeCase,
} from 'string-transform';
/**
* Transforms the first character of each word to uppercase; other
* characters are unaffected.
* @param {string} str The string to be transformed.
* @return {string} Returns transformed string.
*/
console.log(capitalize('test string')); // Test String
/**
* Converts <code>str</code> to hashed string.
* @param {string} str The input string.
* @return {string} Returns hashed string.
*/
console.log(hash('https://glize.js.org/')); // 4Q69R
/**
* Converts the passed string into a string with the separator denoted by the
* next word capitalized (aka lower camel case).
* @param {string} str The input string.
* @return {string} A string convered into a string with the separator
* denoted by the next word capitalized.
* @see https://en.wikipedia.org/wiki/Camel_case
*/
console.log(toCamelCase('to-camel-case')); // toCamelCase
/**
* Converts the passed string into a string of capitalized words without
* separators (aka upper camel case).
* @param {string} str The input string.
* @return {string} A string convered into a string of capitalized words
* without separators.
* @see https://en.wikipedia.org/wiki/PascalCase
*/
console.log(toPascalCase('to-pascal-case')); // ToPascalCase
/**
* Converts the given string into a string with a single underscore as a separator.
* @param {string} str The input string.
* @return {string} A convered string.
* @see https://en.wikipedia.org/wiki/Snake_case
*/
console.log(toSnakeCase('toSnakeCase')); // to_snake_case
/**
* Converts the given string into a string with a single dash as a separator.
* @param {string} str The input string.
* @return {string} A convered string.
*/
console.log(toKebabCase('toKebabCase')); // to-kebab-case
For more information please visit Glize project page.