UNPKG

@amaui/utils

Version:
24 lines (23 loc) 888 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const is_1 = __importDefault(require("./is")); const cleanValue_1 = __importDefault(require("./cleanValue")); const optionsDefault = { lowercase: true }; const slugify = (value_, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault), options_); let value = (0, cleanValue_1.default)(value_, { replaceWith: '-', lowercase: options.lowercase, filters: [...`\s$*_+~,.()'"!\-;:@`.split(''), '\s+', '-+'] }); // Remove all leading and ending hypens in the value if ((0, is_1.default)('string', value)) value = value.replace(/(^-+|-+$)/g, ''); return value; }; exports.default = slugify;