2018-11-19 20:08:48 +03:00
|
|
|
const _ = require('lodash');
|
2024-06-24 11:01:36 +03:00
|
|
|
const {IncorrectUsageError} = require('@tryghost/errors');
|
2018-11-19 20:08:48 +03:00
|
|
|
|
2019-05-06 15:24:12 +03:00
|
|
|
/**
|
|
|
|
* @description Helper function to prepare params for internal usages.
|
|
|
|
*
|
|
|
|
* e.g. "a,B,c" -> ["a", "b", "c"]
|
|
|
|
*
|
|
|
|
* @param {String} params
|
|
|
|
* @return {Array}
|
|
|
|
*/
|
2018-11-19 20:08:48 +03:00
|
|
|
const trimAndLowerCase = (params) => {
|
|
|
|
params = params || '';
|
|
|
|
|
|
|
|
if (_.isString(params)) {
|
|
|
|
params = params.split(',');
|
|
|
|
}
|
|
|
|
|
2024-06-24 11:01:36 +03:00
|
|
|
// If we don't have an array at this point, something is wrong, so we should throw an
|
|
|
|
// error to avoid trying to .map over something else
|
|
|
|
if (!_.isArray(params)) {
|
|
|
|
throw new IncorrectUsageError({
|
|
|
|
message: 'Params must be a string or array'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-19 20:08:48 +03:00
|
|
|
return params.map((item) => {
|
|
|
|
return item.trim().toLowerCase();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.trimAndLowerCase = trimAndLowerCase;
|