UNPKG

rizzo-next

Version:

The next generation of Lonely Planet's style guide and pattern library.

30 lines (22 loc) 789 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.slugify = undefined; var _deburr = require("lodash/deburr"); var _deburr2 = _interopRequireDefault(_deburr); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Takes a given string and turns it into a hyphenated slug * @param {String} string String to replace * @return {String} */ var clean = function clean(string) { // allow only basic latin alpha, numeric, / - _ and whitespace return (0, _deburr2.default)(string).replace(/[^/-\w\s]/gi, ""); }; var slugify = function slugify(string) { if (!string || typeof string !== "string") return ""; return clean(string).toLowerCase().replace(/\s/g, "-"); }; exports.slugify = slugify;