Skip to content

Commit 6d18c01

Browse files
authored
Update slugify and add more flags (#1)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent a4ae219 commit 6d18c01

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

cli.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const cli = meow(`
88
$ slugify <string>
99
1010
Options
11-
--separator=<string> Word separator [Default: -]
11+
--separator=<string> Word separator [Default: -]
12+
--no-lowercase Don’t make the slug lowercase
13+
--no-decamelize Don’t convert camelCase to separate words
14+
--preserve-leading-underscore If your string starts with an underscore, it will be preserved in the slugified string
1215
1316
Examples
1417
$ slugify 'Déjà Vu!'
@@ -19,6 +22,18 @@ const cli = meow(`
1922
flags: {
2023
separator: {
2124
type: 'string'
25+
},
26+
lowercase: {
27+
type: 'boolean',
28+
default: true
29+
},
30+
decamelize: {
31+
type: 'boolean',
32+
default: true
33+
},
34+
preserveLeadingUnderscore: {
35+
type: 'boolean',
36+
default: false
2237
}
2338
}
2439
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"id"
4444
],
4545
"dependencies": {
46-
"@sindresorhus/slugify": "^0.6.0",
46+
"@sindresorhus/slugify": "^0.11.0",
4747
"meow": "^5.0.0"
4848
},
4949
"devDependencies": {

readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ $ slugify --help
1919
$ slugify <string>
2020
2121
Options
22-
--separator=<string> Word separator [Default: -]
22+
--separator=<string> Word separator [Default: -]
23+
--no-lowercase Don’t make the slug lowercase
24+
--no-decamelize Don’t convert camelCase to separate words
25+
--preserve-leading-underscore If your string starts with an underscore, it will be preserved in the slugified string
2326
2427
Examples
2528
$ slugify 'Déjà Vu!'

test.js

+20
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,23 @@ test('main', async t => {
55
const {stdout} = await execa('./cli.js', ['Déjà Vu!']);
66
t.is(stdout, 'deja-vu');
77
});
8+
9+
test('separator', async t => {
10+
const {stdout} = await execa('./cli.js', ['Unicorns & Rainbows', '--separator=_']);
11+
t.is(stdout, 'unicorns_and_rainbows');
12+
});
13+
14+
test('lowercase', async t => {
15+
const {stdout} = await execa('./cli.js', ['Déjà Vu!', '--no-lowercase']);
16+
t.is(stdout, 'Deja-Vu');
17+
});
18+
19+
test('decamelize', async t => {
20+
const {stdout} = await execa('./cli.js', ['fooBar', '--no-decamelize']);
21+
t.is(stdout, 'foobar');
22+
});
23+
24+
test('preserve-leading-underscore', async t => {
25+
const {stdout} = await execa('./cli.js', ['_foo_bar', '--preserve-leading-underscore']);
26+
t.is(stdout, '_foo-bar');
27+
});

0 commit comments

Comments
 (0)