@tsed/cli-core
Version:
Build your CLI with TypeScript and Decorators
24 lines (23 loc) • 695 B
JavaScript
import { Type } from "@tsed/core";
export function parseOption(value, options) {
const { type, itemType, customParser } = options;
if (type) {
switch (type) {
case String:
value = String(value);
break;
case Boolean: // the flag is added
return true;
case Number:
value = +value;
break;
case Array:
value = value.split(",").map((value) => parseOption(value, { type: itemType, customParser }));
break;
}
}
if (options.customParser) {
value = options.customParser(value);
}
return value;
}