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

runtypes

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

runtypes - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

13

lib/index.d.ts

@@ -122,2 +122,12 @@ /**

/**
* Construct a runtype for arbitrary dictionaries. Note that unlike Record, this provides no actual
* runtime validation of the keys or values.
*/
export declare function Dictionary<V>(keyType?: 'string'): Runtype<{
[_: string]: V;
}>;
export declare function Dictionary<V>(keyType?: 'number'): Runtype<{
[_: number]: V;
}>;
/**
* Construct a record runtype from runtypes for its values.

@@ -233,4 +243,1 @@ */

};
export declare function hasKey<K extends string>(k: K, o: {}): o is {
[_ in K]: {};
};

@@ -106,2 +106,10 @@ "use strict";

exports.Tuple = Tuple;
function Dictionary() {
return runtype(function (x) {
if (x === null || x === undefined)
throw new ValidationError("Expected a defined non-null value but was " + typeof x);
return x;
});
}
exports.Dictionary = Dictionary;
/**

@@ -112,4 +120,3 @@ * Construct a record runtype from runtypes for its values.

return runtype(function (x) {
if (x === null || x === undefined)
throw new ValidationError("Expected a defined non-null value but was " + typeof x);
Dictionary().check(x);
// tslint:disable-next-line:forin

@@ -268,2 +275,1 @@ for (var key in runtypes) {

}
exports.hasKey = hasKey;
{
"name": "runtypes",
"version": "0.6.2",
"version": "0.6.3",
"description": "Runtime validation for static types",

@@ -19,6 +19,6 @@ "main": "./lib/index.js",

"devDependencies": {
"@types/jest": "^16.0.4",
"@types/jest": "^18.1.1",
"jest": "^18.1.0",
"ts-jest": "^18.0.2",
"typescript": "^2.1.5",
"ts-jest": "^18.0.3",
"typescript": "2.1.6",
"xyz": "^2.1.0"

@@ -25,0 +25,0 @@ },

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

/**

@@ -232,5 +231,8 @@ * A successful validation result.

/**
* Construct a record runtype from runtypes for its values.
* Construct a runtype for arbitrary dictionaries. Note that unlike Record, this provides no actual
* runtime validation of the keys or values.
*/
export function Record<O>(runtypes: {[K in keyof O]: Runtype<O[K]> }): Runtype<O> {
export function Dictionary<V>(keyType?: 'string'): Runtype<{ [_: string]: V }>
export function Dictionary<V>(keyType?: 'number'): Runtype<{ [_: number]: V }>
export function Dictionary<V>() {
return runtype(x => {

@@ -240,2 +242,13 @@ if (x === null || x === undefined)

return x
})
}
/**
* Construct a record runtype from runtypes for its values.
*/
export function Record<O>(runtypes: {[K in keyof O]: Runtype<O[K]> }): Runtype<O> {
return runtype(x => {
Dictionary().check(x)
// tslint:disable-next-line:forin

@@ -1235,4 +1248,4 @@ for (const key in runtypes) {

// If this feature gets implemented, we can use `in` instead: https://github.com/Microsoft/TypeScript/issues/10485
export function hasKey<K extends string>(k: K, o: {}): o is { [_ in K]: {} } {
function hasKey<K extends string>(k: K, o: {}): o is { [_ in K]: {} } {
return typeof o === 'object' && k in o
}
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