Socket
Socket
Sign inDemoInstall

url-slug

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0-alpha.0 to 2.2.0

2

index.js

@@ -230,3 +230,3 @@ "use strict";

_parseOptions3$camelC = _parseOptions3.camelCase,
camelCase = _parseOptions3$camelC === void 0 ? this.camelCase : _parseOptions3$camelC,
camelCase = _parseOptions3$camelC === void 0 ? false : _parseOptions3$camelC,
_parseOptions3$separa = _parseOptions3.separator,

@@ -233,0 +233,0 @@ separator = _parseOptions3$separa === void 0 ? null : _parseOptions3$separa,

{
"name": "url-slug",
"version": "2.2.0-alpha.0",
"version": "2.2.0",
"description": "RFC 3986 compliant slug generator with multiple language support",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,3 +8,3 @@ # url-slug [![build status](https://img.shields.io/travis/stldo/url-slug.svg?style=flat)](https://travis-ci.org/stldo/url-slug) [![npm version](https://img.shields.io/npm/v/url-slug.svg?style=flat)](https://www.npmjs.com/package/url-slug)

```bash
$ npm install --save url-slug
$ npm install url-slug
```

@@ -23,4 +23,45 @@

### urlSlug(string, [options]), urlSlug.convert(string, [options])
Returns the __string__ value converted to a slug.
#### string
The string that'll be converted.
#### options
| 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 (set to `false` to keep the string unchanged) | `urlSlug.transformers.lowercase` |
#### Examples
```javascript
import urlSlug from 'url-slug'
urlSlug('Comfortably Numb', {
transformer: urlSlug.transformers.uppercase
})
// COMFORTABLY-NUMB
urlSlug('á é í ó ú Á É Í Ó Ú ç Ç æ Æ œ Œ ® © € ¥ ª º ¹ ² ½ ¼', {
separator: '_',
transformer: false
})
// a_e_i_o_u_A_E_I_O_U_c_C_ae_AE_oe_OE_r_c_EU_Y_a_o_1_2_1_2_1_4
urlSlug('Red, red wine, stay close to me…', {
separator: '',
transformer: urlSlug.transformers.titlecase
})
// RedRedWineStayCloseToMe
```
### urlSlug(string, [separator], [transformer]), urlSlug.convert(string, [separator], [transformer])
> ⚠️ __Warning__: This syntax will be deprecated
Returns the __string__ value converted to a slug.

@@ -46,3 +87,3 @@

#### Example
#### Examples

@@ -62,6 +103,39 @@ ```javascript

### urlSlug.revert(slug, [options])
Returns the __slug__ value converted to a regular string.
#### slug
The slug that'll be reverted.
#### options
| Name | Description | Default |
| --- | --- | --- |
| camelCase | Split camel case occurrences | `false` |
| separator | Character to split the string: `'-'`, `'.'`, `'_'`, `'~'` or `''` (set to `null` to use all characters) | `null` |
| transformer | A built-in transformer or a custom function (set to `false` to keep the string unchanged) | `false` |
#### Examples
```javascript
import urlSlug from 'url-slug'
urlSlug.revert('Replace-every_separator.allowed~andSplitCamelCaseToo')
// Replace every separator allowed and Split Camel Case Too
urlSlug.revert('this-title-needs-a-title_case', {
separator: '-',
transformer: urlSlug.transformers.titlecase
})
// This Title Needs A Title_case
```
### urlSlug.revert(slug, [separator], [transformer])
Returns the __slug__ value converted to a human readable string.
> ⚠️ __Warning__: This syntax will be deprecated
Returns the __slug__ value converted to a regular string.
#### slug

@@ -85,3 +159,3 @@

#### Example
#### Examples

@@ -104,2 +178,4 @@ ```javascript

> ⚠️ __Warning__: This syntax will be deprecated
`url-slug` constructor, useful if you want to create more instances. If `separator` or `transform` are set, they will the default values of the instance.

@@ -119,3 +195,3 @@

#### Example
#### Examples

@@ -135,3 +211,3 @@ ```javascript

#### Example
#### Examples

@@ -138,0 +214,0 @@ ```javascript

@@ -183,2 +183,8 @@ const expect = require('chai').expect

.to.be.equal('A-BRONX-TALE')
}) // TODO v3 deprecate
it('uses upper case as transformer and use the default separator', () => {
const options = { transformer: urlSlug.transformers.uppercase }
expect(urlSlug.convert('a bronx tale', options))
.to.be.equal('A-BRONX-TALE')
})

@@ -189,2 +195,11 @@

