jscodeshaft
Version:
Collection of more or less primitive helpers and abstractions for JSCodeShift, build for design system migrations and upgrades.
20 lines (15 loc) • 469 B
JavaScript
import {isTruthyString} from '../../typeChecking';
/**
* Ensures the input is 1 or more of truthy strings and expressed as array.
* @param {(string|string[])} input
* @returns {string[]}
*/
export const toTruthyStringArray = (input) => {
const output = [];
if (isTruthyString(input)) {
output.push(input);
} else if (Array.isArray(input) && input.length > 0) {
output.push(...input.filter(item => isTruthyString(item)));
}
return output;
};