![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
url-slug
Advanced tools
Readme
RFC 3986 compliant slug generator with multiple language support. It creates slugs safe for use in URL paths, queries and fragments, and can revert them too.
$ npm install url-slug
import urlSlug from 'url-slug'
urlSlug('Sir James Paul McCartney MBE is an English singer-songwriter')
// sir-james-paul-mc-cartney-mbe-is-an-english-singer-songwriter
Returns the string value converted to a slug.
The string that'll be converted.
Name | Description | Default |
---|---|---|
camelCase | Split camel case occurrences | true |
separator | Character to split the string: '-' , '.' , '_' , '~' or '' | '-' |
transformer | A built-in transformer or a custom function (false to keep the string unchanged) | urlSlug.LOWERCASE_TRANSFORMER |
import { * as urlSlug, convert } from 'url-slug'
convert('Comfortably Numb', {
transformer: urlSlug.UPPERCASE_TRANSFORMER
})
// COMFORTABLY-NUMB
convert('á é í ó ú Á É Í Ó Ú ç Ç ª º ¹ ² ½ ¼', {
separator: '_',
transformer: false
})
// a_e_i_o_u_A_E_I_O_U_c_C_a_o_1_2_1_2_1_4
convert('Red, red wine, stay close to me…', {
separator: '',
transformer: urlSlug.TITLECASE_TRANSFORMER
})
// RedRedWineStayCloseToMe
convert('Listen to Fito Páez in Madrid', {
separator: '~',
transformer: urlSlug.SENTENCECASE_TRANSFORMER
})
// Listen~to~fito~paez~in~madrid
Returns the slug value converted to a regular string.
The slug that'll be reverted.
Name | Description | Default |
---|---|---|
camelCase | Split camel case occurrences | false |
separator | Character to split the string: '-' , '.' , '_' , '~' or '' (null to use all characters) | null |
transformer | A built-in transformer or a custom function (false to keep the string unchanged) | false |
import { * as urlSlug, revert } from 'url-slug'
revert('Replace-every_separator.allowed~andSplitCamelCaseToo', {
camelCase: true
})
// Replace every separator allowed and Split Camel Case Too
revert('this-slug-needs-a-title_case', {
separator: '-',
transformer: urlSlug.TITLECASE_TRANSFORMER
})
// This Slug Needs A Title_case
Custom transformers are expressed by a function which receives two arguments, fragments, an array with matching words from a sentence or a slug, and separator, the current separator string set in options. When revert()
calls the transformer, the separator will always be a space character (' '
). Transformers should always return a string.
import { convert, revert } from 'url-slug'
convert('O’Neill is an American surfboard, surfwear and equipment brand', {
transformer: fragments => fragments.join('+').toUpperCase()
})
// O+NEILL+IS+AN+AMERICAN+SURFBOARD+SURFWEAR+AND+EQUIPMENT+BRAND
revert('WEIrd_SNAke_CAse', {
separator: '_',
transformer: (fragments, separator) => fragments.map(fragment => (
fragment.slice(0, -2).toLowerCase() + fragment.slice(-2).toUpperCase()
)).join(separator)
})
// weiRD snaKE caSE
Converts the result to lowercase. E.g.: // SOME WORDS >> some words
Converts the result to sentence case. E.g.: // sOME WORDS >> Some words
Converts the result to uppercase. E.g.: // some words >> SOME WORDS
Converts the result to title case. E.g.: // sOME wORDS >> Some Words
FAQs
Slug generator with less than 1 KB and no dependencies, RFC 3986 compliant
The npm package url-slug receives a total of 210,678 weekly downloads. As such, url-slug popularity was classified as popular.
We found that url-slug demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.