Merge pull request #651 from dopry/xx_remove_urlize
Remove unused urlize
This commit is contained in:
commit
717c14d116
@ -1,4 +1,3 @@
|
|||||||
import url from 'url';
|
|
||||||
import sanitizeFilename from 'sanitize-filename';
|
import sanitizeFilename from 'sanitize-filename';
|
||||||
import { isString, escapeRegExp, flow, partialRight } from 'lodash';
|
import { isString, escapeRegExp, flow, partialRight } from 'lodash';
|
||||||
|
|
||||||
@ -58,31 +57,3 @@ export function sanitizeSlug(str, { replacement = '-' } = {}) {
|
|||||||
return normalizedSlug;
|
return normalizedSlug;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function urlize(string) {
|
|
||||||
const sanitized = makePathSanitized(string);
|
|
||||||
const parsedURL = url.parse(sanitized);
|
|
||||||
|
|
||||||
return url.format(parsedURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
function makePathSanitized(string) {
|
|
||||||
return makePath(string.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
function makePath(string) {
|
|
||||||
return unicodeSanitize(string).trim().replace(/[\s]/g, '-').replace(/-+/g, '-');
|
|
||||||
}
|
|
||||||
|
|
||||||
function unicodeSanitize(string) {
|
|
||||||
let target = [];
|
|
||||||
const runes = string.split('');
|
|
||||||
for (let i=0; i < string.length; i++) {
|
|
||||||
const r = runes[i];
|
|
||||||
if (r == '%' && i+2 < string.length && string.substr(i+1, 2).match(/^[0-9a-f]+$/)) {
|
|
||||||
target = target.concat([r, runes[i+1], runes[i+2]]);
|
|
||||||
} else if (r.match(/[\w .\/\\_#\+-]/u)) {
|
|
||||||
target.push(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target.join('');
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user