@onesy/utils
Version:
22 lines (19 loc) • 618 B
JavaScript
import is from './is';
import cleanValue from './cleanValue';
const optionsDefault = {
lowercase: true
};
const slugify = function (value_) {
let options_ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const options = { ...optionsDefault,
...options_
};
let value = cleanValue(value_, {
replaceWith: '-',
lowercase: options.lowercase,
filters: [..."s$*_+~,.()'\"!-;:@".split(''), '\s+', '-+']
}); // Remove all leading and ending hypens in the value
if (is('string', value)) value = value.replace(/(^-+|-+$)/g, '');
return value;
};
export default slugify;