New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

generic-type-guard

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-type-guard - npm Package Compare versions

Comparing version 3.4.1 to 3.4.2

etc/generic-type-guard.api.md

1

.eslintrc.js

@@ -5,2 +5,3 @@ module.exports = {

'@mscharley',
'@mscharley/eslint-config/node',
],

@@ -7,0 +8,0 @@ overrides: [

{
"typescript.tsdk": "node_modules/typescript/lib"
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#b0d867",
"activityBar.activeBorder": "#3496cb",
"activityBar.background": "#b0d867",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#3496cb",
"activityBarBadge.foreground": "#e7e7e7",
"sash.hoverBorder": "#b0d867",
"titleBar.activeBackground": "#9bce3e",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#9bce3e99",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "#9bce3e"
}

2

api-extractor.json

@@ -113,3 +113,3 @@ /**

*/
"enabled": false
"enabled": true

@@ -116,0 +116,0 @@ /**

# Install
```
yarn install
npm install
```

@@ -10,4 +10,4 @@

```
yarn build
yarn test
npm build
npm test
```

@@ -17,6 +17,9 @@

Ensure you're logged in with `npm login` and `yarn login`.
Ensure you're logged in with `npm login`.
```
yarn lerna publish
npm version <bump-type>
npm publish
```
Don't forget to commit and tag the version bump for GitHub releases too.

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

*/
var isUnion = function (ptt, ptu) { return function (o) { return ptt(o) || ptu(o); }; };
var isUnion = function (ptt, ptu) {
return function (o) {
return ptt(o) || ptu(o);
};
};
exports.isUnion = isUnion;

@@ -17,4 +21,8 @@ /**

*/
var isIntersection = function (ptt, ptu) { return function (o) { return ptt(o) && ptu(o); }; };
var isIntersection = function (ptt, ptu) {
return function (o) {
return ptt(o) && ptu(o);
};
};
exports.isIntersection = isIntersection;
//# sourceMappingURL=functions.js.map

@@ -0,0 +0,0 @@ "use strict";

@@ -35,26 +35,26 @@ "use strict";

var _this = this;
return function (obj) { return primitives_1.isObjectLike(obj) && _this.ptt(obj); };
return function (obj) { return (0, primitives_1.isObjectLike)(obj) && _this.ptt(obj); };
};
InterfaceStep.prototype["with"] = function (ptv) {
return new InterfaceStep(functions_1.isIntersection(this.ptt, ptv));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, ptv));
};
InterfaceStep.prototype.withProperty = function (key, ptv) {
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasProperty(key, ptv)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasProperty(key, ptv)));
};
InterfaceStep.prototype.withOptionalProperty = function (key, ptv) {
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasOptionalProperty(key, ptv)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasOptionalProperty(key, ptv)));
};
InterfaceStep.prototype.withStringIndexSignature = function (value, enforce) {
if (enforce === void 0) { enforce = true; }
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasStringIndexSignature(value, enforce)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasStringIndexSignature(value, enforce)));
};
InterfaceStep.prototype.withNumericIndexSignature = function (value, enforce) {
if (enforce === void 0) { enforce = true; }
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasNumericIndexSignature(value, enforce)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasNumericIndexSignature(value, enforce)));
};
InterfaceStep.prototype.withProperties = function (props) {
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasProperties(props)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasProperties(props)));
};
InterfaceStep.prototype.withOptionalProperties = function (props) {
return new InterfaceStep(functions_1.isIntersection(this.ptt, o.hasOptionalProperties(props)));
return new InterfaceStep((0, functions_1.isIntersection)(this.ptt, o.hasOptionalProperties(props)));
};

@@ -61,0 +61,0 @@ return InterfaceStep;

@@ -24,3 +24,3 @@ "use strict";

IntersectionOf.prototype["with"] = function (ptu) {
return new IntersectionOf(functions_1.isIntersection(this.ptt, ptu));
return new IntersectionOf((0, functions_1.isIntersection)(this.ptt, ptu));
};

