archieve-projects/微信机器人/node_modules/cmd-ts/dist/cjs/oneOf.js

22 lines
675 B
JavaScript
Executable File

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.oneOf = void 0;
const util_1 = require("util");
/**
* A union of literals. When you want to take an exact enum value.
*/
function oneOf(literals) {
const examples = literals.map(x => util_1.inspect(x)).join(', ');
return {
async from(str) {
const value = literals.find(x => x === str);
if (!value) {
throw new Error(`Invalid value '${str}'. Expected one of: ${examples}`);
}
return value;
},
description: `One of ${examples}`,
};
}
exports.oneOf = oneOf;
//# sourceMappingURL=oneOf.js.map