diff --git a/src/lib/urlHelper.js b/src/lib/urlHelper.js index 0080c02f..d320a972 100644 --- a/src/lib/urlHelper.js +++ b/src/lib/urlHelper.js @@ -1,4 +1,3 @@ -import url from 'url'; import sanitizeFilename from 'sanitize-filename'; import { isString, escapeRegExp, flow, partialRight } from 'lodash'; @@ -58,31 +57,3 @@ export function sanitizeSlug(str, { replacement = '-' } = {}) { 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(''); -}