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

runtypes

Package Overview
Dependencies
Maintainers
2
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 6.1.0 to 6.2.0

2

lib/types/constraint.d.ts

@@ -7,3 +7,3 @@ import { Runtype, RuntypeBase, Static } from '../runtype';

underlying: A;
constraint(x: Static<A>): boolean | string;
constraint: ConstraintCheck<A>;
name?: string;

@@ -10,0 +10,0 @@ args?: K;

@@ -43,2 +43,4 @@ import { Runtype, RuntypeBase, Static } from '../runtype';

asReadonly(): InternalRecord<O, Part, true>;
pick<K extends keyof O>(...keys: K[] extends (keyof O)[] ? K[] : never[]): InternalRecord<Pick<O, K>, Part, RO>;
omit<K extends keyof O>(...keys: K[] extends (keyof O)[] ? K[] : never[]): InternalRecord<Omit<O, K>, Part, RO>;
}

@@ -45,0 +47,0 @@ export declare type Record<O extends {

@@ -95,2 +95,4 @@ "use strict";

A.asReadonly = asReadonly;
A.pick = pick;
A.omit = omit;
return A;

@@ -103,2 +105,26 @@ function asPartial() {

}
function pick() {
var keys = [];
for (var _i = 0; _i < arguments.length; _i++) {
keys[_i] = arguments[_i];
}
var result = {};
keys.forEach(function (key) {
result[key] = A.fields[key];
});
return InternalRecord(result, A.isPartial, A.isReadonly);
}
function omit() {
var keys = [];
for (var _i = 0; _i < arguments.length; _i++) {
keys[_i] = arguments[_i];
}
var result = {};
var existingKeys = util_1.enumerableKeysOf(A.fields);
existingKeys.forEach(function (key) {
if (!keys.includes(key))
result[key] = A.fields[key];
});
return InternalRecord(result, A.isPartial, A.isReadonly);
}
}

@@ -37,3 +37,4 @@ "use strict";

return typeof object === 'object' && object !== null
? Reflect.ownKeys(object).filter(function (key) { return object.propertyIsEnumerable(key); })
? // Objects with a null prototype may not have `propertyIsEnumerable`
Reflect.ownKeys(object).filter(function (key) { var _a, _b; return (_b = (_a = object.propertyIsEnumerable) === null || _a === void 0 ? void 0 : _a.call(object, key)) !== null && _b !== void 0 ? _b : true; })
: [];

@@ -40,0 +41,0 @@ };

{
"name": "runtypes",
"version": "6.1.0",
"version": "6.2.0",
"description": "Runtime validation for static types",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -425,2 +425,20 @@ # Runtypes [![Build Status](https://travis-ci.org/pelotom/runtypes.svg?branch=master)](https://travis-ci.org/pelotom/runtypes) [![Coverage Status](https://coveralls.io/repos/github/pelotom/runtypes/badge.svg?branch=master)](https://coveralls.io/github/pelotom/runtypes?branch=master)

## `.pick` and `.omit`
`Record` runtype has the methods `.pick()` and `.omit()`, which will return a new `Record` with or without specified fields:
```ts
const CrewMember = Record({
name: String,
rank: Rank,
home: Planet,
});
const PetMember = CrewMember.pick('name', 'home');
type PetMember = Static<typeof PetMember>; // { name: string; home: Planet; }
const Background = CrewMember.omit('name');
type Background = Static<typeof Background>; // { rank: Rank; home: Planet; }
```
## Related libraries

@@ -427,0 +445,0 @@

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