Home

Awesome

Voca JavaScript library logo

travis build code coverage npm package

Voca is a JavaScript library for manipulating strings. https://vocajs.pages.dev

v.camelCase('bird flight');              // => 'birdFlight'
v.sprintf('%s costs $%.2f', 'Tea', 1.5); // => 'Tea costs $1.50'
v.slugify('What a wonderful world');     // => 'what-a-wonderful-world'

The Voca library offers helpful functions to make string manipulations comfortable: change case, trim, pad, slugify, latinise, sprintf'y, truncate, escape and much more. The modular design allows to load the entire library, or individual functions to minimize the application builds. The library is fully tested, well documented and long-term supported.

Features

Documentation

See the complete documentation at https://vocajs.pages.dev

Usage

Voca can be used in various environments.

Node.js, Rollup, Webpack, Browserify

Voca JavaScript library supports Node.js, Rollup, Webpack, Browserify

Install the library with npm into your local modules directory:

npm install voca

CommonJS modules

Then in your application require the entire library:

const v = require('voca');
v.trim(' Hello World! ');            // => 'Hello World'
v.sprintf('%d red %s', 3, 'apples'); // => '3 red apples'

Or require individual functions:

const words = require('voca/words');
const slugify = require('voca/slugify');
words('welcome to Earth'); // => ['welcome', 'to', 'Earth']
slugify('caffé latté');    // => 'caffe-latte'

ES2015 modules

Voca is compatible with ES2015 modules to import the entire library:

import voca from 'voca';
voca.kebabCase('goodbye blue sky'); // => 'goodbye-blue-sky'

Or import individual functions:

import last from 'voca/last';
last('sun rises', 5); // => 'rises'

Browser

Voca JavaScript library supports Chrome, Firefox, Safari, Edge, Internet Explorer

Load the UMD builds directly into browser's web page:

<script src="voca.js" type="text/javascript"></script>

Then a global variable v is exposed for the entire library:

<script type="text/javascript">
  v.last('wonderful world', 5); // => 'world'
</script>

Functions

ManipulateQueryChopCaseIndex
v.insertv.endsWithv.charAtv.camelCasev.indexOf
v.latinisev.includesv.codePointAtv.capitalizev.lastIndexOf
v.padv.isAlphav.firstv.decapitalizev.search
v.padLeftv.isAlphaDigitv.graphemeAtv.kebabCaseEscape
v.padRightv.isBlankv.lastv.lowerCasev.escapeHtml
v.repeatv.isDigitv.prunev.snakeCasev.escapeRegExp
v.replacev.isEmptyv.slicev.swapCasev.unescapeHtml
v.replaceAllv.isLowerCasev.substrv.titleCaseStrip
v.reversev.isNumericv.substringv.upperCasev.stripBom
v.reverseGraphemev.isStringv.truncateSplitv.stripTags
v.slugifyv.isUpperCaseCountv.chars
v.splicev.matchesv.countv.codePoints
v.trv.startsWithv.countGraphemesv.graphemes
v.trimFormatv.countSubstringsv.split
v.trimLeftv.sprintfv.countWherev.words
v.trimRightv.vprintfv.countWords
v.wordWrap

Bug reports

For bug reports, documentation typos or feature requests feel free to create an issue.
Please make sure that the same problem wasn't reported already.

For general usage questions please ask on StackOverflow.

Contributing

Contribution is welcome!

See more details in Contributing guide.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Author

Dmitri Pavlutin
Dmitri Pavlutin
Personal blog
Email

License

Licensed under MIT