Registry / serialization / slang
library0.1.12jsnpmunverified

Slang is a lightweight JavaScript library providing a collection of utility functions for common string manipulations, such as capitalization, camel case conversion, dasherization, and pluralization. Originally published over a decade ago (v0.3.0, December 2013), it was designed for use in both browser environments and CommonJS Node.js projects. The library is stable in its functionality but has not seen active development or maintenance since its last release. Key differentiators at the time included its small footprint and a focus on essential string transformations. Due to its age, it primarily uses CommonJS module patterns and lacks native ESM support or TypeScript definitions, making it less suitable for modern, type-safe, or highly modular JavaScript/TypeScript ecosystems without additional tooling or shims.

npm install slang
INSTALL
IMPORT
SIG · SLANG
S
slang
serializationjavascriptv0.1.12
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.

slang
import slang from 'slang';
const slang = require('slang').default;
While primarily a CommonJS library, modern bundlers can often resolve 'import slang from "slang"' correctly by treating the CommonJS export as the default. Explicit `require` is the original intended usage.
capitalize
import slang from 'slang'; slang.capitalize('hello');
import { capitalize } from 'slang';
Functions are exposed as methods on the `slang` object, not as named exports. Destructuring `slang` directly for functions is incorrect.
camelize
const slang = require('slang'); const camelizedString = slang.camelize('hello world');
import { camelize } from 'slang';
For CommonJS environments, `require('slang')` returns the global `slang` object directly. Access functions via `slang.functionName`.

Demonstrates how to import the `slang` library using CommonJS and utilize several of its core string utility functions like `capitalize`, `camelize`, `dasherize`, `pluralize`, and `isString`.

const slang = require('slang'); // Basic string manipulation const capitalized = slang.capitalize('hello world'); console.log(`Capitalized: ${capitalized}`); // Expected: Hello world const camelized = slang.camelize('hello world string'); console.log(`Camelized: ${camelized}`); // Expected: helloWorldString const dasherized = slang.dasherize('yet another example'); console.log(`Dasherized: ${dasherized}`); // Expected: yet-another-example // Pluralization (with default English language) const pluralWord = slang.pluralize('cat', 2); console.log(`Plural (2 cats): ${pluralWord}`); // Expected: cats const singularWord = slang.singularize('dogs'); console.log(`Singular (dogs): ${singularWord}`); // Expected: dog // Check if string const isItString = slang.isString('test'); console.log(`Is 'test' a string? ${isItString}`); // Expected: true // Example of older, less common features // Note: addToPrototype is generally discouraged in modern JS // slang.addToPrototype(); // console.log('another example'.capitalize()); // This would work if prototype was extended
Debug
Known issues
breakingThe `addToPrototype` method, which adds `slang` functions directly to `String.prototype`, is available but highly discouraged. Modifying native prototypes can lead to conflicts, unexpected behavior in other libraries, and makes code harder to maintain and debug.
fix
Avoid calling `slang.addToPrototype()`. Instead, explicitly call functions via the `slang` object (e.g., `slang.camelize('my-string')`) or destructure individual functions if preferred, ensuring proper scoping.
affects: >=0.1.0
gotchaThis package is very old (last published in 2013) and is no longer actively maintained. It does not provide native ES module (ESM) support or TypeScript definitions. Using it in modern JavaScript/TypeScript projects may require bundler configuration or type declaration files.
fix
For new projects, consider using a more modern, maintained string utility library with explicit ESM and TypeScript support (e.g., `lodash/string` or `change-case`). If retained, use bundlers like Webpack or Rollup to handle CommonJS imports, and create custom `.d.ts` files for TypeScript support.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: slang.camelize is not a function
Attempting to import `camelize` as a named ESM export, but `slang` exposes its functions as properties of a single exported object.
fix
If using `import`, ensure you import the default export and then access the function: `import slang from 'slang'; slang.camelize('string');`. If using `require`, assign the result to a variable and access methods: `const slang = require('slang'); slang.camelize('string');`
Error: Cannot find module 'slang' (ESM context)
Attempting to `import` 'slang' directly in a pure ESM Node.js environment without a bundler or specific Node.js CommonJS interoperability settings.
fix
Configure your build tool (e.g., Webpack, Rollup, Vite) to correctly handle CommonJS modules, or use dynamic import `import('slang')` with `await` if suitable. Alternatively, ensure your Node.js environment is configured for CommonJS (`'type': 'commonjs'` in `package.json`) or use a CommonJS wrapper.
Upgrade
Version history
0.1.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
slang — npm install slang · libregistry