Installations
npm install slugify
Releases
Unable to fetch releases
Developer
simov
Developer Guide
Module System
CommonJS
Min. Node Version
>=8.0.0
Typescript Support
Yes
Node Version
14.20.0
NPM Version
6.14.17
Statistics
1,529 Stars
211 Commits
131 Forks
8 Watching
1 Branches
39 Contributors
Updated on 28 Nov 2024
Bundle Size
8.11 kB
Minified
3.46 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
533,750,054
Last day
6.6%
901,722
Compared to previous day
Last week
4.4%
4,582,070
Compared to previous week
Last month
11.1%
18,841,416
Compared to previous month
Last year
37%
168,017,272
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
slugify
1var slugify = require('slugify') 2 3slugify('some string') // some-string 4 5// if you prefer something other than '-' as separator 6slugify('some string', '_') // some_string
- Vanilla ES2015 JavaScript
- If you need to use Slugify with older browsers, consider using version 1.4.7
- No dependencies
- Coerces foreign symbols to their English equivalent (check out the charMap for more details)
- Works in the browser (window.slugify) and AMD/CommonJS-flavored module loaders
Options
1slugify('some string', { 2 replacement: '-', // replace spaces with replacement character, defaults to `-` 3 remove: undefined, // remove characters that match regex, defaults to `undefined` 4 lower: false, // convert to lower case, defaults to `false` 5 strict: false, // strip special characters except replacement, defaults to `false` 6 locale: 'vi', // language code of the locale to use 7 trim: true // trim leading and trailing replacement chars, defaults to `true` 8})
Remove
For example, to remove *+~.()'"!:@
from the result slug, you can use slugify('..', {remove: /[*+~.()'"!:@]/g})
.
- If the value of
remove
is a regular expression, it should be a character class and only a character class. It should also use the global flag. (For example:/[*+~.()'"!:@]/g
.) Otherwise, theremove
option might not work as expected. - If the value of
remove
is a string, it should be a single character. Otherwise, theremove
option might not work as expected.
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.
You can get the correct language code of your language from here.
Extend
Out of the box slugify
comes with support for a handful of Unicode symbols. For example the ☢
(radioactive) symbol is not defined in the charMap
and therefore it will be stripped by default:
1slugify('unicode ♥ is ☢') // unicode-love-is
However you can extend the supported symbols, or override the existing ones with your own:
1slugify.extend({'☢': 'radioactive'}) 2slugify('unicode ♥ is ☢') // unicode-love-is-radioactive
Keep in mind that the extend
method extends/overrides the default charMap
for the entire process. In case you need a fresh instance of the slugify's charMap
object you have to clean up the module cache first:
1delete require.cache[require.resolve('slugify')] 2var slugify = require('slugify')
Contribute
- Add chars to
charmap.json
- Run tests
npm test
- The tests will build the charmap in
index.js
and will sort thecharmap.json
- Commit all modified files
Originally this was a vanilla javascript port of node-slug.
Note that the original slug module has been ported to vanilla javascript too.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 12/22 approved changesets -- score normalized to 5
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/simov/slugify/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/simov/slugify/node.js.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/node.js.yml:30
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More