Skip to content

Commit

Permalink
fix: remove() should work with multichar strings
Browse files Browse the repository at this point in the history
Fixes: simov#164

BREAKING CHANGE: remove() behavior now aligns with
Stirng.prototype.replace(). To remove more than the first
instance/match, use a regular expression with the global (g) flag.
  • Loading branch information
Trott committed Aug 18, 2022
1 parent 1d24cf7 commit 607261e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ slugify('some string', {

For example, to remove `*+~.()'"!:@` from the result slug, you can use `slugify('..', {remove: /[*+~.()'"!:@]/g})`.

The `remove` option uses `String.prototype.replace()`. This means that it will
only remove the first match if it is a string or a regular expression without
the global (`g`) flag. To remove all matches, supply a regular expression with
the global (`g`) flag.

## Locales

The main `charmap.json` file contains all known characters and their transliteration. All new characters should be added there first. In case you stumble upon a character already set in `charmap.json`, but not transliterated correctly according to your language, then you have to add those characters in `locales.json` to override the already existing transliteration in `charmap.json`, but for your locale only.
Expand Down
6 changes: 3 additions & 3 deletions slugify.js

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

7 changes: 6 additions & 1 deletion test/slugify.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,18 @@ describe('slugify', () => {
'foo *+~.() bar \'"!:@ baz',
{remove: /[$*_+~.()'"!\-:@]/g}
), 'foo-bar-baz')

t.equal(slugify(
'AFdAFd',
{ remove: /AF/g }
), 'dd')
})

it('options.remove regex without g flag', () => {
t.equal(slugify(
'foo bar, bar foo, foo bar',
{remove: /[^a-zA-Z0-9 -]/}
), 'foo-bar-bar-foo-foo-bar')
), 'foo-bar-bar-foo,-foo-bar')
})

it('options.lower', () => {
Expand Down

0 comments on commit 607261e

Please sign in to comment.