https://github.com/argodevops/safe-change-case
Safely transforms semi-structured text in the form of Objects, Arrays or Strings into presentable text using different cases.
https://github.com/argodevops/safe-change-case
javascript npmjs
Last synced: 11 months ago
JSON representation
Safely transforms semi-structured text in the form of Objects, Arrays or Strings into presentable text using different cases.
- Host: GitHub
- URL: https://github.com/argodevops/safe-change-case
- Owner: argodevops
- License: apache-2.0
- Created: 2024-12-16T15:42:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-09T22:08:58.000Z (about 1 year ago)
- Last Synced: 2025-04-09T23:21:06.547Z (about 1 year ago)
- Topics: javascript, npmjs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@argodevops/safe-change-case
- Size: 1.17 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# safe-change-case
> Safely transforms semi-structured text in the form of Objects, Arrays or Strings into presentable text using different cases.
Built on top of [change-case](https://github.com/blakeembrey/change-case) it will transform text to `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Capital Case`, and `Sentence case`.
It will accept `undefined` and `null` values and return an empty string for safety.
## Installation
`npm install safe-change-case --save`
## Usage
```
import { safeChangeCase, CaseType } from 'safe-change-case';
// Strings
console.log(camelCase('hello world')); // 'helloWorld'
console.log(snakeCase('hello world')); // 'hello_world'
console.log(kebabCase('hello world')); // 'hello-world'
console.log(pascalCase('hello world')); // 'HelloWorld'
console.log(capitalCase('hello world')); // 'Hello World'
console.log(sentenceCase('hello world')); // 'Hello world'
// Arrays
console.log(camelCase(['hello', 'world'])); // 'helloWorld'
console.log(snakeCase(['hello', 'world'])); // 'hello_world'
// Objects
console.log(kebabCase({ hello: 'world' })); // 'hello-world'
// Null and undefined
console.log(camelCase(null)); // ''
console.log(snakeCase(undefined)); // ''
// safeChangeCase function
console.log(safeChangeCase('hello world', CaseType.CAMEL)); // 'helloWorld'
console.log(safeChangeCase('hello world', CaseType.SNAKE)); // 'hello_world'
console.log(safeChangeCase('hello world', CaseType.KEBAB)); // 'hello-world'
console.log(safeChangeCase('hello world', CaseType.PASCAL)); // 'HelloWorld'
console.log(safeChangeCase('hello world', CaseType.CAPITAL)); // 'Hello World'
console.log(safeChangeCase([ 'hello', 'world' ], CaseType.SENTENCE)); // 'Hello world'
console.log(safeChangeCase({ hello: 'world' }, CaseType.SNAKE)); // 'hello_world'
console.log(safeChangeCase(null, CaseType.CAMEL)); // ''
```
## Related
- [Change Case](https://github.com/blakeembrey/change-case)
## License
Apache 2.0