Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

superstruct

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superstruct - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

9

lib/index.es.js

@@ -937,3 +937,3 @@ /**

const validate = (value = resolveDefaults(defaults)) => {
let error;
const errors = [];

@@ -947,7 +947,6 @@ for (const k of kinds) {

error = e;
errors.push(e);
}
error.type = type;
return [error];
errors[0].type = type;
return errors;
};

@@ -954,0 +953,0 @@

@@ -941,3 +941,3 @@ 'use strict';

const validate = (value = resolveDefaults(defaults)) => {
let error;
const errors = [];

@@ -951,7 +951,6 @@ for (const k of kinds) {

error = e;
errors.push(e);
}
error.type = type;
return [error];
errors[0].type = type;
return errors;
};

@@ -958,0 +957,0 @@

{
"name": "superstruct",
"description": "A simple, expressive way to validate data in JavaScript.",
"version": "0.5.1",
"version": "0.5.2",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git",

@@ -915,3 +915,3 @@ (function (global, factory) {

const validate = (value = resolveDefaults(defaults)) => {
let error;
const errors = [];

@@ -925,7 +925,6 @@ for (const k of kinds) {

error = e;
errors.push(e);
}
error.type = type;
return [error];
errors[0].type = type;
return errors;
};

@@ -932,0 +931,0 @@

@@ -1,1 +0,1 @@

!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.Superstruct={})}(this,function(t){"use strict";function r(t){return t.constructor?t.constructor.name:null}function e(t){return!(!t||!t[m])}function n(t,r){return"function"==typeof t?t(r):t}function a(t,r,n){if(e(t))return t[w];if(t instanceof g)return t;switch(b(t)){case"array":return t.length>1?d(t,r,n):s(t,r,n);case"function":return i(t,r,n);case"object":return u(t,r,n);case"string":{let e,a=!0;if(t.endsWith("?")&&(a=!1,t=t.slice(0,-1)),t.includes("|")){e=p(t.split(/\s*\|\s*/g),r,n)}else if(t.includes("&")){e=l(t.split(/\s*&\s*/g),r,n)}else e=f(t,r,n);return a||(e=c(e,void 0,n)),e}}throw new Error(`A schema definition must be an object, array, string or function, but you passed: ${t}`)}function o(t,r,e){if("array"!==b(t))throw new Error(`Enum structs must be defined as an array, but you passed: ${t}`);const a=t.map(t=>{try{return JSON.stringify(t)}catch(r){return String(t)}}).join(" | ");return new g("enum",a,(e=n(r))=>t.includes(e)?[void 0,e]:[{data:e,path:[],value:e,type:a}])}function i(t,r,e){if("function"!==b(t))throw new Error(`Function structs must be defined as a function, but you passed: ${t}`);return new g("function","<function>",(e=n(r),a)=>{const o=t(e,a),i="string"===b(o),s="boolean"===b(o);if(!i&&!s)throw new Error(`Validator functions must return a boolean or an error reason string, but you passed: ${t}`);return!i&&o?[void 0,e]:[{type:"<function>",value:e,data:e,path:[],reason:i?o:void 0}]})}function s(t,r,e){if("array"!==b(t)||1!==t.length)throw new Error(`List structs must be defined as an array with a single element, but you passed: ${t}`);const o=f("array",void 0,e),i=a(t[0],void 0,e),s=`[${i.type}]`;return new g("list",s,(t=n(r))=>{const[e,a]=o.validate(t);if(e)return e.type=s,[e];t=a;const u=[],c=[];for(let r=0;r<t.length;r++){const e=t[r],[n,a]=i.validate(e);n?(n.path=[r].concat(n.path),n.data=t,u.push(n)):c[r]=a}if(u.length){const t=u[0];return t.errors=u,[t]}return[void 0,c]})}function u(t,r,e){if("object"!==b(t))throw new Error(`Object structs must be defined as an object, but you passed: ${t}`);const o=f("object",void 0,e),i=[],s={};for(const r in t){i.push(r);const n=a(t[r],void 0,e);s[r]=n}const u=`{${i.join()}}`;return new g("object",u,(t=n(r))=>{const[e]=o.validate(t);if(e)return e.type=u,[e];const a=[],i={},c=Object.keys(t),f=Object.keys(s);if(new Set(c.concat(f)).forEach(e=>{let o=t[e];const u=s[e];if(void 0===o&&(o=n(r&&r[e],t)),!u){const r={data:t,path:[e],value:o};return void a.push(r)}const[c,f]=u.validate(o,t);if(c)return c.path=[e].concat(c.path),c.data=t,void a.push(c);(e in t||void 0!==f)&&(i[e]=f)}),a.length){const t=a[0];return t.errors=a,[t]}return[void 0,i]})}function c(t,r,e){return p([t,"undefined"],r,e)}function f(t,r,e){if("string"!==b(t))throw new Error(`Scalar structs must be defined as a string, but you passed: ${t}`);const{types:n}=e,a=n[t];if("function"!==b(a))throw new Error(`No struct validator function found for type "${t}".`);const o=i(a,r),s=t;return new g("scalar",s,t=>{const[r,e]=o.validate(t);return r?(r.type=s,[r]):[void 0,e]})}function d(t,r,e){if("array"!==b(t))throw new Error(`Tuple structs must be defined as an array, but you passed: ${t}`);const o=t.map(t=>a(t,void 0,e)),i=f("array",void 0,e),s=`[${o.map(t=>t.type).join()}]`;return new g("tuple",s,(t=n(r))=>{const[e]=i.validate(t);if(e)return e.type=s,[e];const a=[],u=[],c=Math.max(t.length,o.length);for(let r=0;r<c;r++){const e=o[r],n=t[r];if(!e){const e={data:t,path:[r],value:n};u.push(e);continue}const[i,s]=e.validate(n);i?(i.path=[r].concat(i.path),i.data=t,u.push(i)):a[r]=s}if(u.length){const t=u[0];return t.errors=u,[t]}return[void 0,a]})}function p(t,r,e){if("array"!==b(t))throw new Error(`Union structs must be defined as an array, but you passed: ${t}`);const o=t.map(t=>a(t,void 0,e)),i=o.map(t=>t.type).join(" | ");return new g("union",i,(t=n(r))=>{let e;for(const r of o){const[n,a]=r.validate(t);if(!n)return[void 0,a];e=n}return e.type=i,[e]})}function l(t,r,e){if("array"!==b(t))throw new Error(`Intersection structs must be defined as an array, but you passed: ${t}`);const o=t.map(t=>a(t,void 0,e)),i=o.map(t=>t.type).join(" & ");return new g("intersection",i,(t=n(r))=>{let e=t;for(const t of o){const[r,n]=t.validate(e);if(r)return r.type=i,[r];e=n}return[void 0,e]})}function y(t={}){function r(t,r,a={}){function o(t){if(this instanceof o)throw new Error("The `Struct` creation function should not be used with the `new` keyword.");return o.assert(t)}e(t)&&(t=t.schema);const i=j.any(t,r,$({},a,{types:n}));return Object.defineProperty(o,m,{value:!0}),Object.defineProperty(o,w,{value:i}),o.kind=i.name,o.type=i.type,o.schema=t,o.defaults=r,o.options=a,o.assert=(t=>{const[r,e]=i.validate(t);if(r)throw new h(r);return e}),o.test=(t=>{const[r]=i.validate(t);return!r}),o.validate=(t=>{const[r,e]=i.validate(t);return r?[new h(r)]:[void 0,e]}),o}const n=$({},E,t.types||{});return Object.keys(j).forEach(t=>{const e=j[t];r[t]=((t,a,o)=>{return r(e(t,a,$({},o,{types:n})),a,o)})}),r}class h extends TypeError{static format(t){const{type:r,path:e,value:n}=t;return`Expected a value of type \`${r}\`${e.length?` for \`${e.join(".")}\``:""} but received \`${JSON.stringify(n)}\`.`}constructor(t){super(h.format(t));const{data:r,path:e,value:n,reason:a,type:o,errors:i=[]}=t;this.data=r,this.path=e,this.value=n,this.reason=a,this.type=o,this.errors=i,i.length||i.push(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack}}var v=Object.prototype.toString,b=function(t){if(void 0===t)return"undefined";if(null===t)return"null";var e=typeof t;if("boolean"===e)return"boolean";if("string"===e)return"string";if("number"===e)return"number";if("symbol"===e)return"symbol";if("function"===e)return function(t,e){return"GeneratorFunction"===r(t)}(t)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(t))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(t))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}(t))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(t))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(t))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(t))return"regexp";switch(r(t)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(t))return"generator";switch(e=v.call(t)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return e.slice(8,-1).toLowerCase().replace(/\s/g,"")};const m="@@__STRUCT__@@",w="@@__KIND__@@";class g{constructor(t,r,e){this.name=t,this.type=r,this.validate=e}}const j={any:a,dict:function(t,r,e){if("array"!==b(t)||2!==t.length)throw new Error(`Dict structs must be defined as an array with two elements, but you passed: ${t}`);const o=f("object",void 0,e),i=a(t[0],void 0,e),s=a(t[1],void 0,e),u=`dict<${i.type},${s.type}>`;return new g("dict",u,(t=n(r))=>{const[e]=o.validate(t);if(e)return e.type=u,[e];const a={},c=[];for(let r in t){const e=t[r],[n,o]=i.validate(r);if(n){n.path=[r].concat(n.path),n.data=t,c.push(n);continue}r=o;const[u,f]=s.validate(e);u?(u.path=[r].concat(u.path),u.data=t,c.push(u)):a[r]=f}if(c.length){const t=c[0];return t.errors=c,[t]}return[void 0,a]})},enum:o,enums:function(t,r,e){return s([o(t,void 0)],r,e)},function:i,instance:function(t,r,e){const a=`instance<${t.name}>`;return new g("instance",a,(e=n(r))=>e instanceof t?[void 0,e]:[{data:e,path:[],value:e,type:a}])},interface:function(t,r,e){if("object"!==b(t))throw new Error(`Interface structs must be defined as an object, but you passed: ${t}`);const o=[],i={};for(const r in t){o.push(r);const n=a(t[r],void 0,e);i[r]=n}const s=`{${o.join()}}`;return new g("interface",s,(t=n(r))=>{const e=[];for(const r in i){const n=t[r],a=i[r],[o]=a.validate(n);o&&(o.path=[r].concat(o.path),o.data=t,e.push(o))}if(e.length){const t=e[0];return t.errors=e,[t]}return[void 0,t]})},lazy:function(t,r,e){if("function"!==b(t))throw new Error(`Lazy structs must be defined as an function that returns a schema, but you passed: ${t}`);let n,a;return n=new g("lazy","lazy...",r=>(a=t(),n.name=a.kind,n.type=a.type,n.validate=a.validate,n.validate(r)))},list:s,literal:function(t,r,e){const a=`literal: ${JSON.stringify(t)}`;return new g("literal",a,(e=n(r))=>e===t?[void 0,e]:[{data:e,path:[],value:e,type:a}])},object:u,optional:c,partial:function(t,r,e){if("object"!==b(t))throw new Error(`Partial structs must be defined as an object, but you passed: ${t}`);const o=f("object",void 0,e),i=[],s={};for(const r in t){i.push(r);const n=a(t[r],void 0,e);s[r]=n}const u=`{${i.join()},...}`;return new g("partial",u,(t=n(r))=>{const[e]=o.validate(t);if(e)return e.type=u,[e];const a=[],i={};for(const e in s){let o=t[e];const u=s[e];void 0===o&&(o=n(r&&r[e],t));const[c,f]=u.validate(o,t);c?(c.path=[e].concat(c.path),c.data=t,a.push(c)):(e in t||void 0!==f)&&(i[e]=f)}if(a.length){const t=a[0];return t.errors=a,[t]}return[void 0,i]})},scalar:f,tuple:d,union:p,intersection:l},E={any:t=>void 0!==t};["arguments","array","boolean","buffer","date","error","float32array","float64array","function","generatorfunction","int16array","int32array","int8array","map","null","number","object","promise","regexp","set","string","symbol","uint16array","uint32array","uint8array","uint8clampedarray","undefined","weakmap","weakset"].forEach(t=>{E[t]=(r=>b(r)===t)});var $=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t};const S=y();t.struct=S,t.superstruct=y,t.isStruct=e,t.StructError=h,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.Superstruct={})}(this,function(t){"use strict";function r(t){return t.constructor?t.constructor.name:null}function e(t){return!(!t||!t[m])}function n(t,r){return"function"==typeof t?t(r):t}function o(t,r,n){if(e(t))return t[w];if(t instanceof g)return t;switch(b(t)){case"array":return t.length>1?d(t,r,n):s(t,r,n);case"function":return i(t,r,n);case"object":return u(t,r,n);case"string":{let e,o=!0;if(t.endsWith("?")&&(o=!1,t=t.slice(0,-1)),t.includes("|")){e=p(t.split(/\s*\|\s*/g),r,n)}else if(t.includes("&")){e=y(t.split(/\s*&\s*/g),r,n)}else e=f(t,r,n);return o||(e=c(e,void 0,n)),e}}throw new Error(`A schema definition must be an object, array, string or function, but you passed: ${t}`)}function a(t,r,e){if("array"!==b(t))throw new Error(`Enum structs must be defined as an array, but you passed: ${t}`);const o=t.map(t=>{try{return JSON.stringify(t)}catch(r){return String(t)}}).join(" | ");return new g("enum",o,(e=n(r))=>t.includes(e)?[void 0,e]:[{data:e,path:[],value:e,type:o}])}function i(t,r,e){if("function"!==b(t))throw new Error(`Function structs must be defined as a function, but you passed: ${t}`);return new g("function","<function>",(e=n(r),o)=>{const a=t(e,o),i="string"===b(a),s="boolean"===b(a);if(!i&&!s)throw new Error(`Validator functions must return a boolean or an error reason string, but you passed: ${t}`);return!i&&a?[void 0,e]:[{type:"<function>",value:e,data:e,path:[],reason:i?a:void 0}]})}function s(t,r,e){if("array"!==b(t)||1!==t.length)throw new Error(`List structs must be defined as an array with a single element, but you passed: ${t}`);const a=f("array",void 0,e),i=o(t[0],void 0,e),s=`[${i.type}]`;return new g("list",s,(t=n(r))=>{const[e,o]=a.validate(t);if(e)return e.type=s,[e];t=o;const u=[],c=[];for(let r=0;r<t.length;r++){const e=t[r],[n,o]=i.validate(e);n?(n.path=[r].concat(n.path),n.data=t,u.push(n)):c[r]=o}if(u.length){const t=u[0];return t.errors=u,[t]}return[void 0,c]})}function u(t,r,e){if("object"!==b(t))throw new Error(`Object structs must be defined as an object, but you passed: ${t}`);const a=f("object",void 0,e),i=[],s={};for(const r in t){i.push(r);const n=o(t[r],void 0,e);s[r]=n}const u=`{${i.join()}}`;return new g("object",u,(t=n(r))=>{const[e]=a.validate(t);if(e)return e.type=u,[e];const o=[],i={},c=Object.keys(t),f=Object.keys(s);if(new Set(c.concat(f)).forEach(e=>{let a=t[e];const u=s[e];if(void 0===a&&(a=n(r&&r[e],t)),!u){const r={data:t,path:[e],value:a};return void o.push(r)}const[c,f]=u.validate(a,t);if(c)return c.path=[e].concat(c.path),c.data=t,void o.push(c);(e in t||void 0!==f)&&(i[e]=f)}),o.length){const t=o[0];return t.errors=o,[t]}return[void 0,i]})}function c(t,r,e){return p([t,"undefined"],r,e)}function f(t,r,e){if("string"!==b(t))throw new Error(`Scalar structs must be defined as a string, but you passed: ${t}`);const{types:n}=e,o=n[t];if("function"!==b(o))throw new Error(`No struct validator function found for type "${t}".`);const a=i(o,r),s=t;return new g("scalar",s,t=>{const[r,e]=a.validate(t);return r?(r.type=s,[r]):[void 0,e]})}function d(t,r,e){if("array"!==b(t))throw new Error(`Tuple structs must be defined as an array, but you passed: ${t}`);const a=t.map(t=>o(t,void 0,e)),i=f("array",void 0,e),s=`[${a.map(t=>t.type).join()}]`;return new g("tuple",s,(t=n(r))=>{const[e]=i.validate(t);if(e)return e.type=s,[e];const o=[],u=[],c=Math.max(t.length,a.length);for(let r=0;r<c;r++){const e=a[r],n=t[r];if(!e){const e={data:t,path:[r],value:n};u.push(e);continue}const[i,s]=e.validate(n);i?(i.path=[r].concat(i.path),i.data=t,u.push(i)):o[r]=s}if(u.length){const t=u[0];return t.errors=u,[t]}return[void 0,o]})}function p(t,r,e){if("array"!==b(t))throw new Error(`Union structs must be defined as an array, but you passed: ${t}`);const a=t.map(t=>o(t,void 0,e)),i=a.map(t=>t.type).join(" | ");return new g("union",i,(t=n(r))=>{const e=[];for(const r of a){const[n,o]=r.validate(t);if(!n)return[void 0,o];e.push(n)}return e[0].type=i,e})}function y(t,r,e){if("array"!==b(t))throw new Error(`Intersection structs must be defined as an array, but you passed: ${t}`);const a=t.map(t=>o(t,void 0,e)),i=a.map(t=>t.type).join(" & ");return new g("intersection",i,(t=n(r))=>{let e=t;for(const t of a){const[r,n]=t.validate(e);if(r)return r.type=i,[r];e=n}return[void 0,e]})}function l(t={}){function r(t,r,o={}){function a(t){if(this instanceof a)throw new Error("The `Struct` creation function should not be used with the `new` keyword.");return a.assert(t)}e(t)&&(t=t.schema);const i=j.any(t,r,$({},o,{types:n}));return Object.defineProperty(a,m,{value:!0}),Object.defineProperty(a,w,{value:i}),a.kind=i.name,a.type=i.type,a.schema=t,a.defaults=r,a.options=o,a.assert=(t=>{const[r,e]=i.validate(t);if(r)throw new h(r);return e}),a.test=(t=>{const[r]=i.validate(t);return!r}),a.validate=(t=>{const[r,e]=i.validate(t);return r?[new h(r)]:[void 0,e]}),a}const n=$({},E,t.types||{});return Object.keys(j).forEach(t=>{const e=j[t];r[t]=((t,o,a)=>{return r(e(t,o,$({},a,{types:n})),o,a)})}),r}class h extends TypeError{static format(t){const{type:r,path:e,value:n}=t;return`Expected a value of type \`${r}\`${e.length?` for \`${e.join(".")}\``:""} but received \`${JSON.stringify(n)}\`.`}constructor(t){super(h.format(t));const{data:r,path:e,value:n,reason:o,type:a,errors:i=[]}=t;this.data=r,this.path=e,this.value=n,this.reason=o,this.type=a,this.errors=i,i.length||i.push(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack}}var v=Object.prototype.toString,b=function(t){if(void 0===t)return"undefined";if(null===t)return"null";var e=typeof t;if("boolean"===e)return"boolean";if("string"===e)return"string";if("number"===e)return"number";if("symbol"===e)return"symbol";if("function"===e)return function(t,e){return"GeneratorFunction"===r(t)}(t)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(t))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(t))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}(t))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(t))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(t))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(t))return"regexp";switch(r(t)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(t))return"generator";switch(e=v.call(t)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return e.slice(8,-1).toLowerCase().replace(/\s/g,"")};const m="@@__STRUCT__@@",w="@@__KIND__@@";class g{constructor(t,r,e){this.name=t,this.type=r,this.validate=e}}const j={any:o,dict:function(t,r,e){if("array"!==b(t)||2!==t.length)throw new Error(`Dict structs must be defined as an array with two elements, but you passed: ${t}`);const a=f("object",void 0,e),i=o(t[0],void 0,e),s=o(t[1],void 0,e),u=`dict<${i.type},${s.type}>`;return new g("dict",u,(t=n(r))=>{const[e]=a.validate(t);if(e)return e.type=u,[e];const o={},c=[];for(let r in t){const e=t[r],[n,a]=i.validate(r);if(n){n.path=[r].concat(n.path),n.data=t,c.push(n);continue}r=a;const[u,f]=s.validate(e);u?(u.path=[r].concat(u.path),u.data=t,c.push(u)):o[r]=f}if(c.length){const t=c[0];return t.errors=c,[t]}return[void 0,o]})},enum:a,enums:function(t,r,e){return s([a(t,void 0)],r,e)},function:i,instance:function(t,r,e){const o=`instance<${t.name}>`;return new g("instance",o,(e=n(r))=>e instanceof t?[void 0,e]:[{data:e,path:[],value:e,type:o}])},interface:function(t,r,e){if("object"!==b(t))throw new Error(`Interface structs must be defined as an object, but you passed: ${t}`);const a=[],i={};for(const r in t){a.push(r);const n=o(t[r],void 0,e);i[r]=n}const s=`{${a.join()}}`;return new g("interface",s,(t=n(r))=>{const e=[];for(const r in i){const n=t[r],o=i[r],[a]=o.validate(n);a&&(a.path=[r].concat(a.path),a.data=t,e.push(a))}if(e.length){const t=e[0];return t.errors=e,[t]}return[void 0,t]})},lazy:function(t,r,e){if("function"!==b(t))throw new Error(`Lazy structs must be defined as an function that returns a schema, but you passed: ${t}`);let n,o;return n=new g("lazy","lazy...",r=>(o=t(),n.name=o.kind,n.type=o.type,n.validate=o.validate,n.validate(r)))},list:s,literal:function(t,r,e){const o=`literal: ${JSON.stringify(t)}`;return new g("literal",o,(e=n(r))=>e===t?[void 0,e]:[{data:e,path:[],value:e,type:o}])},object:u,optional:c,partial:function(t,r,e){if("object"!==b(t))throw new Error(`Partial structs must be defined as an object, but you passed: ${t}`);const a=f("object",void 0,e),i=[],s={};for(const r in t){i.push(r);const n=o(t[r],void 0,e);s[r]=n}const u=`{${i.join()},...}`;return new g("partial",u,(t=n(r))=>{const[e]=a.validate(t);if(e)return e.type=u,[e];const o=[],i={};for(const e in s){let a=t[e];const u=s[e];void 0===a&&(a=n(r&&r[e],t));const[c,f]=u.validate(a,t);c?(c.path=[e].concat(c.path),c.data=t,o.push(c)):(e in t||void 0!==f)&&(i[e]=f)}if(o.length){const t=o[0];return t.errors=o,[t]}return[void 0,i]})},scalar:f,tuple:d,union:p,intersection:y},E={any:t=>void 0!==t};["arguments","array","boolean","buffer","date","error","float32array","float64array","function","generatorfunction","int16array","int32array","int8array","map","null","number","object","promise","regexp","set","string","symbol","uint16array","uint32array","uint8array","uint8clampedarray","undefined","weakmap","weakset"].forEach(t=>{E[t]=(r=>b(r)===t)});var $=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t};const S=l();t.struct=S,t.superstruct=l,t.isStruct=e,t.StructError=h,Object.defineProperty(t,"__esModule",{value:!0})});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc