2020-03-20 19:00:48 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const slugify = require('@sindresorhus/slugify');
|
|
|
|
|
|
|
|
const nameToSlug = name => slugify(name, { separator: '-' });
|
|
|
|
|
|
|
|
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
|
|
|
|
2020-04-30 12:11:12 +02:00
|
|
|
const escapeQuery = (query, charsToEscape, escapeChar = '\\') => {
|
2020-04-24 12:06:35 +02:00
|
|
|
return query
|
|
|
|
.split('')
|
|
|
|
.reduce(
|
|
|
|
(escapedQuery, char) =>
|
|
|
|
charsToEscape.includes(char)
|
2020-04-30 12:11:12 +02:00
|
|
|
? `${escapedQuery}${escapeChar}${char}`
|
2020-04-24 12:06:35 +02:00
|
|
|
: `${escapedQuery}${char}`,
|
|
|
|
''
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-20 19:00:48 +01:00
|
|
|
module.exports = {
|
|
|
|
nameToSlug,
|
|
|
|
nameToCollectionName,
|
2020-04-24 12:06:35 +02:00
|
|
|
escapeQuery,
|
2020-03-20 19:00:48 +01:00
|
|
|
};
|