2.0.9 • Published 4 months ago

@zerodep/case-snake v2.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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
2.0.9

4 months ago

2.0.8

4 months ago

2.0.7

4 months ago

2.0.6

8 months ago

2.0.5

9 months ago

2.0.3

12 months ago

2.0.2

12 months ago

2.0.1

12 months ago