Sha256: 71efa2bc18848a9e4f53d8fe634050ec91e32ed45b0b3b789cb054773efb2509

Contents?: true

Size: 618 Bytes

Versions: 49

Compression:

Stored size: 618 Bytes

Contents

'use strict';

module.exports = function defFunc(ajv) {
  if (!ajv._opts.v5) console.warn('keywords if/then/else require v5 option');

  defFunc.definition = {
    macro: function (schema, parentSchema) {
      if (parentSchema.then === undefined)
        throw new Error('keyword "then" is absent');
      var cases = [ { 'if': schema, 'then': parentSchema.then } ];
      if (parentSchema.else !== undefined)
        cases[1] = { 'then': parentSchema.else };
      return { switch: cases };
    }
  };

  ajv.addKeyword('if', defFunc.definition);
  ajv.addKeyword('then');
  ajv.addKeyword('else');
  return ajv;
};

Version data entries

49 entries across 49 versions & 4 rubygems

Version Path
ilog-0.4.1 node_modules/ajv-keywords/keywords/if.js
ilog-0.4.0 node_modules/ajv-keywords/keywords/if.js
ilog-0.3.3 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-18.0.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.21.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.20.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.19.1 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.19.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.18.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.17.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.16.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.15.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.14.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.13.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.12.2 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.12.1 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.12.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.11.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.10.0 node_modules/ajv-keywords/keywords/if.js
govuk_publishing_components-17.9.0 node_modules/ajv-keywords/keywords/if.js