slugify
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The slugify
npm package is a handy utility tool in JavaScript ES2015 that is used to convert strings into URL-friendly slugs. With slugify
, you can convert a string like "Some String" into a hyphen-separated, URL-safe string e.g. "some-string". The module is free from dependencies, and compatible with both browser and AMD module loaders. Notably, the module also features a coercion function that translates foreign symbols into their English equivalent.
The usage of slugify
is incredibly straightforward. First, ensure that the package installed in your system through npm. If you don't have it, you can use npm install slugify
to add it to your project. Then require it into your file using var slugify = require('slugify')
. Once this has been done, you can then convert any string to a URL-friendly format by calling the slugify function and passing in the string as an argument. Here's a quick example:
var slugify = require('slugify');
console.log(slugify('Some String')); // Output: some-string
If you prefer a character other than a hyphen as the separator, you can specify it as the second argument:
var slugify = require('slugify');
console.log(slugify('Some String', '_')); // Output: some_string
You can also leverage various options such as replacement character, removal of certain patterns, case conversion among others, like so:
slugify('Some String', {
replacement: '_',
remove: /[*+~.()'"!:@]/g,
lower: true,
strict: true,
locale: 'en',
trim: true
});
You can get more information on how to use slugify
, its options, and further details about the package in the official GitHub repository (https://github.com/simov/slugify). The repo contains comprehensive documentation on the package usage, including additional package options and methods such as how to remove certain characters from the slug, or how to extend the charMap with custom symbols. Always make sure to refer to this docs page for an up-to-date guide on the correct usage of slugify
and its features.