UNPKG

@wordpress/url

Version:
37 lines (32 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanForSlug = cleanForSlug; var _lodash = require("lodash"); /** * External dependencies */ /** * Performs some basic cleanup of a string for use as a post slug. * * This replicates some of what `sanitize_title()` does in WordPress core, but * is only designed to approximate what the slug will be. * * Converts whitespace, periods, forward slashes and underscores to hyphens. * Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin * letters. Removes combining diacritical marks. Converts remaining string * to lowercase. It does not touch octets, HTML entities, or other encoded * characters. * * @param {string} string Title or slug to be processed. * * @return {string} Processed string. */ function cleanForSlug(string) { if (!string) { return ''; } return (0, _lodash.toLower)((0, _lodash.deburr)((0, _lodash.trim)(string.replace(/[\s\./_]+/g, '-'), '-'))); } //# sourceMappingURL=clean-for-slug.js.map