public-apis/utils/db/format-categories.js
2022-11-18 18:51:59 +01:00

11 lines
297 B
JavaScript

module.exports = function (categories) {
return categories.map(category => ({
name: category,
slug: category
.trim()
.toLowerCase()
.replace(/&/g, 'and')
.replace(/[^A-Z0-9/]+/gi, '-')
.replace(/\s/g, '-'),
}))
}