Tiny and powerful utility to convert between camelCase, snake_case, PascalCase, kebab-case, dot.case, COBOL-CASE and more — with abbreviation preservation.
npm install @xelbera/recase> Convert strings between camelCase, PascalCase, snake_case, kebab-case, dot.case, COBOL-CASE and more — with optional abbreviation preservation.
---
- Convert between popular casing styles:
- camelCase, PascalCase, snake_case, UPPER_SNAKE_CASE
- kebab-case, Train-Case, dot.case, COBOL-CASE
- Detect case style from input
- Preserve known abbreviations like API, HTML, URL
- Zero dependencies
- TypeScript-native
---
``bash`
npm install @xelbera/recase`
orbash`
yarn add @xelbera/recase
---
`ts
import {
convertCase,
detectCase,
splitToParts
} from '@xelbera/recase';
// Convert between styles
convertCase('userProfileID', 'snake');
// => 'user_profile_id'
convertCase('userHTMLData', 'camel', { preserveAbbreviations: true });
// => 'userHTMLData'
convertCase('userHTMLData', 'camel');
// => 'userHtmlData'
// Detect style
detectCase('USER-PROFILE-ID');
// => 'cobol'
// Split string into parts
splitToParts('userProfileID');
// => ['user', 'profile', 'id']
splitToParts('userHTMLData', true);
// => ['user', 'HTML', 'Data']
`
---
| Style | Example |
|--------------|----------------------|
| camel | userProfileId |pascal
| | UserProfileId |snake
| | user_profile_id |upper_snake
| | USER_PROFILE_ID |kebab
| | user-profile-id |dot
| | user.profile.id |train
| | User-Profile-Id |cobol
| | USER-PROFILE-ID` |
---
See LICENSE for full details.
---
MIT © Stepan Matafonov