@zerodep/case-snake
TypeScript icon, indicating that this package has built-in type declarations

2.0.9 • Public • Published

@zerodep/case-snake

version language types license

CodeFactor Known Vulnerabilities

A utility to convert a string to snake_case that also strips out non-alphanumeric characters and any leading numeric characters. Non-string values will cause a ZeroDepError to be thrown.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

import { caseSnake } from '@zerodep/case-snake';
// or
const { caseSnake } = require('@zerodep/case-snake');

Use Cases

caseSnake('From sentence case'); // "from_sentence_case"
caseSnake('fromCamelCase'); // "from_camel_case"
caseSnake('from.dot.case'); // "from_dot_case"
caseSnake('from_snake_case'); // "from_snake_case"
caseSnake('FromPascalCase'); // "from_pascal_case"
caseSnake(''); // ""

// with non-alphanumeric characters
caseSnake('A string with some !@#$%^& characters'); // "a_string_with_some_characters"
caseSnake('A #22 character long string'); // "a_22_character_long_string"
caseSnake("I'm a sp3c!al $741ng"); // "i_m_a_sp3c_al_741ng"

// with accented characters
caseSnake('àëîóüý Žøñç'); // "aeiouy_zonc"

// with leading special characters and numbers
caseSnake('__with    many --- spaces'); // "with_many_spaces"
caseCamel('12 monkeys see 6 bananas'); // "monkeys_see_6_bananas"

// non-string values
caseSnake({ not: 'a string' }); // throws ZeroDepError: Value is not a string

Package Sidebar

Install

npm i @zerodep/case-snake

Homepage

zerodep.app

Weekly Downloads

9

Version

2.0.9

License

MIT

Unpacked Size

10.9 kB

Total Files

7

Last publish

Collaborators

  • cdepage