voca

repository·master·Indexed 25 days ago

https://github.com/panzerdp/voca

A lightweight, modular JavaScript string library for comprehensive string manipulation. Voca provides tools for changing case, trimming, padding, slugifying, formatting, and querying strings, supporting CommonJS, ES2015 modules, and UMD builds.

Tokens
726
Snippets
4
Records
7
Agent score
36%

What's inside voca

  1. Use Voca in the Browser

    master

    To use Voca directly in a web page, load the UMD builds via a <script> tag. This exposes a global variable v containing the entire library.

    <script src="voca.js" type="text/javascript"></script>
    <script type="text/javascript">
      v.last('wonderful world', 5); // => 'world'
    </script>
  2. Use Voca with CommonJS modules

    master

    In a CommonJS environment, you can require the entire library to access all functions via a single object, or require individual functions to minimize your bundle size.

    // Require the entire library
    const v = require('voca');
    v.trim(' Hello World! ');            // => 'Hello World'
    v.sprintf('%d red %s', 3, 'apples'); // => '3 red apples'
    
    // 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'
  3. Use Voca with ES2015 modules

    master

    Voca is compatible with ES2015 modules. You can import the entire library as a default export or import specific functions directly.

    // Import the entire library
    import voca from 'voca';
    voca.kebabCase('goodbye blue sky'); // => 'goodbye-blue-sky'
    
    // Import individual functions
    import last from 'voca/last';
    last('sun rises', 5); // => 'rises'
  4. Initialize Voca with v()

    master

    To start a string manipulation sequence, call the default export v(subject). This creates a ChainWrapper object that allows for implicit method chaining.

    If a method in the chain returns a number, boolean, or array, the chain terminates and returns that value. For all other cases (when the result is still a wrapper), use the .value() method to unwrap the final string result.