{"id":12387,"library":"voca","title":"Voca JavaScript String Library","description":"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.","status":"active","version":"1.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/panzerdp/voca","tags":["javascript","string","sprintf","trim","truncate","pad","slugify","latinise","escape"],"install":[{"cmd":"npm install voca","lang":"bash","label":"npm"},{"cmd":"yarn add voca","lang":"bash","label":"yarn"},{"cmd":"pnpm add voca","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The entire library is exposed as a default export in ES2015 modules. Access functions via `voca.someFunction()`.","wrong":"import { voca } from 'voca';","symbol":"voca","correct":"import voca from 'voca';"},{"note":"In CommonJS environments, the library is typically imported as `v` for consistency with browser global usage. Access functions via `v.someFunction()`.","wrong":"const voca = require('voca');","symbol":"v","correct":"const v = require('voca');"},{"note":"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.","wrong":"import { slugify } from 'voca';","symbol":"slugify","correct":"import slugify from 'voca/slugify';"},{"note":"For CommonJS, individual functions are also imported directly from their subpath for modularity and reduced bundle size.","wrong":"const { words } = require('voca');","symbol":"words","correct":"const words = require('voca/words');"}],"quickstart":{"code":"import voca from 'voca';\nimport camelCase from 'voca/camelCase';\nimport sprintf from 'voca/sprintf';\nimport slugify from 'voca/slugify';\n\n// Using the entire library default export\nconst sentence = '  Hello wonderful WORLD!  ';\nconst trimmedSentence = voca.trim(sentence);\nconsole.log(`Trimmed: '${trimmedSentence}'`);\n\n// Using individual function imports for tree-shaking\nconst camelCased = camelCase('bird flight');\nconsole.log(`Camel Case: '${camelCased}'`);\n\nconst formattedString = sprintf('%s costs $%.2f', 'Tea', 1.5);\nconsole.log(`Formatted: '${formattedString}'`);\n\nconst urlSlug = slugify('What a wonderful world');\nconsole.log(`Slug: '${urlSlug}'`);\n\n// Example of another function from the main export\nconst capitalized = voca.capitalize('hello voca');\nconsole.log(`Capitalized: '${capitalized}'`);","lang":"typescript","description":"Demonstrates importing the entire Voca library and individual functions, then using several string manipulation utilities."},"warnings":[{"fix":"Always use `import functionName from 'voca/functionName';` for specific functions in ES2015 modules, or `const functionName = require('voca/functionName');` in CommonJS.","message":"Voca 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Correct the import statement to `import slugify from 'voca/slugify';`","cause":"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.","error":"TypeError: voca.slugify is not a function"},{"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.","cause":"Trying to use `v.someFunction()` in a Node.js or browser environment without properly importing or loading the Voca library first.","error":"ReferenceError: v is not defined"},{"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.","cause":"Using `require('voca')` or `require('voca/someFunction')` directly in a browser without a CommonJS compatible bundler (like Webpack or Browserify).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}