@@ -27,0 +27,0 @@ return IntersectionOf;

@@ -24,3 +24,3 @@ "use strict";

UnionOf.prototype["with"] = function (ptv) {
return new UnionOf(functions_1.isUnion(this.ptt, ptv));
return new UnionOf((0, functions_1.isUnion)(this.ptt, ptv));
};

@@ -27,0 +27,0 @@ return UnionOf;

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

/**

@@ -26,3 +25,3 @@ * Asserts that a guard is successful.

*
* @param guards A list of partial typeguards to string together.
* @param guards - A list of partial typeguards to string together.
*

@@ -387,2 +386,9 @@ * @public

/**
* Validate if an object is a Set containing elements of a given type.
*
* @public
*/
export declare const isSetOf: <T>(tg: TypeGuard<T>) => (o: unknown) => o is Set<T>;
/**
* Validate if a value is a specific javascript number.

@@ -389,0 +395,0 @@ *

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ "use strict";

@@ -11,6 +11,8 @@ "use strict";

*/
var hasProperty = function (property, value) { return function (o) {
// If the property exists and conforms to the value type guard.
return value(o[property]);
}; };
var hasProperty = function (property, value) {
return function (o) {
// If the property exists and conforms to the value type guard.
return value(o[property]);
};
};
exports.hasProperty = hasProperty;

@@ -22,7 +24,9 @@ /**

*/
var hasOptionalProperty = function (property, value) { return function (o) {
return !(property in o) ||
// If the property exists and conforms to the value type guard.
value(o[property]);
}; };
var hasOptionalProperty = function (property, value) {
return function (o) {
return !(property in o) ||
// If the property exists and conforms to the value type guard.
value(o[property]);
};
};
exports.hasOptionalProperty = hasOptionalProperty;

@@ -36,5 +40,7 @@ /**

*/
var isRecord = function (property, value) { return function (o) {
return primitives_1.isObject(o) && exports.hasProperty(property, value)(o);
}; };
var isRecord = function (property, value) {
return function (o) {
return (0, primitives_1.isObject)(o) && (0, exports.hasProperty)(property, value)(o);
};
};
exports.isRecord = isRecord;

@@ -63,3 +69,2 @@ /**

}
/* eslint-disable-next-line @typescript-eslint/no-magic-numbers */
return !enforce || n > 0;

@@ -92,3 +97,2 @@ };

}
/* eslint-disable-next-line @typescript-eslint/no-magic-numbers */
return !enforce || n > 0;

@@ -103,3 +107,7 @@ };

*/
var isInstance = function (klass) { return function (o) { return o instanceof klass; }; };
var isInstance = function (klass) {
return function (o) {
return o instanceof klass;
};
};
exports.isInstance = isInstance;

