devsite/node_modules/list-to-array/index.js

19 lines
382 B
JavaScript
Raw Permalink Normal View History

2024-07-08 01:49:38 +00:00
function truthy(val) { return val; }
function trim(str) { return str.trim(); }
function listToArray (str, delimiter) {
if (Array.isArray(str)) {
return str;
}
if (!str || typeof str !== 'string') {
return [];
}
if (!delimiter) {
delimiter = ' ';
str = str.replace(/\,/g, ' ');
}
return str.split(delimiter).map(trim).filter(truthy);
}
module.exports = listToArray;