hexo/node_modules/@babel/helper-validator-option/lib/validator.js.map

1 line
3.8 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"names":["OptionValidator","constructor","descriptor","validateTopLevelOptions","options","TopLevelOptionShape","validOptionNames","Object","keys","option","includes","Error","formatMessage","findSuggestion","validateBooleanOption","name","value","defaultValue","undefined","invariant","validateStringOption","condition","message"],"sources":["../src/validator.ts"],"sourcesContent":["import { findSuggestion } from \"./find-suggestion\";\n\nexport class OptionValidator {\n declare descriptor: string;\n constructor(descriptor: string) {\n this.descriptor = descriptor;\n }\n\n /**\n * Validate if the given `options` follow the name of keys defined in the `TopLevelOptionShape`\n *\n * @param {Object} options\n * @param {Object} TopLevelOptionShape\n * An object with all the valid key names that `options` should be allowed to have\n * The property values of `TopLevelOptionShape` can be arbitrary\n * @memberof OptionValidator\n */\n validateTopLevelOptions(options: Object, TopLevelOptionShape: Object): void {\n const validOptionNames = Object.keys(TopLevelOptionShape);\n for (const option of Object.keys(options)) {\n if (!validOptionNames.includes(option)) {\n throw new Error(\n this.formatMessage(`'${option}' is not a valid top-level option.\n- Did you mean '${findSuggestion(option, validOptionNames)}'?`),\n );\n }\n }\n }\n\n // note: we do not consider rewrite them to high order functions\n // until we have to support `validateNumberOption`.\n validateBooleanOption<T>(\n name: string,\n value?: boolean,\n defaultValue?: T,\n ): boolean | T {\n if (value === undefined) {\n return defaultValue;\n } else {\n this.invariant(\n typeof value === \"boolean\",\n `'${name}' option must be a boolean.`,\n );\n }\n return value;\n }\n\n validateStringOption<T>(\n name: string,\n value?: string,\n defaultValue?: T,\n ): string | T {\n if (value === undefined) {\n return defaultValue;\n } else {\n this.invariant(\n typeof value === \"string\",\n `'${name}' option must be a string.`,\n );\n }\n return value;\n }\n /**\n * A helper interface copied from the `invariant` npm package.\n * It throws given `message` when `condition` is not met\n *\n * @param {boolean} condition\n * @param {string} message\n * @memberof OptionValidator\n */\n invariant(condition: boolean, message: string): void {\n if (!condition) {\n throw new Error(this.formatMessage(message));\n }\n }\n\n formatMessage(message: string): string {\n return `${this.descriptor}: ${message}`;\n }\n}\n"],"mappings":";;;;;;AAAA;AAEO,MAAMA,eAAe,CAAC;EAE3BC,WAAW,CAACC,UAAkB,EAAE;IAC9B,IAAI,CAACA,UAAU,GAAGA,UAAU;EAC9B;EAWAC,uBAAuB,CAACC,OAAe,EAAEC,mBAA2B,EAAQ;IAC1E,MAAMC,gBAAgB,GAAGC,MAAM,CAACC,IAAI,CAACH,mBAAmB,CAAC;IACzD,KAAK,MAAMI,MAAM,IAAIF,MAAM,CAACC,IAAI,CAACJ,OAAO,CAAC,EAAE;MACzC,IAAI,CAACE,gBAAgB,CAACI,QAAQ,CAACD,MAAM,CAAC,EAAE;QACtC,MAAM,IAAIE,KAAK,CACb,IAAI,CAACC,aAAa,CAAE,IAAGH,MAAO;AACxC,kBAAkB,IAAAI,8BAAc,EAACJ,MAAM,EAAEH,gBAAgB,CAAE,IAAG,CAAC,CACtD;MACH;IACF;EACF;EAIAQ,qBAAqB,CACnBC,IAAY,EACZC,KAAe,EACfC,YAAgB,EACH;IACb,IAAID,KAAK,KAAKE,SAAS,EAAE;MACvB,OAAOD,YAAY;IACrB,CAAC,MAAM;MACL,IAAI,CAACE,SAAS,CACZ,OAAOH,KAAK,KAAK,SAAS,EACzB,IAAGD,IAAK,6BAA4B,CACtC;IACH;IACA,OAAOC,KAAK;EACd;EAEAI,oBAAoB,CAClBL,IAAY,EACZC,KAAc,EACdC,YAAgB,EACJ;IACZ,IAAID,KAAK,KAAKE,SAAS,EAAE;MACvB,OAAOD,YAAY;IACrB,CAAC,MAAM;MACL,IAAI,CAACE,SAAS,CACZ,OAAOH,KAAK,KAAK,QAAQ,EACxB,IAAGD,IAAK,4BAA2B,CACrC;IACH;IACA,OAAOC,KAAK;EACd;EASAG,SAAS,CAACE,SAAkB,EAAEC,OAAe,EAAQ;IACnD,IAAI,CAACD,SAAS,EAAE;MACd,MAAM,IAAIV,KAAK,CAAC,IAAI,CAACC,aAAa,CAACU,OAAO,CAAC,CAAC;IAC9C;EACF;EAEAV,aAAa,CAACU,OAAe,EAAU;IACrC,OAAQ,GAAE,IAAI,CAACpB,UAAW,KAAIoB,OAAQ,EAAC;EACzC;AACF;AAAC"}