Socket
Socket
Sign inDemoInstall

url-slug

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

url-slug - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

54

index.js

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

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

@@ -19,6 +19,2 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var unidecode = require('unidecode');
/* TODO v2.3
* - Deprecate transformers represented by strings ('uppercase', etc.)
*/
/* TODO v3

@@ -50,5 +46,5 @@ * - Set default transformers as exports

var BASE = '(?:[a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))';
var CONVERT_CAMELCASE = new RegExp(`[A-Za-z0-9]*?${BASE}|[A-Za-z0-9]+`, 'g');
var REVERT_CAMELCASE = new RegExp(`[^-._~]*?${BASE}|[^-._~]+`, 'g');
var REVERT_CAMELCASE_WITH_EMPTY_SEPARATOR = new RegExp(`.*?${BASE}|.+`, 'g');
var CONVERT_CAMELCASE = new RegExp("[A-Za-z0-9]*?".concat(BASE, "|[A-Za-z0-9]+"), 'g');
var REVERT_CAMELCASE = new RegExp("[^-._~]*?".concat(BASE, "|[^-._~]+"), 'g');
var REVERT_CAMELCASE_WITH_EMPTY_SEPARATOR = new RegExp(".*?".concat(BASE, "|.+"), 'g');
/**

@@ -69,4 +65,4 @@ * Check and return validated options

validate({
separator,
transformer
separator: separator,
transformer: transformer
});

@@ -80,11 +76,12 @@ } else if (1 === options.length) {

} else if (defaultTransformers[option]) {
/* TODO Remove in v3 */
transformer = option;
validate({
transformer
transformer: transformer
});
/* Show deprecation warning */
/* Throw deprecation error */
} else if (typeof option === 'string') {
separator = option;
validate({
separator
separator: separator
});

@@ -96,5 +93,5 @@ } else if (option != null) {

validate({
camelCase,
separator,
transformer
camelCase: camelCase,
separator: separator,
transformer: transformer
});

@@ -105,3 +102,3 @@ }

if (defaultTransformers[transformer]) {
/* Deprecate in v2.3.0 */
/* Remove in v3.0.0 */
transformer = defaultTransformers[transformer];

@@ -111,5 +108,5 @@ }

return {
camelCase,
camelCase: camelCase,
separator: separator == null ? void 0 : separator,
transformer
transformer: transformer
};

@@ -129,3 +126,3 @@ }

if (typeof camelCase !== 'boolean') {
throw new Error(`camelCase must be a boolean: "${camelCase}".`);
throw new Error("camelCase must be a boolean: \"".concat(camelCase, "\"."));
}

@@ -136,5 +133,5 @@ }

if ('string' !== typeof separator) {
throw new Error(`separator must be a string: "${separator}".`);
throw new Error("separator must be a string: \"".concat(separator, "\"."));
} else if (INVALID_SEPARATOR.test(separator)) {
throw new Error(`separator has invalid characters: "${separator}".`);
throw new Error("separator has invalid characters: \"".concat(separator, "\"."));
}

@@ -146,5 +143,6 @@ }

if (typeof transformer === 'string' && defaultTransformers[transformer]) {
console.warn('\x1b[33m[DEPRECATION WARNING]\x1b[0m Using transformer name ' + 'strings will be deprecated in v2.3.0');
throw new Error('Using transformer name as string was deprecated');
/* TODO Remove in v3 */
} else {
throw new Error(`transformer must be a function: "${transformer}".`);
throw new Error("transformer must be a function: \"".concat(transformer, "\"."));
}

@@ -155,5 +153,3 @@ }

var UrlSlug =
/*#__PURE__*/
function () {
var UrlSlug = /*#__PURE__*/function () {
_createClass(UrlSlug, null, [{

@@ -280,5 +276,5 @@ key: "LOWERCASE_TRANSFORMER",

titlecase: UrlSlug.TITLECASE_TRANSFORMER
/* Prepare the global instance and export it */
};
/* Prepare the global instance and export it */
};
var urlSlug = new UrlSlug();

@@ -285,0 +281,0 @@ var global = urlSlug.convert.bind(urlSlug);

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

@@ -18,10 +18,9 @@ "main": "index.js",

"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.6",
"@babel/preset-env": "^7.8.6",
"@babel/register": "^7.8.6",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"mocha": "^6.2.0",
"sinon": "^7.3.2"
"cross-env": "^7.0.0",
"mocha": "^7.1.0"
},

@@ -28,0 +27,0 @@ "repository": "https://github.com/stldo/url-slug",

const expect = require('chai').expect
const sinon = require('sinon')

@@ -142,15 +141,12 @@ const urlSlug = require('../src/index')

.to.throw('transformer must be a function')
expect(() => new urlSlug.UrlSlug({ transformer: 'string' }))
expect(() => new urlSlug.UrlSlug({ transformer: 'string' }))
.to.throw('transformer must be a function')
expect(() => new urlSlug.UrlSlug({ transformer: {} }))
expect(() => new urlSlug.UrlSlug({ transformer: {} }))
.to.throw('transformer must be a function')
})
it('shows a deprecation warning message for tranformer strings', () => {
sinon.stub(console, 'warn')
new urlSlug.UrlSlug({ transformer: 'uppercase' })
expect(console.warn.getCall(0).args[0])
.to.be.string('DEPRECATION WARNING')
console.warn.restore()
})
it('throws a deprecation error for tranformer strings', () => {
expect(() => new urlSlug.UrlSlug({ transformer: 'uppercase' }))
.to.throw('Using transformer name as string was deprecated')
}) // TODO Remove in v3
})

@@ -157,0 +153,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc