Socket
Socket
Sign inDemoInstall

simple-runtypes

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.0.1

4

CHANGELOG.md

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

### 6.0.1
- fix: rename `useRuntype` to `use`
### 6.0.0

@@ -2,0 +6,0 @@

2

dist/custom.d.ts

@@ -30,2 +30,2 @@ import { Fail, Runtype } from './runtype';

*/
export declare function useRuntype<T>(r: Runtype<T>, v: unknown): ValidationResult<T>;
export declare function use<T>(r: Runtype<T>, v: unknown): ValidationResult<T>;
export { getFormattedError, getFormattedErrorPath, getFormattedErrorValue, } from './runtypeError';
export { Fail, Runtype, RuntypeError, RuntypeUsageError } from './runtype';
export { createError, runtype, useRuntype, ValidationResult } from './custom';
export { createError, runtype, use, ValidationResult } from './custom';
export { any } from './any';

@@ -5,0 +5,0 @@ export { boolean } from './boolean';

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

function useRuntype(r, v) {
function use(r, v) {
var result = r(v, failSymbol);

@@ -1280,3 +1280,3 @@

exports.unknown = unknown;
exports.useRuntype = useRuntype;
exports.use = use;
//# sourceMappingURL=simple-runtypes.cjs.development.js.map

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

"use strict";function r(r,e){var t;if(void 0===e&&(e=512),void 0===r)return"undefined";try{t=JSON.stringify(r)}catch(e){t=""+r}return t.length>e?t.slice(0,e-1)+"…":t}function e(r){return Array.isArray(r.path)?[].concat(r.path).reverse().map((function(r){return"number"==typeof r?"["+r+"]":/^([A-z0-9_])+$/.test(r)?"."+r:"['"+JSON.stringify(r)+"']"})).join("").slice(1):"(error is not a RuntypeError!)"}function t(e,t){return void 0===t&&(t=512),r(e.value,t)}function n(){return(n=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}function o(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e}function i(r){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function u(r,e){return(u=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(r){return!1}}function a(r,e,t){return(a=f()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(r,n));return t&&u(o,t.prototype),o}).apply(null,arguments)}function c(r){var e="function"==typeof Map?new Map:void 0;return(c=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return a(r,arguments,i(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),u(t,r)})(r)}Object.defineProperty(exports,"__esModule",{value:!0});var s=function(r){function e(e,t,n){var o;return(o=r.call(this,e)||this).name="RuntypeError",o.reason=e,o.path=n,o.value=t,o}return o(e,r),e}(c(Error)),p=function(r){function e(){return r.apply(this,arguments)||this}return o(e,r),e}(c(Error)),l=Symbol("SimpleRuntypesFail");function v(r,e,t){if(void 0===r)throw new s(e,t,[]);var n;if(r===l)return(n={})[l]=!0,n.reason=e,n.path=[],n.value=void 0,n;throw new p("failOrThrow must be undefined or the failSymbol, not "+JSON.stringify(r))}function d(r,e,t,n){if(void 0!==n&&e.path.push(n),void 0===r)throw new s(e.reason,t,e.path);if(r===l)return e;throw new p("failOrThrow must be undefined or the failSymbol, not "+JSON.stringify(r))}var y=Symbol("isPure");function h(r,e){if(!0===e)return Object.assign(r,{isPure:y});if(void 0===e||!1===e)return r;throw new p('expected "isPure" or undefined as the second argument')}function g(r){return!!r.isPure}function x(r){return!("object"!=typeof r||!r)&&r[l]}var b=h((function(r,e){return!0===r||!1===r?r:v(e,"expected a boolean",r)}),!0),m=h((function(r,e){return"object"!=typeof r||Array.isArray(r)||null===r?v(e,"expected an object",r):r}),!0),w=h((function(r,e){return"string"==typeof r?r:v(e,"expected a string",r)}),!0),O=h((function(r,e){return"number"==typeof r&&Number.isSafeInteger(r)?r:v(e,"expected a safe integer",r)}),!0),j=h((function(r,e){if("string"==typeof r){var t=parseInt(r,10),n=O(t,l);if(x(n))return d(e,n,r);var o="-0"===r?"0":"+"===r[0]?r.slice(1):r;return n.toString()!==o?v(e,"expected string to contain only the safe integer, not additional characters, whitespace or leading zeros",r):n}return v(e,"expected a string that contains a safe integer",r)})),_=h((function(r,e){return Array.isArray(r)?r:v(e,"expected an Array",r)}),!0);function S(e,t){var n=Object.values(e).every((function(r){return g(r)})),o=t||!n,i=h((function(n,i){var u=m(n,i);if(x(u))return d(i,u,n);var f=o?{}:u;for(var a in e){var c=e[a](u[a],l);if(x(c))return d(i,c,n,a);o&&(f[a]=c)}if(!t){var s=Object.keys(u).filter((function(r){return!Object.prototype.hasOwnProperty.call(e,r)}));if(s.length)return v(i,"invalid keys in record "+r(s),n)}return f}),n),u={};for(var f in e)u[f]=e[f];return i.fields=u,i}function P(r){if(r.fields)return r.fields}function A(r){return S(r,!1)}function E(r,e){return"fields"in r&&"fields"in e?function(r,e){var t={},o=r.fields,i=e.fields;for(var u in n({},o,{},i))if(o[u]&&i[u])t[u]=R(o[u],i[u]);else if(o[u])t[u]=o[u];else{if(!i[u])throw new p("invalid else");t[u]=i[u]}return A(t)}(r,e):h((function(t,n){var o=r(t,n),i=e(t,n);return x(i)?d(n,i,t):x(o)?d(n,o,t):i}),g(r)&&g(e))}function R(){if(2===arguments.length)return E(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(3===arguments.length)return R(E(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]),arguments.length<=2?void 0:arguments[2]);throw new p("unsupported number of arguments "+arguments.length)}function k(e,t){var n=new Map;return t.forEach((function(t){var o=t.fields[e].literal;if(void 0===o)throw new p("broken record type definition, "+t+"["+e+"] is not a literal");if("string"!=typeof o&&"number"!=typeof o)throw new p("broken record type definition, "+t+"["+e+"] must be a string or number, not "+r(o));n.set(o,t)})),h((function(t,o){var i=m(t,o);if(x(i))return d(o,i,t);var u=i[e],f=n.get(u);return void 0===f?v(o,"no Runtype found for discriminated union tag "+e+": "+r(u),t):f(t,o)}),t.every((function(r){return g(r)})))}function I(r){for(var e=new Map,t=0;t<r.length;t++){var n=P(r[t]);if(!n)return;for(var o in n){var i,u=n[o].literal;void 0!==u&&(e.has(o)||e.set(o,new Set),null===(i=e.get(o))||void 0===i||i.add(u))}}var f=[];if(e.forEach((function(e,t){e.size===r.length&&f.push(t)})),f.length)return f[0]}exports.RuntypeError=s,exports.RuntypeUsageError=p,exports.any=function(){return h((function(r){return r}),!0)},exports.array=function(r,e){var t=e||{},n=t.maxLength,o=t.minLength,i=g(r);return h((function(e,t){var u=_(e,t);if(x(u))return d(t,u,e);if(void 0!==n&&u.length>n)return v(t,"expected the array to contain at most "+n+" elements",e);if(void 0!==o&&u.length<o)return v(t,"expected the array to contain at least "+o+" elements",e);for(var f=i?u:new Array(u.length),a=0;a<u.length;a++){var c=r(u[a],l);if(x(c))return d(t,c,e,a);i||(f[a]=c)}return f}),i)},exports.boolean=function(){return b},exports.createError=function(r){return v(l,r)},exports.enum=function(e){return h((function(t,n){return"number"==typeof t&&void 0!==e[t]||-1!==Object.values(e).indexOf(t)?t:v(n,"expected a value that belongs to the enum "+r(e),t)}),!0)},exports.getFormattedError=function(r,n){void 0===n&&(n=512);var o=e(r),i=o?"<value>."+o:"<value>",u="name"in r?r.name+": ":"",f=t(r,n);return""+u+r.reason+" at `"+i+"` in `"+f+"`"},exports.getFormattedErrorPath=e,exports.getFormattedErrorValue=t,exports.guardedBy=function(r){return h((function(e,t){return r(e)?e:v(t,"expected typeguard to return true",e)}),!0)},exports.ignore=function(){return h((function(){}),!0)},exports.integer=function(r){if(!r)return O;var e=r.min,t=r.max;return h((function(r,n){var o=O(r,n);return x(o)?d(n,o,r):void 0!==e&&o<e?v(n,"expected the integer to be >= "+e,r):void 0!==t&&o>t?v(n,"expected the integer to be <= "+t,r):o}),!0)},exports.intersection=R,exports.literal=function(e){var t=h((function(t,n){return t===e?e:v(n,"expected a literal: "+r(e),t)}),!0);return t.literal=e,t},exports.null=function(){return h((function(r,e){return null!==r?v(e,"expected null",r):r}),!0)},exports.nullable=function(r){return h((function(e,t){return null===e?null:r(e,t)}),g(r))},exports.number=function(r){var e=r||{},t=e.allowNaN,n=e.allowInfinity,o=e.min,i=e.max;return h((function(r,e){return"number"!=typeof r?v(e,"expected a number",r):!t&&isNaN(r)?v(e,"expected a number that is not NaN",r):n||Infinity!==r&&-Infinity!==r?void 0!==o&&r<o?v(e,"expected number to be >= "+o,r):void 0!==i&&r>i?v(e,"expected number to be <= "+i,r):r:v(e,"expected a finite number",r)}),!0)},exports.numberIndex=function(e){var t=g(e);return h((function(n,o){var i=m(n,o);if(x(i))return d(o,i,n);if(Object.getOwnPropertySymbols(i).length)return v(o,"invalid key in stringIndex: "+r(Object.getOwnPropertySymbols(i)),n);var u=t?i:{};for(var f in i){if("__proto__"===f)return v(o,"invalid key in stringIndex: "+r(f),n);var a=j(f,o);if(x(a))return d(o,a,n);var c=e(i[a],l);if(x(c))return d(o,c,n,a);t||(u[a]=c)}return u}),!0)},exports.object=function(){return m},exports.omit=function(r){var e=r.fields;if(!e)throw new p("expected a record runtype");for(var t=n({},e),o=arguments.length,i=new Array(o>1?o-1:0),u=1;u<o;u++)i[u-1]=arguments[u];return i.forEach((function(r){delete t[r]})),A(t)},exports.optional=function(r){return h((function(e,t){if(void 0!==e)return r(e,t)}),g(r))},exports.pick=function(r){var e=r.fields;if(!e)throw new p("expected a record runtype");for(var t={},n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return o.forEach((function(r){t[r]=e[r]})),A(t)},exports.record=A,exports.runtype=function(r){return h((function(e,t){var n=r(e);return x(n)?d(t,n,e):n}))},exports.sloppyRecord=function(r){return S(r,!0)},exports.string=function(r){if(!r)return w;var e=r.maxLength,t=r.trim;return h((function(r,n){var o=w(r,n);return x(o)?d(n,o,r):void 0!==e&&o.length>e?v(n,"expected the string length to not exceed "+e,r):t?o.trim():o}),!t)},exports.stringAsInteger=function(r){if(!r)return j;var e=r.min,t=r.max;return h((function(r,n){var o=j(r,n);return x(o)?d(n,o,r):void 0!==e&&o<e?v(n,"expected the integer to be >= "+e,r):void 0!==t&&o>t?v(n,"expected the integer to be <= "+t,r):o}))},exports.stringIndex=function(e){var t=g(e);return h((function(n,o){var i=m(n,o);if(x(i))return d(o,i,n);if(Object.getOwnPropertySymbols(i).length)return v(o,"invalid key in stringIndex: "+r(Object.getOwnPropertySymbols(i)),n);var u=t?i:{};for(var f in i){if("__proto__"===f)return v(o,"invalid key in stringIndex: "+r(f),n);var a=e(i[f],l);if(x(a))return d(o,a,n,f);t||(u[f]=a)}return u}),t)},exports.stringLiteralUnion=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=new Set(e);return h((function(r,t){return"string"==typeof r&&n.has(r)?r:v(t,"expected one of "+e,r)}),!0)},exports.tuple=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=e.every((function(r){return g(r)}));return h((function(r,t){var o=_(r,t);if(x(o))return d(t,o,r);if(o.length!==e.length)return v(t,"tuple array does not have the required length",r);for(var i=n?o:new Array(o.length),u=0;u<e.length;u++){var f=e[u](o[u],l);if(x(f))return d(t,f,r,u);n||(i[u]=f)}return i}),n)},exports.undefined=function(){return h((function(r,e){return void 0!==r?v(e,"expected undefined",r):r}),!0)},exports.union=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];if(!e.length)throw new p("no runtypes given to union");var n=I(e);if(void 0!==n)return k(n,e);var o=e.every((function(r){return g(r)}));return h((function(r,t){for(var n,o=0;o<e.length;o++){var i=e[o](r,l);if(!x(i))return i;n=i}return d(t,n,r)}),o)},exports.unknown=function(){return h((function(r){return r}),!0)},exports.useRuntype=function(r,e){var t=r(e,l);return x(t)?(t.value=e,{ok:!1,error:t}):{ok:!0,result:t}};
"use strict";function r(r,e){var t;if(void 0===e&&(e=512),void 0===r)return"undefined";try{t=JSON.stringify(r)}catch(e){t=""+r}return t.length>e?t.slice(0,e-1)+"…":t}function e(r){return Array.isArray(r.path)?[].concat(r.path).reverse().map((function(r){return"number"==typeof r?"["+r+"]":/^([A-z0-9_])+$/.test(r)?"."+r:"['"+JSON.stringify(r)+"']"})).join("").slice(1):"(error is not a RuntypeError!)"}function t(e,t){return void 0===t&&(t=512),r(e.value,t)}function n(){return(n=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}function o(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,r.__proto__=e}function i(r){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)})(r)}function u(r,e){return(u=Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(r){return!1}}function a(r,e,t){return(a=f()?Reflect.construct:function(r,e,t){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(r,n));return t&&u(o,t.prototype),o}).apply(null,arguments)}function c(r){var e="function"==typeof Map?new Map:void 0;return(c=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(r))return e.get(r);e.set(r,t)}function t(){return a(r,arguments,i(this).constructor)}return t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),u(t,r)})(r)}Object.defineProperty(exports,"__esModule",{value:!0});var s=function(r){function e(e,t,n){var o;return(o=r.call(this,e)||this).name="RuntypeError",o.reason=e,o.path=n,o.value=t,o}return o(e,r),e}(c(Error)),l=function(r){function e(){return r.apply(this,arguments)||this}return o(e,r),e}(c(Error)),p=Symbol("SimpleRuntypesFail");function v(r,e,t){if(void 0===r)throw new s(e,t,[]);var n;if(r===p)return(n={})[p]=!0,n.reason=e,n.path=[],n.value=void 0,n;throw new l("failOrThrow must be undefined or the failSymbol, not "+JSON.stringify(r))}function d(r,e,t,n){if(void 0!==n&&e.path.push(n),void 0===r)throw new s(e.reason,t,e.path);if(r===p)return e;throw new l("failOrThrow must be undefined or the failSymbol, not "+JSON.stringify(r))}var y=Symbol("isPure");function h(r,e){if(!0===e)return Object.assign(r,{isPure:y});if(void 0===e||!1===e)return r;throw new l('expected "isPure" or undefined as the second argument')}function g(r){return!!r.isPure}function x(r){return!("object"!=typeof r||!r)&&r[p]}var b=h((function(r,e){return!0===r||!1===r?r:v(e,"expected a boolean",r)}),!0),m=h((function(r,e){return"object"!=typeof r||Array.isArray(r)||null===r?v(e,"expected an object",r):r}),!0),w=h((function(r,e){return"string"==typeof r?r:v(e,"expected a string",r)}),!0),O=h((function(r,e){return"number"==typeof r&&Number.isSafeInteger(r)?r:v(e,"expected a safe integer",r)}),!0),j=h((function(r,e){if("string"==typeof r){var t=parseInt(r,10),n=O(t,p);if(x(n))return d(e,n,r);var o="-0"===r?"0":"+"===r[0]?r.slice(1):r;return n.toString()!==o?v(e,"expected string to contain only the safe integer, not additional characters, whitespace or leading zeros",r):n}return v(e,"expected a string that contains a safe integer",r)})),_=h((function(r,e){return Array.isArray(r)?r:v(e,"expected an Array",r)}),!0);function S(e,t){var n=Object.values(e).every((function(r){return g(r)})),o=t||!n,i=h((function(n,i){var u=m(n,i);if(x(u))return d(i,u,n);var f=o?{}:u;for(var a in e){var c=e[a](u[a],p);if(x(c))return d(i,c,n,a);o&&(f[a]=c)}if(!t){var s=Object.keys(u).filter((function(r){return!Object.prototype.hasOwnProperty.call(e,r)}));if(s.length)return v(i,"invalid keys in record "+r(s),n)}return f}),n),u={};for(var f in e)u[f]=e[f];return i.fields=u,i}function P(r){if(r.fields)return r.fields}function A(r){return S(r,!1)}function E(r,e){return"fields"in r&&"fields"in e?function(r,e){var t={},o=r.fields,i=e.fields;for(var u in n({},o,{},i))if(o[u]&&i[u])t[u]=k(o[u],i[u]);else if(o[u])t[u]=o[u];else{if(!i[u])throw new l("invalid else");t[u]=i[u]}return A(t)}(r,e):h((function(t,n){var o=r(t,n),i=e(t,n);return x(i)?d(n,i,t):x(o)?d(n,o,t):i}),g(r)&&g(e))}function k(){if(2===arguments.length)return E(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]);if(3===arguments.length)return k(E(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]),arguments.length<=2?void 0:arguments[2]);throw new l("unsupported number of arguments "+arguments.length)}function I(e,t){var n=new Map;return t.forEach((function(t){var o=t.fields[e].literal;if(void 0===o)throw new l("broken record type definition, "+t+"["+e+"] is not a literal");if("string"!=typeof o&&"number"!=typeof o)throw new l("broken record type definition, "+t+"["+e+"] must be a string or number, not "+r(o));n.set(o,t)})),h((function(t,o){var i=m(t,o);if(x(i))return d(o,i,t);var u=i[e],f=n.get(u);return void 0===f?v(o,"no Runtype found for discriminated union tag "+e+": "+r(u),t):f(t,o)}),t.every((function(r){return g(r)})))}function R(r){for(var e=new Map,t=0;t<r.length;t++){var n=P(r[t]);if(!n)return;for(var o in n){var i,u=n[o].literal;void 0!==u&&(e.has(o)||e.set(o,new Set),null===(i=e.get(o))||void 0===i||i.add(u))}}var f=[];if(e.forEach((function(e,t){e.size===r.length&&f.push(t)})),f.length)return f[0]}exports.RuntypeError=s,exports.RuntypeUsageError=l,exports.any=function(){return h((function(r){return r}),!0)},exports.array=function(r,e){var t=e||{},n=t.maxLength,o=t.minLength,i=g(r);return h((function(e,t){var u=_(e,t);if(x(u))return d(t,u,e);if(void 0!==n&&u.length>n)return v(t,"expected the array to contain at most "+n+" elements",e);if(void 0!==o&&u.length<o)return v(t,"expected the array to contain at least "+o+" elements",e);for(var f=i?u:new Array(u.length),a=0;a<u.length;a++){var c=r(u[a],p);if(x(c))return d(t,c,e,a);i||(f[a]=c)}return f}),i)},exports.boolean=function(){return b},exports.createError=function(r){return v(p,r)},exports.enum=function(e){return h((function(t,n){return"number"==typeof t&&void 0!==e[t]||-1!==Object.values(e).indexOf(t)?t:v(n,"expected a value that belongs to the enum "+r(e),t)}),!0)},exports.getFormattedError=function(r,n){void 0===n&&(n=512);var o=e(r),i=o?"<value>."+o:"<value>",u="name"in r?r.name+": ":"",f=t(r,n);return""+u+r.reason+" at `"+i+"` in `"+f+"`"},exports.getFormattedErrorPath=e,exports.getFormattedErrorValue=t,exports.guardedBy=function(r){return h((function(e,t){return r(e)?e:v(t,"expected typeguard to return true",e)}),!0)},exports.ignore=function(){return h((function(){}),!0)},exports.integer=function(r){if(!r)return O;var e=r.min,t=r.max;return h((function(r,n){var o=O(r,n);return x(o)?d(n,o,r):void 0!==e&&o<e?v(n,"expected the integer to be >= "+e,r):void 0!==t&&o>t?v(n,"expected the integer to be <= "+t,r):o}),!0)},exports.intersection=k,exports.literal=function(e){var t=h((function(t,n){return t===e?e:v(n,"expected a literal: "+r(e),t)}),!0);return t.literal=e,t},exports.null=function(){return h((function(r,e){return null!==r?v(e,"expected null",r):r}),!0)},exports.nullable=function(r){return h((function(e,t){return null===e?null:r(e,t)}),g(r))},exports.number=function(r){var e=r||{},t=e.allowNaN,n=e.allowInfinity,o=e.min,i=e.max;return h((function(r,e){return"number"!=typeof r?v(e,"expected a number",r):!t&&isNaN(r)?v(e,"expected a number that is not NaN",r):n||Infinity!==r&&-Infinity!==r?void 0!==o&&r<o?v(e,"expected number to be >= "+o,r):void 0!==i&&r>i?v(e,"expected number to be <= "+i,r):r:v(e,"expected a finite number",r)}),!0)},exports.numberIndex=function(e){var t=g(e);return h((function(n,o){var i=m(n,o);if(x(i))return d(o,i,n);if(Object.getOwnPropertySymbols(i).length)return v(o,"invalid key in stringIndex: "+r(Object.getOwnPropertySymbols(i)),n);var u=t?i:{};for(var f in i){if("__proto__"===f)return v(o,"invalid key in stringIndex: "+r(f),n);var a=j(f,o);if(x(a))return d(o,a,n);var c=e(i[a],p);if(x(c))return d(o,c,n,a);t||(u[a]=c)}return u}),!0)},exports.object=function(){return m},exports.omit=function(r){var e=r.fields;if(!e)throw new l("expected a record runtype");for(var t=n({},e),o=arguments.length,i=new Array(o>1?o-1:0),u=1;u<o;u++)i[u-1]=arguments[u];return i.forEach((function(r){delete t[r]})),A(t)},exports.optional=function(r){return h((function(e,t){if(void 0!==e)return r(e,t)}),g(r))},exports.pick=function(r){var e=r.fields;if(!e)throw new l("expected a record runtype");for(var t={},n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return o.forEach((function(r){t[r]=e[r]})),A(t)},exports.record=A,exports.runtype=function(r){return h((function(e,t){var n=r(e);return x(n)?d(t,n,e):n}))},exports.sloppyRecord=function(r){return S(r,!0)},exports.string=function(r){if(!r)return w;var e=r.maxLength,t=r.trim;return h((function(r,n){var o=w(r,n);return x(o)?d(n,o,r):void 0!==e&&o.length>e?v(n,"expected the string length to not exceed "+e,r):t?o.trim():o}),!t)},exports.stringAsInteger=function(r){if(!r)return j;var e=r.min,t=r.max;return h((function(r,n){var o=j(r,n);return x(o)?d(n,o,r):void 0!==e&&o<e?v(n,"expected the integer to be >= "+e,r):void 0!==t&&o>t?v(n,"expected the integer to be <= "+t,r):o}))},exports.stringIndex=function(e){var t=g(e);return h((function(n,o){var i=m(n,o);if(x(i))return d(o,i,n);if(Object.getOwnPropertySymbols(i).length)return v(o,"invalid key in stringIndex: "+r(Object.getOwnPropertySymbols(i)),n);var u=t?i:{};for(var f in i){if("__proto__"===f)return v(o,"invalid key in stringIndex: "+r(f),n);var a=e(i[f],p);if(x(a))return d(o,a,n,f);t||(u[f]=a)}return u}),t)},exports.stringLiteralUnion=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=new Set(e);return h((function(r,t){return"string"==typeof r&&n.has(r)?r:v(t,"expected one of "+e,r)}),!0)},exports.tuple=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];var n=e.every((function(r){return g(r)}));return h((function(r,t){var o=_(r,t);if(x(o))return d(t,o,r);if(o.length!==e.length)return v(t,"tuple array does not have the required length",r);for(var i=n?o:new Array(o.length),u=0;u<e.length;u++){var f=e[u](o[u],p);if(x(f))return d(t,f,r,u);n||(i[u]=f)}return i}),n)},exports.undefined=function(){return h((function(r,e){return void 0!==r?v(e,"expected undefined",r):r}),!0)},exports.union=function(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];if(!e.length)throw new l("no runtypes given to union");var n=R(e);if(void 0!==n)return I(n,e);var o=e.every((function(r){return g(r)}));return h((function(r,t){for(var n,o=0;o<e.length;o++){var i=e[o](r,p);if(!x(i))return i;n=i}return d(t,n,r)}),o)},exports.unknown=function(){return h((function(r){return r}),!0)},exports.use=function(r,e){var t=r(e,p);return x(t)?(t.value=e,{ok:!1,error:t}):{ok:!0,result:t}};
//# sourceMappingURL=simple-runtypes.cjs.production.min.js.map