@@ -114,10 +122,12 @@ /**

*/
var hasProperties = function (props) { return function (o) {
for (var prop in props) {
if (!exports.hasProperty(prop, props[prop])(o)) {
return false;
var hasProperties = function (props) {
return function (o) {
for (var prop in props) {
if (!(0, exports.hasProperty)(prop, props[prop])(o)) {
return false;
}
}
}
return true;
}; };
return true;
};
};
exports.hasProperties = hasProperties;

@@ -131,18 +141,20 @@ /**

*/
var hasOnlyProperties = function (props) { return function (o) {
var found = [];
for (var prop in o) {
if (prop in props) {
var propsKey = prop;
if (!exports.hasProperty(propsKey, props[propsKey])(o)) {
var hasOnlyProperties = function (props) {
return function (o) {
var found = [];
for (var prop in o) {
if (prop in props) {
var propsKey = prop;
if (!(0, exports.hasProperty)(propsKey, props[propsKey])(o)) {
return false;
}
found.push(propsKey);
}
else {
return false;
}
found.push(propsKey);
}
else {
return false;
}
}
return found.length === Object.keys(props).length;
}; };
return found.length === Object.keys(props).length;
};
};
exports.hasOnlyProperties = hasOnlyProperties;

@@ -157,10 +169,12 @@ /**

*/
var hasOptionalProperties = function (props) { return function (o) {
for (var prop in props) {
if (!exports.hasOptionalProperty(prop, props[prop])(o)) {
return false;
var hasOptionalProperties = function (props) {
return function (o) {
for (var prop in props) {
if (!(0, exports.hasOptionalProperty)(prop, props[prop])(o)) {
return false;
}
}
}
return true;
}; };
return true;
};
};
exports.hasOptionalProperties = hasOptionalProperties;

@@ -172,4 +186,6 @@ /**

*/
var isExactObject = function (props) { return utils_1.combine(primitives_1.isObject, exports.hasProperties(props)); };
var isExactObject = function (props) {
return (0, utils_1.combine)(primitives_1.isObject, (0, exports.hasProperties)(props));
};
exports.isExactObject = isExactObject;
//# sourceMappingURL=objects.js.map
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
exports.__esModule = true;
exports.isNever = exports.isUnknown = exports.isAny = exports.isSet = exports.isObject = exports.isObjectLike = exports.narrowArray = exports.narrowValue = exports.isArray = exports.isMissing = exports.isNullable = exports.isOptional = exports.isUndefined = exports.isNull = exports.isBoolean = exports.isSingletonStringUnion = exports.isSingletonString = exports.isString = exports.isSingletonNumberUnion = exports.isSingletonNumber = exports.isElementOf = exports.isNaN = exports.isInfinity = exports.isDouble = exports.isFloat = exports.isFiniteNumber = exports.isNumber = void 0;
exports.isNever = exports.isUnknown = exports.isAny = exports.isSet = exports.isObject = exports.isObjectLike = exports.isSetOf = exports.narrowArray = exports.narrowValue = exports.isArray = exports.isMissing = exports.isNullable = exports.isOptional = exports.isUndefined = exports.isNull = exports.isBoolean = exports.isSingletonStringUnion = exports.isSingletonString = exports.isString = exports.isSingletonNumberUnion = exports.isSingletonNumber = exports.isElementOf = exports.isNaN = exports.isInfinity = exports.isDouble = exports.isFloat = exports.isFiniteNumber = exports.isNumber = void 0;
var MINIMUM_ARRAY_INDEX = 0;

@@ -10,5 +35,3 @@ /**

*/
var isNumber = function (n) {
return typeof n === 'number' && !global.isNaN(n);
};
var isNumber = function (n) { return typeof n === 'number' && !isNaN(n); };
exports.isNumber = isNumber;

@@ -21,3 +44,3 @@ /**

var isFiniteNumber = function (n) {
return typeof n === 'number' && !global.isNaN(n) && global.isFinite(n);
return typeof n === 'number' && !isNaN(n) && isFinite(n);
};

@@ -33,5 +56,3 @@ exports.isFiniteNumber = isFiniteNumber;

*/
var isFloat = function (n) {
return typeof n === 'number';
};
var isFloat = function (n) { return typeof n === 'number'; };
exports.isFloat = isFloat;

@@ -51,3 +72,3 @@ /**

var isInfinity = function (n) {
return typeof n === 'number' && !global.isNaN(n) && !global.isFinite(n);
return typeof n === 'number' && !isNaN(n) && !isFinite(n);
};

@@ -60,6 +81,4 @@ exports.isInfinity = isInfinity;

*/
var isNaN = function (n) {
return typeof n === 'number' && global.isNaN(n);
};
exports.isNaN = isNaN;
var _isNaN = function (n) { return typeof n === 'number' && isNaN(n); };
exports.isNaN = _isNaN;
/**

@@ -75,3 +94,5 @@ * Validates that a value is one of a set of values.

}
return function (s) { return ss.indexOf(s) >= MINIMUM_ARRAY_INDEX; };
return function (s) {
return ss.indexOf(s) >= MINIMUM_ARRAY_INDEX;
};
});

@@ -83,3 +104,7 @@ /**

*/
var isSingletonNumber = function (v) { return function (n) { return n === v; }; };
var isSingletonNumber = function (v) {
return function (n) {
return n === v;
};
};
exports.isSingletonNumber = isSingletonNumber;

@@ -105,5 +130,3 @@ /**

*/
var isString = function (s) {
return typeof s === 'string';
};
var isString = function (s) { return typeof s === 'string'; };
exports.isString = isString;

@@ -115,3 +138,7 @@ /**

*/
var isSingletonString = function (v) { return function (s) { return s === v; }; };
var isSingletonString = function (v) {
return function (s) {
return s === v;
};
};
exports.isSingletonString = isSingletonString;

@@ -137,5 +164,3 @@ /**

*/
var isBoolean = function (b) {
return typeof b === 'boolean';
};
var isBoolean = function (b) { return typeof b === 'boolean'; };
exports.isBoolean = isBoolean;

@@ -154,5 +179,3 @@ /**

*/
var isUndefined = function (u) {
return typeof u === 'undefined';
};
var isUndefined = function (u) { return typeof u === 'undefined'; };
exports.isUndefined = isUndefined;

@@ -164,3 +187,7 @@ /**

*/
var isOptional = function (tgt) { return function (o) { return typeof o === 'undefined' || tgt(o); }; };
var isOptional = function (tgt) {
return function (o) {
return typeof o === 'undefined' || tgt(o);
};
};
exports.isOptional = isOptional;

@@ -172,3 +199,7 @@ /**

*/
var isNullable = function (tgt) { return function (o) { return o === null || tgt(o); }; };
var isNullable = function (tgt) {
return function (o) {
return o === null || tgt(o);
};
};
exports.isNullable = isNullable;

@@ -180,5 +211,7 @@ /**

*/
var isMissing = function (tgt) { return function (o) {
return o == null || tgt(o);
}; };
var isMissing = function (tgt) {
return function (o) {
return o == null || tgt(o);
};
};
exports.isMissing = isMissing;

@@ -190,6 +223,7 @@ /**

*/
var isArray = function (valueCheck) { return function (arr) {
return Array.isArray(arr) &&
arr.reduce(function (acc, v) { return acc && valueCheck(v); }, true);
}; };
var isArray = function (valueCheck) {
return function (arr) {
return Array.isArray(arr) && arr.reduce(function (acc, v) { return acc && valueCheck(v); }, true);
};
};
exports.isArray = isArray;

@@ -201,3 +235,7 @@ /**

*/
var narrowValue = function (ptt, ptu) { return function (t) { return ptt(t) && ptu(t); }; };
var narrowValue = function (ptt, ptu) {
return function (t) {
return ptt(t) && ptu(t);
};
};
exports.narrowValue = narrowValue;

@@ -209,7 +247,20 @@ /**

*/
var narrowArray = function (pt) { return function (ts) {
return ts.reduce(function (acc, b) { return acc && pt(b); }, true);
}; };
var narrowArray = function (pt) {
return function (ts) {
return ts.reduce(function (acc, b) { return acc && pt(b); }, true);
};
};
exports.narrowArray = narrowArray;
/**
* Validate if an object is a Set containing elements of a given type.
*
* @public
*/
var isSetOf = function (tg) {
return function (o) {
return o instanceof Set && Array.of.apply(Array, __spreadArray([], __read(o.values()), false)).reduce(function (acc, v) { return acc && tg(v); }, true);
};
};
exports.isSetOf = isSetOf;
/**
* Validate if a value is like an object.

@@ -222,5 +273,3 @@ *

*/
var isObjectLike = function (obj) {
return obj != null && typeof obj === 'object';
};
var isObjectLike = function (obj) { return obj != null && typeof obj === 'object'; };
exports.isObjectLike = isObjectLike;

@@ -241,5 +290,3 @@ /**

*/
var isSet = function (obj) {
return obj != null;
};
var isSet = function (obj) { return obj != null; };
exports.isSet = isSet;

@@ -273,5 +320,5 @@ /**

var isNever = function (n) {
throw Error("Unexpected value when expecting never: " + n);
throw Error("Unexpected value when expecting never: ".concat(n));
};
exports.isNever = isNever;
//# sourceMappingURL=primitives.js.map

@@ -17,2 +17,13 @@ "use strict";

})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
exports.__esModule = true;

@@ -47,3 +58,3 @@ exports.combine = exports.assert = exports.AssertionError = void 0;

if (!guard(value)) {
throw new AssertionError(value, message !== null && message !== void 0 ? message : "Invalid value provided: " + JSON.stringify(value));
throw new AssertionError(value, message !== null && message !== void 0 ? message : "Invalid value provided: ".concat(JSON.stringify(value)));
}

@@ -55,3 +66,3 @@ };

*
* @param guards A list of partial typeguards to string together.
* @param guards - A list of partial typeguards to string together.
*

@@ -66,8 +77,18 @@ * @public

return function (v) {
for (var _i = 0, guards_1 = guards; _i < guards_1.length; _i++) {
var guard = guards_1[_i];
if (!guard(v)) {
return false;
var e_1, _a;
try {
for (var guards_1 = __values(guards), guards_1_1 = guards_1.next(); !guards_1_1.done; guards_1_1 = guards_1.next()) {
var guard = guards_1_1.value;
if (!guard(v)) {
return false;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (guards_1_1 && !guards_1_1.done && (_a = guards_1["return"])) _a.call(guards_1);
}
finally { if (e_1) throw e_1.error; }
}
return true;

@@ -74,0 +95,0 @@ };

{
"name": "generic-type-guard",
"version": "3.4.1",
"version": "3.4.2",
"description": "Generic type guards for TypeScript",
"main": "dist/index.js",
"types": "dist/generic-type-guard.d.ts",
"engines": {
"npm": ">= 7"
},
"scripts": {

@@ -70,23 +73,23 @@ "build": "rimraf dist && tsc --target es3 && api-extractor run --local --verbose",

"devDependencies": {
"@microsoft/api-extractor": "7.13.2",
"@mscharley/eslint-config": "1.3.2",
"@mscharley/prettier-config": "1.1.1",
"@stryker-mutator/core": "4.5.0",
"@stryker-mutator/mocha-runner": "4.5.0",
"@stryker-mutator/typescript-checker": "4.5.0",
"@types/chai": "4.2.15",
"@types/mocha": "8.2.1",
"@types/node": "12.20.4",
"chai": "4.3.3",
"codecov": "3.8.1",
"mocha": "8.3.1",
"nodemon": "2.0.7",
"@microsoft/api-extractor": "7.19.4",
"@mscharley/eslint-config": "1.7.1",
"@mscharley/prettier-config": "1.2.1",
"@stryker-mutator/core": "5.6.1",
"@stryker-mutator/mocha-runner": "5.6.1",
"@stryker-mutator/typescript-checker": "5.6.1",
"@types/chai": "4.3.0",
"@types/mocha": "9.1.0",
"@types/node": "16.11.24",
"chai": "4.3.6",
"codecov": "3.8.3",
"mocha": "9.2.0",
"nodemon": "2.0.15",
"nyc": "15.1.0",
"prettier": "2.2.1",
"prettier": "2.5.1",
"rimraf": "3.0.2",
"source-map-support": "0.5.19",
"testdouble": "3.16.1",
"ts-node": "9.1.1",
"typescript": "4.2.3"
"source-map-support": "0.5.21",
"testdouble": "3.16.4",
"ts-node": "10.5.0",
"typescript": "4.5.5"
}
}

@@ -0,0 +0,0 @@ # generic-type-guard

@@ -12,3 +12,3 @@ {

"packageNames": ["@types/node"],
"allowedVersions": "^12.0.0",
"allowedVersions": "^16.0.0",
"major": { "enabled": true }

@@ -15,0 +15,0 @@ }

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

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

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

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

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

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

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