Registry / serialization / voca
library0.1.10jsnpmunverified

Voca is a comprehensive JavaScript library designed for efficient string manipulation, offering a wide array of functions for tasks such as changing case, trimming, padding, slugifying, latinising, formatting (like `sprintf`), truncating, and escaping strings. Currently stable at version 1.4.1, the library maintains a steady release cadence with minor versions introducing new utility functions and improvements. A key differentiator is its modular design, which allows developers to either load the entire library or import individual functions, optimizing application bundle sizes through tree-shaking. It boasts 100% test coverage, comprehensive documentation, and no external dependencies, making it a robust and lightweight solution for string operations across various environments, including Node.js (0.10+), modern browsers (Chrome, Firefox, Safari 7+, Edge 13+, IE 9+), and bundlers like Webpack and Rollup.

npm install voca
INSTALL
IMPORT
SIG · VOCA
V
voca
serializationjavascriptv0.1.10
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

voca
import voca from 'voca';
import { voca } from 'voca';
The entire library is exposed as a default export in ES2015 modules. Access functions via `voca.someFunction()`.
v
const v = require('voca');
const voca = require('voca');
In CommonJS environments, the library is typically imported as `v` for consistency with browser global usage. Access functions via `v.someFunction()`.
slugify
import slugify from 'voca/slugify';
import { slugify } from 'voca';
To enable tree-shaking and import only specific functions in ES2015 modules, import them directly from their subpath. Each function is a default export from its specific module.
words
const words = require('voca/words');
const { words } = require('voca');
For CommonJS, individual functions are also imported directly from their subpath for modularity and reduced bundle size.

Demonstrates importing the entire Voca library and individual functions, then using several string manipulation utilities.

import voca from 'voca'; import camelCase from 'voca/camelCase'; import sprintf from 'voca/sprintf'; import slugify from 'voca/slugify'; // Using the entire library default export const sentence = ' Hello wonderful WORLD! '; const trimmedSentence = voca.trim(sentence); console.log(`Trimmed: '${trimmedSentence}'`); // Using individual function imports for tree-shaking const camelCased = camelCase('bird flight'); console.log(`Camel Case: '${camelCased}'`); const formattedString = sprintf('%s costs $%.2f', 'Tea', 1.5); console.log(`Formatted: '${formattedString}'`); const urlSlug = slugify('What a wonderful world'); console.log(`Slug: '${urlSlug}'`); // Example of another function from the main export const capitalized = voca.capitalize('hello voca'); console.log(`Capitalized: '${capitalized}'`);
Debug
Known issues
gotchaVoca functions are imported individually from subpaths (e.g., `import slugify from 'voca/slugify'`) rather than as named exports from the main package (`import { slugify } from 'voca'`). Attempting the latter will result in a runtime error.
fix
Always use `import functionName from 'voca/functionName';` for specific functions in ES2015 modules, or `const functionName = require('voca/functionName');` in CommonJS.
affects: >=1.0.0
gotchaThe global variable for Voca in browser environments is `v`, while the CommonJS require often uses `v`, but the ES2015 default import is typically aliased as `voca`. This inconsistency can lead to confusion if not mindful of the environment and import style.
fix
Be explicit about your imports. For ES modules, `import voca from 'voca';` is standard. For CommonJS, `const v = require('voca');` or `const voca = require('voca');` are common, but stick to `v` if mirroring browser usage. For browsers, ensure `voca.js` is loaded to expose the global `v`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: voca.slugify is not a function
Attempting to import `slugify` as a named export from the main `voca` package (`import { slugify } from 'voca';`) when it's a default export from a subpath.
fix
Correct the import statement to `import slugify from 'voca/slugify';`
ReferenceError: v is not defined
Trying to use `v.someFunction()` in a Node.js or browser environment without properly importing or loading the Voca library first.
fix
In Node.js, add `const v = require('voca');`. In a browser, ensure `<script src="voca.js"></script>` is present before your script, or `import voca from 'voca'` if using a module bundler.
ReferenceError: require is not defined
Using `require('voca')` or `require('voca/someFunction')` directly in a browser without a CommonJS compatible bundler (like Webpack or Browserify).
fix
For browser-only usage, load `dist/voca.min.js` via a script tag which exposes a global `v` object. If using a bundler, ensure it's configured to handle CommonJS modules.
Upgrade
Version history
0.1.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
voca — npm install voca · libregistry