source: trip-planner-front/node_modules/ajv/dist/compile/validate/defaults.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.assignDefaults = void 0;
4const codegen_1 = require("../codegen");
5const util_1 = require("../util");
6function assignDefaults(it, ty) {
7 const { properties, items } = it.schema;
8 if (ty === "object" && properties) {
9 for (const key in properties) {
10 assignDefault(it, key, properties[key].default);
11 }
12 }
13 else if (ty === "array" && Array.isArray(items)) {
14 items.forEach((sch, i) => assignDefault(it, i, sch.default));
15 }
16}
17exports.assignDefaults = assignDefaults;
18function assignDefault(it, prop, defaultValue) {
19 const { gen, compositeRule, data, opts } = it;
20 if (defaultValue === undefined)
21 return;
22 const childData = codegen_1._ `${data}${codegen_1.getProperty(prop)}`;
23 if (compositeRule) {
24 util_1.checkStrictMode(it, `default is ignored for: ${childData}`);
25 return;
26 }
27 let condition = codegen_1._ `${childData} === undefined`;
28 if (opts.useDefaults === "empty") {
29 condition = codegen_1._ `${condition} || ${childData} === null || ${childData} === ""`;
30 }
31 // `${childData} === undefined` +
32 // (opts.useDefaults === "empty" ? ` || ${childData} === null || ${childData} === ""` : "")
33 gen.if(condition, codegen_1._ `${childData} = ${codegen_1.stringify(defaultValue)}`);
34}
35//# sourceMappingURL=defaults.js.map
Note: See TracBrowser for help on using the repository browser.