franken-ui
Version:
Franken UI is an HTML-first, open-source library of UI components based on the utility-first Tailwind CSS with UIkit 3 compatibility. The design is based on shadcn/ui ported to be framework-agnostic.
31 lines (30 loc) • 902 B
JavaScript
import uniq from 'lodash/uniq.js';
export function parseArgs(args, safelist, map) {
const result = [];
const invalidCommands = [];
args.forEach((arg) => {
if (/^-[^-]/.test(arg)) {
for (let i = 1; i < arg.length; i++) {
const char = arg[i];
const mappedArg = map[char];
if (mappedArg && safelist.includes(mappedArg)) {
result.push(mappedArg);
}
else {
invalidCommands.push(`-${char}`);
}
}
}
else if (safelist.includes(arg)) {
result.push(arg);
}
else {
invalidCommands.push(arg);
}
});
if (invalidCommands.length > 0) {
console.error(`Invalid command ${invalidCommands.join(' ')}`);
process.exit(1);
}
return uniq(result);
}