24 lines
560 B
JavaScript
24 lines
560 B
JavaScript
const slugify = require('slugify');
|
|
|
|
/** Converts string to a slug form. */
|
|
const slugifyString = str => {
|
|
return slugify(str, {
|
|
replacement: '-',
|
|
remove: /[#,&,+()$~%.'":*¿?¡!<>{}]/g,
|
|
lower: true
|
|
});
|
|
};
|
|
|
|
/** throw an error if the provided argument is not of the expected. */
|
|
const throwIfNotType = (arg, expectedType) => {
|
|
if (typeof arg !== expectedType) {
|
|
throw new Error(
|
|
`Expected argument of type ${expectedType} but instead got ${arg} (${typeof arg})`
|
|
);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
slugifyString,
|
|
throwIfNotType
|
|
};
|