react-slugify
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -6,3 +6,6 @@ import * as React from 'react'; | ||
} | ||
/** | ||
* Slugify a React node | ||
*/ | ||
declare const slugify: (node: React.ReactNode, options?: SlugifyOptions) => string; | ||
export default slugify; |
"use strict"; | ||
exports.__esModule = true; | ||
var stripAccents = function (str) { | ||
/** | ||
* Remove all accentuated characters from a string | ||
*/ | ||
var stripAccents = function (input) { | ||
var accents = 'ÀÁÂÃÄÅĄàáâãäåąÒÓÔÕÕÖØòóôõöøÈÉÊËĘèéêëðęÇĆçćÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠŚšśŸÿýŽŹŻžźżŁłŃń'; | ||
@@ -11,12 +14,30 @@ var fixes = 'AAAAAAAaaaaaaaOOOOOOOooooooEEEEEeeeeeeCCccDIIIIiiiiUUUUuuuuNnSSssYyyZZZzzzLlNn'; | ||
} | ||
return str.replace(reg, replacement); | ||
return input.replace(reg, replacement); | ||
}; | ||
var harmonize = function (text, delimiter, ignoreInvalid) { | ||
var getSafeRegexpString = function (input) { | ||
return input | ||
.split('') | ||
.map(function (char) { return "\\" + char; }) | ||
.join(''); | ||
}; | ||
/** | ||
* Harmonize a string by removing spaces, non-alphabetical caracters and by | ||
* adding delimiter | ||
*/ | ||
var harmonize = function (input, delimiter, ignoreInvalid) { | ||
if (ignoreInvalid === void 0) { ignoreInvalid = false; } | ||
var harmonized = stripAccents(text).trim().toLowerCase(); | ||
var harmonized = stripAccents(input).trim().toLowerCase(); | ||
var safeDelimiter = getSafeRegexpString(delimiter); | ||
if (ignoreInvalid) { | ||
return harmonized.replace(/\s+/g, delimiter); | ||
} | ||
return harmonized.replace(new RegExp("[^a-z0-9" + delimiter + "]+", 'g'), delimiter); | ||
return harmonized | ||
.replace(new RegExp("[^a-z0-9" + safeDelimiter + "]+", 'g'), delimiter) // Replace all non-valid caracters by delimiter | ||
.replace(new RegExp(safeDelimiter + "+", 'g'), delimiter) // Remove multiple delimiters repetition | ||
.replace(new RegExp("^" + safeDelimiter, 'g'), '') // remove delimiter at the beginning | ||
.replace(new RegExp(safeDelimiter + "$", 'g'), ''); // remove delimiter at the end | ||
}; | ||
/** | ||
* Slugify a React node | ||
*/ | ||
var slugify = function (node, options) { | ||
@@ -45,4 +66,2 @@ if (options === void 0) { options = { delimiter: '-', prefix: '' }; } | ||
} | ||
// We did the check about empty object before | ||
// const castedNode = node as React.ReactElement<any> | React.ReactNodeArray | React.ReactPortal; | ||
// ReactPortal | ||
@@ -54,3 +73,3 @@ if ('children' in node) { | ||
if (node instanceof Array) { | ||
return slugify(node.map(function (n) { return slugify(n, { delimiter: delimiter }); }).join(delimiter), options); | ||
return slugify(node.map(function (subNode) { return slugify(subNode, { delimiter: delimiter }); }).join(delimiter), options); | ||
} | ||
@@ -57,0 +76,0 @@ // ReactElement |
{ | ||
"name": "react-slugify", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Slugify a React node", | ||
@@ -32,9 +32,9 @@ "main": "dist/slugify.js", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.19", | ||
"@types/react": "^17.0.0", | ||
"jest": "^26.6.3", | ||
"react": "^17.0.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.2" | ||
"@types/jest": "^27.0.1", | ||
"@types/react": "^17.0.21", | ||
"jest": "^27.2.0", | ||
"react": "^17.0.2", | ||
"ts-jest": "^27.0.5", | ||
"typescript": "^4.4.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
9107
89