@@ -344,3 +344,3 @@ /**

function useRuntype(r, v) {
function use(r, v) {
var result = r(v, failSymbol);

@@ -1242,3 +1242,3 @@

export { RuntypeError, RuntypeUsageError, any, array, _boolean as boolean, createError, enumRuntype as enum, getFormattedError, getFormattedErrorPath, getFormattedErrorValue, guardedBy, ignore, integer, intersection, literal, nullRuntype as null, nullable, number, numberIndex, object, omit, optional, pick, record, runtype, sloppyRecord, string, stringAsInteger, stringIndex, stringLiteralUnion, tuple, undefinedRuntype as undefined, union, unknown, useRuntype };
export { RuntypeError, RuntypeUsageError, any, array, _boolean as boolean, createError, enumRuntype as enum, getFormattedError, getFormattedErrorPath, getFormattedErrorValue, guardedBy, ignore, integer, intersection, literal, nullRuntype as null, nullable, number, numberIndex, object, omit, optional, pick, record, runtype, sloppyRecord, string, stringAsInteger, stringIndex, stringLiteralUnion, tuple, undefinedRuntype as undefined, union, unknown, use };
//# sourceMappingURL=simple-runtypes.esm.js.map
{
"name": "simple-runtypes",
"version": "6.0.0",
"version": "6.0.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "author": "Erik Söhnel",

@@ -68,3 +68,3 @@ [![npm version](https://badge.fury.io/js/simple-runtypes.svg)](https://www.npmjs.com/package/simple-runtypes)

You can also `use` a runtype without throwing errors:
You can also [`use`](src/custom.ts#L51) a runtype without throwing errors:

@@ -103,7 +103,8 @@ ```typescript

A [`Runtype`](src/runtype.ts#L79) is a function that:
A [`Runtype`](src/runtype.ts#L106) is a function that:
1. receives an unknown value
2. returns that value or a copy if all validations pass
3. throws a [`RuntypeError`](src/runtypeError.ts#L30) when validation fails
3. throws a [`RuntypeError`](src/runtype.ts#L7) when validation fails
or returns [`ValidationResult`](src/custom.ts#L37) when passed to [`use`](src/custom.ts#L51)

@@ -182,3 +183,3 @@ ```typescript

Simple-runtypes supports [Discriminating Unions](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#discriminating-unions) via the [`union`](src/union.ts#L137) runtype.
Simple-runtypes supports [Discriminating Unions](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#discriminating-unions) via the [`union`](src/union.ts#L138) runtype.

@@ -250,5 +251,5 @@ The example found in the [Typescript Handbook](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#discriminating-unions) translated to simple-runtypes:

- [`nullable`](src/nullable.ts#L11)
- [`union`](src/union.ts#L137)
- [`union`](src/union.ts#L138)
- [`intersection`](src/intersection.ts#L72)
- [`omit`](src/omit.ts#L9)
- [`omit`](src/omit.ts#L8)

@@ -258,3 +259,3 @@ ### Roadmap / Todos

- rename [`sloppyRecord`](src/record.ts#L97) to `record.sloppy` because I need
the `sloppy`-concept for other runtypes too: e.g. `nullable.sloppy` - a
the "sloppy"-concept for other runtypes too: e.g. `nullable.sloppy` - a
`Runtype<T | null>` that also accepts `undefined` which is useful to slowly

@@ -261,0 +262,0 @@ add new nullable fields to existing json database records

Sorry, the diff of this file is not supported yet

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc