houdini/app/javascript/legacy/common/sanitize-slug.js

6 lines
268 B
JavaScript
Raw Permalink Normal View History

2019-11-06 20:36:28 +00:00
// License: LGPL-3.0-or-later
module.exports = str =>
str.trim().toLowerCase()
.replace(/\s*[^A-Za-z0-9\-]\s*/g, '-') // Replace any oddballs with a hyphen
.replace(/-+$/g,'').replace(/^-+/, '').replace(/-+/, '-') // Remove starting/trailing and repeated hyphens