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

@cloudflare/util-en-garde

Package Overview
Dependencies
Maintainers
40
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/util-en-garde - npm Package Compare versions

Comparing version 7.2.0 to 8.0.0

18

CHANGELOG.md

@@ -6,2 +6,20 @@ # Change Log

# [8.0.0](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-en-garde@7.2.0...@cloudflare/util-en-garde@8.0.0) (2020-07-28)
### Bug Fixes
* **util-en-garde:** TSX-168 Allow optional keys to be missing ([5b3ceb2](http://stash.cfops.it:7999/fe/stratus/commits/5b3ceb2))
### BREAKING CHANGES
* **util-en-garde:** Previously if an optional key was missing while checking with an object's type
guard, it would say that it did NOT match the decoded type. Going forward, it will say that it DOES
match the decoded type.
# [7.2.0](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-en-garde@7.1.2...@cloudflare/util-en-garde@7.2.0) (2020-07-17)

@@ -8,0 +26,0 @@

3

dist/type-helpers.d.ts

@@ -34,1 +34,4 @@ /**

export declare const hasAtLeastTwo: <T>(ts: T[]) => ts is [T, T, ...T[]];
export declare function hasProperties<T extends object, K extends string>(obj: T, ...keys: K[]): obj is T & {
[J in K]: unknown;
};

12

es/index.js

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

@@ -13,2 +11,4 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

@@ -41,3 +41,3 @@

import * as t from 'io-ts';
import { objectKeys, hasAtLeastTwo } from './type-helpers';
import { objectKeys, hasAtLeastTwo, hasProperties } from './type-helpers';
/**

@@ -178,3 +178,7 @@ * Why does this wrapper exist?

_this3 = _possibleConstructorReturn(this, _getPrototypeOf(ObjectCodec).call(this, ioTsCodec.name, // these MUST be cast as any because the types don't line up and that's
ioTsCodec.is, ioTsCodec.validate, ioTsCodec.encode, ioTsCodec.props));
function (value) {
return _typeof(value) === 'object' && value !== null && Object.keys(ioTsCodec.props).every(function (key) {
return ioTsCodec.props[key].is(hasProperties(value, key) ? value[key] : undefined);
});
}, ioTsCodec.validate, ioTsCodec.encode, ioTsCodec.props));

@@ -181,0 +185,0 @@ _defineProperty(_assertThisInitialized(_assertThisInitialized(_this3)), "assertDecode", function (value) {

@@ -35,2 +35,11 @@ /**

return ts.length > 1;
};
};
export function hasProperties(obj) {
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
keys[_key - 1] = arguments[_key];
}
return !!obj && keys.every(function (key) {
return obj.hasOwnProperty(key);
});
}

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

@@ -29,2 +27,4 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

@@ -122,3 +122,7 @@

_this3 = _possibleConstructorReturn(this, _getPrototypeOf(ObjectCodec).call(this, ioTsCodec.name, // these MUST be cast as any because the types don't line up and that's
ioTsCodec.is, ioTsCodec.validate, ioTsCodec.encode, ioTsCodec.props));
function (value) {
return _typeof(value) === 'object' && value !== null && Object.keys(ioTsCodec.props).every(function (key) {
return ioTsCodec.props[key].is((0, _typeHelpers.hasProperties)(value, key) ? value[key] : undefined);
});
}, ioTsCodec.validate, ioTsCodec.encode, ioTsCodec.props));

@@ -125,0 +129,0 @@ _defineProperty(_assertThisInitialized(_assertThisInitialized(_this3)), "assertDecode", function (value) {

@@ -7,2 +7,3 @@ "use strict";

exports.objectKeys = objectKeys;
exports.hasProperties = hasProperties;
exports.hasAtLeastTwo = void 0;

@@ -47,2 +48,12 @@

exports.hasAtLeastTwo = hasAtLeastTwo;
exports.hasAtLeastTwo = hasAtLeastTwo;
function hasProperties(obj) {
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
keys[_key - 1] = arguments[_key];
}
return !!obj && keys.every(function (key) {
return obj.hasOwnProperty(key);
});
}
{
"name": "@cloudflare/util-en-garde",
"description": "",
"version": "7.2.0",
"version": "8.0.0",
"types": "./dist/index.d.ts",

@@ -29,3 +29,3 @@ "main": "lib/index.js",

},
"gitHead": "d8e7e783275d80f783cc84e2c4db2b49714c4896"
"gitHead": "881be2736ed4939143899fac09544b6bd803678a"
}
import * as t from 'io-ts';
import { Refinement } from 'fp-ts/lib/function';
import { Compute, objectKeys, hasAtLeastTwo, ValueOf } from './type-helpers';
import {
Compute,
objectKeys,
hasAtLeastTwo,
ValueOf,
hasProperties
} from './type-helpers';

@@ -136,3 +142,10 @@ /**

// what we want since we're enabling optional keys
ioTsCodec.is as any,
(value: unknown): value is any =>
typeof value === 'object' &&
value !== null &&
Object.keys(ioTsCodec.props).every(key =>
ioTsCodec.props[key].is(
hasProperties(value, key) ? value[key] : undefined
)
),
ioTsCodec.validate as any,

@@ -139,0 +152,0 @@ ioTsCodec.encode as any,

@@ -40,1 +40,8 @@ /**

ts.length > 1;
export function hasProperties<T extends object, K extends string>(
obj: T,
...keys: K[]
): obj is T & { [J in K]: unknown } {
return !!obj && keys.every(key => obj.hasOwnProperty(key));
}
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