Skip to content

Datamart/string-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Transform Tweet

Build Status License NPM version Website NPM downloads

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 a 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 transformed 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 transformed 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 transformed 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 transformed string.
 */
console.log(toKebabCase('toKebabCase')); // to-kebab-case

For more information please visit Glize project page.