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

18 lines
551 B
JavaScript
Executable File

import { inspect } from 'util';
/**
* A union of literals. When you want to take an exact enum value.
*/
export function oneOf(literals) {
const examples = literals.map(x => 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}`,
};
}
//# sourceMappingURL=oneOf.js.map