stringlish
v1.0.1
Published
This class helps parse, format, and transform strings.
Maintainers
Readme
Stringlish
This class helps parse, format, and transform strings. It supports both Node and browser use.
Usage
Node
npm i stringlish
let Stringlish = require("stringlish");Minified version:
let Stringlish = require("stringlish/dist/Stringlish.min");Browser
import Stringlish from "stringlish";Minified version:
import Stringlish from "stringlish/dist/Stringlish.min";Script tag:
<script src="node_modules/stringlish/dist/Stringlish.min.js"></script>Notes
- This project is lightweight and dependency free.
- The source code is written in ES6 and transpiled with Babel.
- If you need to create documentation for local use, run
npm run doc. Otherwise, visit the online docs.
Samples
Static Methods
Stringlish.firstLetterUpper(str);
Stringlish.firstLetterUpper("hello world");
// Hello worldStringlish.firstLettersUpper(str);
Stringlish.firstLettersUpper("hello world");
// Hello WorldStringlish.toCamelCase(str);
Stringlish.toCamelCase("hello world");
// helloWorldStringlish.toPascalCase(str);
Stringlish.toPascalCase("hello world");
// HelloWorldStringlish.toSnakeCase(str);
Stringlish.toSnakeCase("hello world");
// hello_worldStringlish.toKebabCase(str);
Stringlish.toKebabCase("hello world");
// hello-worldStringlish.trimLeft(str);
Stringlish.trimLeft(" hello world");
// hello worldStringlish.trimRight(str);
Stringlish.trimRight("hello world ");
// hello worldStringlish.trim(str);
Stringlish.trim(" hello world ");
// hello worldStringlish.cutStr(str, maxLength, ellipsis = true);
Stringlish.cutStr("Get on the good foot", 6);
// Get o…
Stringlish.cutStr("Get on the good foot", 10, false);
// Get on theStringlish.cutStrAtWords(str, maxLength, ellipsis = true);
Stringlish.cutStrAtWords("Get on the good foot", 5);
// Get…Stringlish.cutStrReverse(str, maxLength, ellipsis = true);
Stringlish.cutStrReverse("Get on the good foot", 9);
// …ood footStringlish.cutStrAtWordsReverse(str, maxLength, ellipsis = true);
Stringlish.cutStrAtWordsReverse("Get on the good foot", 9);
// …footStringlish.wordCount(str);
Stringlish.wordCount("hello world");
// 2Stringlish.addOrdinalIndicator(num);
Stringlish.addOrdinalIndicator(1);
// 1st
Stringlish.addOrdinalIndicator(22);
// 22nd
Stringlish.addOrdinalIndicator(103);
// 103rdStringlish.readableNumber(num);
Stringlish.readableNumber(100000);
// 100,000
Stringlish.readableNumber(1000.75);
// 1,000.75See the full documentation here.
License
Copyright (c) 2014, 2017 Leandro Silva (http://grafluxe.com)
Released under the MIT License.
See LICENSE.md for entire terms.

