File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,20 @@ console.log(toKebabCase("React Testing Library")); // react-testing-library
147147console .log (toKebabCase (" Aliessa Dedase" )); // aliessa-dedase
148148```
149149
150+ ### ` unslugify `
151+
152+ Convert slugs to Sentence Case
153+
154+ ** Usage:**
155+
156+ ``` typescript
157+ import { unslugify } from " largs-utils" ;
158+
159+ unslugify (" my-awesome-title" ); // "My Awesome Title"
160+ unslugify (" hello_world" ); // "Hello World"
161+ unslugify (" spaced--out__slug " ); // "Spaced Out Slug"
162+ ```
163+
150164#### Support my enthusiasm
151165
152166If you like this util, feel free to buy me a coffee ☕!
Original file line number Diff line number Diff line change 1+ import { unslugify } from "../unslugify" ;
2+
3+ describe ( "unslugify" , ( ) => {
4+ it ( "converts kebab-case to capitalized words" , ( ) => {
5+ expect ( unslugify ( "my-awesome-title" ) ) . toBe ( "My Awesome Title" ) ;
6+ } ) ;
7+
8+ it ( "converts snake_case to capitalized words" , ( ) => {
9+ expect ( unslugify ( "hello_world_test" ) ) . toBe ( "Hello World Test" ) ;
10+ } ) ;
11+
12+ it ( "handles mixed separators and spacing" , ( ) => {
13+ expect ( unslugify ( " this--is__a_test " ) ) . toBe ( "This Is A Test" ) ;
14+ } ) ;
15+
16+ it ( "handles single word" , ( ) => {
17+ expect ( unslugify ( "example" ) ) . toBe ( "Example" ) ;
18+ } ) ;
19+
20+ it ( "returns empty string if input is empty" , ( ) => {
21+ expect ( unslugify ( "" ) ) . toBe ( "" ) ;
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ export const unslugify = ( slug : string ) : string =>
2+ slug
3+ . replace ( / [ - _ ] / g, " " )
4+ . replace ( / \s + / g, " " )
5+ . trim ( )
6+ . replace (
7+ / \w \S * / g,
8+ ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( )
9+ ) ;
You can’t perform that action at this time.
0 commit comments