Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preserve option to allow preserving additional characters in strict mode #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ slugify('some string', {
strict: false, // strip special characters except replacement, defaults to `false`
locale: 'vi', // language code of the locale to use
trim: true // trim leading and trailing replacement chars, defaults to `true`
preserve: ['.'] // preserve specified characters in the result
})
```

Expand Down
1 change: 1 addition & 0 deletions slugify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare function slugify(
strict?: boolean;
locale?: string;
trim?: boolean;
preserve?: string[];
}
| string,

Expand Down
10 changes: 8 additions & 2 deletions slugify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/slugify.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ describe('slugify', () => {
t.equal(slugify('Foo bAr baZ', {lower: true}), 'foo-bar-baz')
})

it('options.preserve', () => {
t.equal(slugify('/url/to/foo bar baz', {preserve: ['/']}), '/url/to/foo-bar-baz')
});

it('options.strict', () => {
t.equal(slugify('foo_bar. -@-baz!', {strict: true}), 'foobar-baz')
})
Expand All @@ -76,6 +80,14 @@ describe('slugify', () => {
t.equal(slugify('foo @ bar', {strict: true}), 'foo-bar')
})

it('options.strict, options.preserve and options.replacement', () => {
t.equal(slugify('!foo.bar_baz@#~', {
replacement: '_',
strict: true,
preserve: ['.']
}), 'foo.bar_baz')
})

it('options.replacement and options.strict', () => {
t.equal(slugify('foo_@_bar-baz!', {
replacement: '_',
Expand Down