generic-type-guard
Advanced tools
Comparing version 3.5.0 to 3.6.0
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"workbench.colorCustomizations": { | ||
"activityBar.activeBackground": "#6472e7", | ||
"activityBar.activeBorder": "#f2acb4", | ||
"activityBar.background": "#6472e7", | ||
"activityBar.foreground": "#e7e7e7", | ||
"activityBar.inactiveForeground": "#e7e7e799", | ||
"activityBarBadge.background": "#f2acb4", | ||
"activityBarBadge.foreground": "#15202b", | ||
"titleBar.activeBackground": "#384ae0", | ||
"titleBar.activeForeground": "#e7e7e7", | ||
"titleBar.inactiveBackground": "#384ae099", | ||
"titleBar.inactiveForeground": "#e7e7e799" | ||
"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": "#384ae0" | ||
"peacock.color": "#9bce3e" | ||
} |
@@ -113,3 +113,3 @@ /** | ||
*/ | ||
"enabled": false | ||
"enabled": true | ||
@@ -116,0 +116,0 @@ /** |
@@ -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; |
@@ -239,3 +239,3 @@ /** | ||
/** | ||
* Validate that an object has exactly the fields provided | ||
* Validate that an object has exactly the fields provided. | ||
* | ||
@@ -303,2 +303,9 @@ * @public | ||
/** | ||
* Validate that an object has the fields provided. | ||
* | ||
* @public | ||
*/ | ||
export declare const isLikeObject: <V extends object>(props: MappedTypeGuard<V>) => TypeGuard<V>; | ||
/** | ||
* Validates if a value is a given type or null or undefined. | ||
@@ -305,0 +312,0 @@ * |
"use strict"; | ||
exports.__esModule = true; | ||
exports.isExactObject = exports.hasOptionalProperties = exports.hasOnlyProperties = exports.hasProperties = exports.isInstance = exports.hasNumericIndexSignature = exports.hasStringIndexSignature = exports.isRecord = exports.hasOptionalProperty = exports.hasProperty = void 0; | ||
exports.isExactObject = exports.isLikeObject = exports.hasOptionalProperties = exports.hasOnlyProperties = exports.hasProperties = exports.isInstance = exports.hasNumericIndexSignature = exports.hasStringIndexSignature = exports.isRecord = exports.hasOptionalProperty = exports.hasProperty = void 0; | ||
var utils_1 = require("./utils"); | ||
@@ -40,3 +40,3 @@ var primitives_1 = require("./primitives"); | ||
return function (o) { | ||
return primitives_1.isObject(o) && exports.hasProperty(property, value)(o); | ||
return (0, primitives_1.isObject)(o) && (0, exports.hasProperty)(property, value)(o); | ||
}; | ||
@@ -120,3 +120,3 @@ }; | ||
for (var prop in props) { | ||
if (!exports.hasProperty(prop, props[prop])(o)) { | ||
if (!(0, exports.hasProperty)(prop, props[prop])(o)) { | ||
return false; | ||
@@ -142,3 +142,3 @@ } | ||
var propsKey = prop; | ||
if (!exports.hasProperty(propsKey, props[propsKey])(o)) { | ||
if (!(0, exports.hasProperty)(propsKey, props[propsKey])(o)) { | ||
return false; | ||
@@ -167,3 +167,3 @@ } | ||
for (var prop in props) { | ||
if (!exports.hasOptionalProperty(prop, props[prop])(o)) { | ||
if (!(0, exports.hasOptionalProperty)(prop, props[prop])(o)) { | ||
return false; | ||
@@ -177,8 +177,19 @@ } | ||
/** | ||
* Validate that an object has exactly the fields provided | ||
* Validate that an object has the fields provided. | ||
* | ||
* @public | ||
*/ | ||
var isExactObject = function (props) { return utils_1.combine(primitives_1.isObject, exports.hasProperties(props)); }; | ||
var isLikeObject = function (props) { | ||
return (0, utils_1.combine)(primitives_1.isObject, (0, exports.hasProperties)(props)); | ||
}; | ||
exports.isLikeObject = isLikeObject; | ||
/** | ||
* Validate that an object has exactly the fields provided. | ||
* | ||
* @public | ||
*/ | ||
var isExactObject = function (props) { | ||
return (0, utils_1.combine)(primitives_1.isObject, (0, exports.hasOnlyProperties)(props)); | ||
}; | ||
exports.isExactObject = isExactObject; | ||
//# sourceMappingURL=objects.js.map |
@@ -18,6 +18,10 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
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)); | ||
}; | ||
@@ -32,5 +36,3 @@ exports.__esModule = true; | ||
*/ | ||
var isNumber = function (n) { | ||
return typeof n === 'number' && !global.isNaN(n); | ||
}; | ||
var isNumber = function (n) { return typeof n === 'number' && !isNaN(n); }; | ||
exports.isNumber = isNumber; | ||
@@ -43,3 +45,3 @@ /** | ||
var isFiniteNumber = function (n) { | ||
return typeof n === 'number' && !global.isNaN(n) && global.isFinite(n); | ||
return typeof n === 'number' && !isNaN(n) && isFinite(n); | ||
}; | ||
@@ -55,5 +57,3 @@ exports.isFiniteNumber = isFiniteNumber; | ||
*/ | ||
var isFloat = function (n) { | ||
return typeof n === 'number'; | ||
}; | ||
var isFloat = function (n) { return typeof n === 'number'; }; | ||
exports.isFloat = isFloat; | ||
@@ -73,3 +73,3 @@ /** | ||
var isInfinity = function (n) { | ||
return typeof n === 'number' && !global.isNaN(n) && !global.isFinite(n); | ||
return typeof n === 'number' && !isNaN(n) && !isFinite(n); | ||
}; | ||
@@ -82,6 +82,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; | ||
/** | ||
@@ -131,5 +129,3 @@ * Validates that a value is one of a set of values. | ||
*/ | ||
var isString = function (s) { | ||
return typeof s === 'string'; | ||
}; | ||
var isString = function (s) { return typeof s === 'string'; }; | ||
exports.isString = isString; | ||
@@ -166,5 +162,3 @@ /** | ||
*/ | ||
var isBoolean = function (b) { | ||
return typeof b === 'boolean'; | ||
}; | ||
var isBoolean = function (b) { return typeof b === 'boolean'; }; | ||
exports.isBoolean = isBoolean; | ||
@@ -183,5 +177,3 @@ /** | ||
*/ | ||
var isUndefined = function (u) { | ||
return typeof u === 'undefined'; | ||
}; | ||
var isUndefined = function (u) { return typeof u === 'undefined'; }; | ||
exports.isUndefined = isUndefined; | ||
@@ -228,4 +220,3 @@ /** | ||
return function (arr) { | ||
return Array.isArray(arr) && | ||
arr.reduce(function (acc, v) { return acc && valueCheck(v); }, true); | ||
return Array.isArray(arr) && arr.reduce(function (acc, v) { return acc && valueCheck(v); }, true); | ||
}; | ||
@@ -263,4 +254,3 @@ }; | ||
return function (o) { | ||
return o instanceof Set && | ||
Array.of.apply(Array, __spreadArray([], __read(o.values()))).reduce(function (acc, v) { return acc && tg(v); }, true); | ||
return o instanceof Set && Array.of.apply(Array, __spreadArray([], __read(o.values()), false)).reduce(function (acc, v) { return acc && tg(v); }, true); | ||
}; | ||
@@ -277,5 +267,3 @@ }; | ||
*/ | ||
var isObjectLike = function (obj) { | ||
return obj != null && typeof obj === 'object'; | ||
}; | ||
var isObjectLike = function (obj) { return obj != null && typeof obj === 'object'; }; | ||
exports.isObjectLike = isObjectLike; | ||
@@ -296,5 +284,3 @@ /** | ||
*/ | ||
var isSet = function (obj) { | ||
return obj != null; | ||
}; | ||
var isSet = function (obj) { return obj != null; }; | ||
exports.isSet = isSet; | ||
@@ -328,5 +314,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 |
@@ -57,3 +57,3 @@ "use strict"; | ||
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))); | ||
} | ||
@@ -60,0 +60,0 @@ }; |
{ | ||
"name": "generic-type-guard", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Generic type guards for TypeScript", | ||
"main": "dist/index.js", | ||
"types": "dist/generic-type-guard.d.ts", | ||
"engines": { | ||
"npm": ">= 7" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && tsc --target es3 && api-extractor run --local --verbose", | ||
"prepack": "rimraf dist && tsc --target es3 && api-extractor run --local", | ||
"test": "npm run lint && npm run mocha", | ||
"test": "npm run lint && npm run mocha && git diff --name-only --exit-code", | ||
"test-watch": "nodemon -e ts,json --exec npm run test", | ||
@@ -70,30 +73,23 @@ "lint": "eslint . --ext .js,.jsx,.ts,.tsx", | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "7.18.9", | ||
"@mscharley/eslint-config": "1.6.3", | ||
"@mscharley/prettier-config": "1.1.2", | ||
"@stryker-mutator/core": "5.4.0", | ||
"@stryker-mutator/mocha-runner": "5.4.0", | ||
"@stryker-mutator/typescript-checker": "5.4.0", | ||
"@types/chai": "4.2.21", | ||
"@types/mocha": "9.0.0", | ||
"@types/node": "12.20.25", | ||
"@typescript-eslint/eslint-plugin": "4.31.1", | ||
"@typescript-eslint/parser": "4.31.1", | ||
"chai": "4.3.4", | ||
"@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.25", | ||
"chai": "4.3.6", | ||
"codecov": "3.8.3", | ||
"eslint": "7.32.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-deprecation": "1.2.1", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"mocha": "9.1.1", | ||
"nodemon": "2.0.12", | ||
"mocha": "9.2.1", | ||
"nodemon": "2.0.15", | ||
"nyc": "15.1.0", | ||
"prettier": "2.4.1", | ||
"prettier": "2.5.1", | ||
"rimraf": "3.0.2", | ||
"source-map-support": "0.5.20", | ||
"testdouble": "3.16.2", | ||
"ts-node": "10.2.1", | ||
"typescript": "4.3.5" | ||
"source-map-support": "0.5.21", | ||
"testdouble": "3.16.4", | ||
"ts-node": "10.5.0", | ||
"typescript": "4.5.5" | ||
} | ||
} |
@@ -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
137230
20
48
1731