.to.be.equal('Tom_Jobim')
}) // TODO v3 deprecate
it('uses underscore as separator and title case as transformer', () => {
const options = {
separator: '_',
transformer: urlSlug.transformers.titlecase
}
expect(urlSlug.convert('tom jobim', options))
.to.be.equal('Tom_Jobim')
})

@@ -195,2 +210,11 @@

.to.be.equal('Charly-._~-._~Garcia')
}) // TODO v3 deprecate
it('allows multiple characters as separator and maintains the case', () => {
const options = {
separator: '-._~-._~',
transformer: false
}
expect(urlSlug.convert('Charly García', options))
.to.be.equal('Charly-._~-._~Garcia')
})

@@ -201,2 +225,11 @@

.to.be.equal('JavaScript')
}) // TODO v3 deprecate
it('returns a camel case slug', () => {
const options = {
separator: '',
transformer: urlSlug.transformers.titlecase
}
expect(urlSlug.convert('java script', options))
.to.be.equal('JavaScript')
})

@@ -217,2 +250,18 @@

.to.be.equal('Ja-Va-Scr-Ip-T')
}) // TODO v3 deprecate
it('splits a camel case string', () => {
const options = { separator: null, transformer: null }
expect(urlSlug.convert('javaScript'))
.to.be.equal('java-script')
expect(urlSlug.convert('javaSCRIPT', options))
.to.be.equal('java-SCRIPT')
expect(urlSlug.convert('JAVAScript', options))
.to.be.equal('JAVA-Script')
expect(urlSlug.convert('jaVAScriPT', options))
.to.be.equal('ja-VA-Scri-PT')
expect(urlSlug.convert('JaVaScriPt', options))
.to.be.equal('Ja-Va-Scri-Pt')
expect(urlSlug.convert('JaVaScrIpT', options))
.to.be.equal('Ja-Va-Scr-Ip-T')
})

@@ -231,2 +280,13 @@

.to.be.equal('Rct')
}) // TODO v3 deprecate
it('returns only consonants', () => {
const options = {
separator: '',
transformer: (fragments, separator) => fragments
.join(separator)
.replace(/[aeiou]/gi, '')
}
expect(urlSlug.convert('React', options))
.to.be.equal('Rct')
})

@@ -258,19 +318,19 @@

it('uses unknown reversion and maintain input case', () => {
it('uses unknown reversion and does not change input case', () => {
expect(urlSlug.revert('UrlSlug-_url.~slug'))
.to.be.equal('Url Slug url slug')
.to.be.equal('UrlSlug url slug')
})
it('splits a camel case slug', () => {
expect(urlSlug.revert('javaScript'))
expect(urlSlug.revert('javaScript', { camelCase: true }))
.to.be.equal('java Script')
expect(urlSlug.revert('javaSCRIPT', ''))
expect(urlSlug.revert('javaSCRIPT', { camelCase: true }))
.to.be.equal('java SCRIPT')
expect(urlSlug.revert('JAVAScript', ''))
expect(urlSlug.revert('JAVAScript', { camelCase: true }))
.to.be.equal('JAVA Script')
expect(urlSlug.revert('jaVAScriPT', ''))
expect(urlSlug.revert('jaVAScriPT', { camelCase: true }))
.to.be.equal('ja VA Scri PT')
expect(urlSlug.revert('JaVaScriPt', ''))
expect(urlSlug.revert('JaVaScriPt', { camelCase: true }))
.to.be.equal('Ja Va Scri Pt')
expect(urlSlug.revert('JaVaScrIpT', ''))
expect(urlSlug.revert('JaVaScrIpT', { camelCase: true }))
.to.be.equal('Ja Va Scr Ip T')

@@ -280,4 +340,4 @@ })

it('does not split a camel case slug', () => {
expect(urlSlug.convert('javaScript', { camelCase: false }))
.to.be.equal('javascript')
expect(urlSlug.revert('javaScript-language'))
.to.be.equal('javaScript language')
})

@@ -289,2 +349,11 @@

.to.be.equal('CLAUDIO BAGLIONI_IS-NOT-GERMAN')
}) // TODO v3 deprecate
it('splits on camel case and convert input to upper case', () => {
const options = {
separator: '',
transformer: urlSlug.transformers.uppercase
}
expect(urlSlug.revert('ClaudioBaglioni_is-NOT-German', options))
.to.be.equal('CLAUDIO BAGLIONI_IS-NOT-GERMAN')
})

@@ -296,2 +365,11 @@

.to.be.equal('Comfortably Numb')
}) // TODO v3 deprecate
it('returns the title of a Pink Floyd track', () => {
const options = {
separator: '-._~',
transformer: urlSlug.transformers.titlecase
}
expect(urlSlug.revert('comfortably-._~numb', options))
.to.be.equal('Comfortably Numb')
})

@@ -298,0 +376,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc