UNPKG

@jil/args

Version:

A convention based argument parsing and formatting library, with strict validation checks

26 lines 843 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.castValue = void 0; const constants_1 = require("../constants"); function castValue(value, type, multiple) { if (multiple && !Array.isArray(value)) { return []; } if (Array.isArray(value)) { return value.map(val => castValue(val, type)); } switch (type) { case 'boolean': { const bool = String(value).toLowerCase(); return bool === 'true' || bool === 'on' || bool === 'yes' || bool === '1'; } case 'number': { const number = Number(value); return Number.isNaN(number) ? constants_1.DEFAULT_NUMBER_VALUE : number; } default: return String(value); } } exports.castValue = castValue; //# sourceMappingURL=castValue.js.map