hypnagaga_old/config/utils/index.js
2022-12-21 09:34:41 +01:00

24 lines
555 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
};