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

@6river/reason-guard

Package Overview
Dependencies
Maintainers
5
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@6river/reason-guard - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

dist/src/constantGuards.js

10

dist/test/arrayHasType.spec.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const util_1 = require("./util");
const assertGuards_1 = require("./assertGuards");
const arrayHasType_1 = require("../src/arrayHasType");

@@ -9,14 +9,14 @@ const primitiveGuards_1 = require("../src/primitiveGuards");

it('guards for correct type', function () {
util_1.assertGuardConfirmed(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), [1, 2]);
assertGuards_1.assertGuards(true)(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), [1, 2]);
});
it('guards against wrong type', function () {
util_1.assertGuardFailed(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), ['string', 'string']);
assertGuards_1.assertGuards(false)(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), ['string', 'string']);
});
it('accepts empty array', function () {
util_1.assertGuardConfirmed(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), []);
assertGuards_1.assertGuards(true)(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), []);
});
it('guards against mixed type', function () {
util_1.assertGuardFailed(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), [1, undefined, 3]);
assertGuards_1.assertGuards(false)(arrayHasType_1.arrayHasType(primitiveGuards_1.isNumber), [1, undefined, 3]);
});
});
//# sourceMappingURL=arrayHasType.spec.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const util_1 = require("./util");
const assertGuards_1 = require("./assertGuards");
const combinators_1 = require("../src/combinators");
const constantGuards_1 = require("../src/constantGuards");
const abbrev = (b) => b ? 'T' : 'F';
describe('combinators', function () {
context('or', function () {
it('F|F=F', function () {
util_1.assertGuardFailed(combinators_1.orGuard(util_1.falseGuard, util_1.falseGuard), undefined);
});
it('F|T=T', function () {
util_1.assertGuardConfirmed(combinators_1.orGuard(util_1.falseGuard, util_1.trueGuard), undefined);
});
it('T|F=T', function () {
util_1.assertGuardConfirmed(combinators_1.orGuard(util_1.trueGuard, util_1.falseGuard), undefined);
});
it('T|T=T', function () {
util_1.assertGuardConfirmed(combinators_1.orGuard(util_1.trueGuard, util_1.trueGuard), undefined);
});
testCombinator2('|', [false, true, true, true], combinators_1.orGuard);
});
context('and', function () {
it('F&F=F', function () {
util_1.assertGuardFailed(combinators_1.andGuard(util_1.falseGuard, util_1.falseGuard), undefined);
});
it('F&T=F', function () {
util_1.assertGuardFailed(combinators_1.andGuard(util_1.falseGuard, util_1.trueGuard), undefined);
});
it('T&F=F', function () {
util_1.assertGuardFailed(combinators_1.andGuard(util_1.trueGuard, util_1.falseGuard), undefined);
});
it('T&T=T', function () {
util_1.assertGuardConfirmed(combinators_1.andGuard(util_1.trueGuard, util_1.trueGuard), undefined);
});
testCombinator2('&', [false, false, false, true], combinators_1.andGuard);
});
context('then', function () {
testCombinator2(',', [false, false, false, true], combinators_1.thenGuard);
});
context('not', function () {
it('!F=T', function () {
util_1.assertGuardConfirmed(combinators_1.notGuard(util_1.falseGuard), undefined);
});
it('!T=F', function () {
util_1.assertGuardFailed(combinators_1.notGuard(util_1.trueGuard), undefined);
});
testCombinator1('!', [true, false], combinators_1.notGuard);
});
context('then', function () {
it('F,F=F', function () {
util_1.assertGuardFailed(combinators_1.thenGuard(util_1.falseGuard, util_1.falseGuard), undefined);
});
it('F,T=F', function () {
util_1.assertGuardFailed(combinators_1.thenGuard(util_1.falseGuard, util_1.trueGuard), undefined);
});
it('T,F=F', function () {
util_1.assertGuardFailed(combinators_1.thenGuard(util_1.trueGuard, util_1.falseGuard), undefined);
});
it('T,T=T', function () {
util_1.assertGuardConfirmed(combinators_1.thenGuard(util_1.trueGuard, util_1.trueGuard), undefined);
});
context('not-or', function () {
const notOr = (left, right) => combinators_1.notGuard(combinators_1.orGuard(left, right));
testCombinator2('!|', [true, false, false, false], notOr);
});
context('not-and', function () {
const notAnd = (left, right) => combinators_1.notGuard(combinators_1.andGuard(left, right));
testCombinator2('!&', [true, true, true, false], notAnd);
});
});
function testCombinator1(char, result, combinator) {
const t = (success, inner) => assertGuards_1.assertGuards(success)(combinator(constantGuards_1.constantGuards(inner)), undefined);
it(char + 'F=' + abbrev(result[0]), function () {
t(result[0], false);
});
it(char + 'T=' + abbrev(result[1]), function () {
t(result[1], true);
});
}
function testCombinator2(char, result, combinator) {
const t = (success, left, right) => assertGuards_1.assertGuards(success)(combinator(constantGuards_1.constantGuards(left), constantGuards_1.constantGuards(right)), undefined);
it('F' + char + 'F=' + abbrev(result[0]), function () {
t(result[0], false, false);
});
it('F' + char + 'F=' + abbrev(result[1]), function () {
t(result[1], false, true);
});
it('F' + char + 'F=' + abbrev(result[2]), function () {
t(result[2], true, false);
});
it('F' + char + 'F=' + abbrev(result[3]), function () {
t(result[3], true, true);
});
}
//# sourceMappingURL=combinators.spec.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const util_1 = require("./util");
const assertGuards_1 = require("./assertGuards");
const instanceGuards_1 = require("../src/instanceGuards");

@@ -9,9 +9,9 @@ describe('instance guards', function () {

it('guards for arrays', function () {
util_1.assertGuardConfirmed(instanceGuards_1.isArray, []);
assertGuards_1.assertGuards(true)(instanceGuards_1.isArray, []);
});
it('guards against non-arrays', function () {
util_1.assertGuardFailed(instanceGuards_1.isArray, undefined);
util_1.assertGuardFailed(instanceGuards_1.isArray, null);
util_1.assertGuardFailed(instanceGuards_1.isArray, 3);
util_1.assertGuardFailed(instanceGuards_1.isArray, {});
assertGuards_1.assertGuards(false)(instanceGuards_1.isArray, undefined);
assertGuards_1.assertGuards(false)(instanceGuards_1.isArray, null);
assertGuards_1.assertGuards(false)(instanceGuards_1.isArray, 3);
assertGuards_1.assertGuards(false)(instanceGuards_1.isArray, {});
});

@@ -21,10 +21,10 @@ });

it('guards for dates', function () {
util_1.assertGuardConfirmed(instanceGuards_1.isDate, new Date());
assertGuards_1.assertGuards(true)(instanceGuards_1.isDate, new Date());
});
it('guards against non-dates', function () {
util_1.assertGuardFailed(instanceGuards_1.isDate, undefined);
util_1.assertGuardFailed(instanceGuards_1.isDate, null);
util_1.assertGuardFailed(instanceGuards_1.isDate, 3);
util_1.assertGuardFailed(instanceGuards_1.isDate, {});
util_1.assertGuardFailed(instanceGuards_1.isDate, new Date().toString());
assertGuards_1.assertGuards(false)(instanceGuards_1.isDate, undefined);
assertGuards_1.assertGuards(false)(instanceGuards_1.isDate, null);
assertGuards_1.assertGuards(false)(instanceGuards_1.isDate, 3);
assertGuards_1.assertGuards(false)(instanceGuards_1.isDate, {});
assertGuards_1.assertGuards(false)(instanceGuards_1.isDate, new Date().toString());
});

@@ -31,0 +31,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const util_1 = require("./util");
const assertGuards_1 = require("./assertGuards");
const primitive = require("../src/primitiveGuards");

@@ -9,11 +9,11 @@ describe('primitive guards', function () {

it('guards for numbers', function () {
util_1.assertGuardConfirmed(primitive.isNumber, 0);
util_1.assertGuardConfirmed(primitive.isNumber, 2.7);
util_1.assertGuardConfirmed(primitive.isNumber, -3);
assertGuards_1.assertGuards(true)(primitive.isNumber, 0);
assertGuards_1.assertGuards(true)(primitive.isNumber, 2.7);
assertGuards_1.assertGuards(true)(primitive.isNumber, -3);
});
it('guards against non-numbers', function () {
util_1.assertGuardFailed(primitive.isNumber, 'string');
util_1.assertGuardFailed(primitive.isNumber, undefined);
util_1.assertGuardFailed(primitive.isNumber, null);
util_1.assertGuardFailed(primitive.isNumber, {});
assertGuards_1.assertGuards(false)(primitive.isNumber, 'string');
assertGuards_1.assertGuards(false)(primitive.isNumber, undefined);
assertGuards_1.assertGuards(false)(primitive.isNumber, null);
assertGuards_1.assertGuards(false)(primitive.isNumber, {});
});

@@ -23,10 +23,10 @@ });

it('guards for strings', function () {
util_1.assertGuardConfirmed(primitive.isString, '');
util_1.assertGuardConfirmed(primitive.isString, 'string');
assertGuards_1.assertGuards(true)(primitive.isString, '');
assertGuards_1.assertGuards(true)(primitive.isString, 'string');
});
it('guards against non-strings', function () {
util_1.assertGuardFailed(primitive.isString, 7);
util_1.assertGuardFailed(primitive.isString, undefined);
util_1.assertGuardFailed(primitive.isString, null);
util_1.assertGuardFailed(primitive.isString, {});
assertGuards_1.assertGuards(false)(primitive.isString, 7);
assertGuards_1.assertGuards(false)(primitive.isString, undefined);
assertGuards_1.assertGuards(false)(primitive.isString, null);
assertGuards_1.assertGuards(false)(primitive.isString, {});
});

@@ -33,0 +33,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("mocha");
const util_1 = require("./util");
const assertGuards_1 = require("./assertGuards");
const property = require("../src/propertyGuards");

@@ -35,8 +35,8 @@ const values = [0, 'string', false, () => null, new Date(), null, undefined, []];

it('guards for correct properties', function () {
util_1.assertGuardConfirmed(guardMaker('prop'), { prop: values[correctIndex] });
assertGuards_1.assertGuards(true)(guardMaker('prop'), { prop: values[correctIndex] });
});
it('guards against missing properties', function () {
util_1.assertGuardFailed(guardMaker('prop'), {});
util_1.assertGuardFailed(guardMaker('prop'), 3);
util_1.assertGuardFailed(guardMaker('prop'), undefined);
assertGuards_1.assertGuards(false)(guardMaker('prop'), {});
assertGuards_1.assertGuards(false)(guardMaker('prop'), 3);
assertGuards_1.assertGuards(false)(guardMaker('prop'), undefined);
});

@@ -46,3 +46,3 @@ it('guards against wrong properties', function () {

if (i !== correctIndex) {
util_1.assertGuardFailed(guardMaker('prop'), { prop: values[i] });
assertGuards_1.assertGuards(false)(guardMaker('prop'), { prop: values[i] });
}

@@ -49,0 +49,0 @@ }

@@ -50,3 +50,3 @@ {

},
"version": "1.0.3"
"version": "1.0.4"
}

@@ -5,3 +5,3 @@ # reason-guard

# semantics
- A true typeguard will provide no errors and at least one confirmation of what was checked.
- A false typeguard will provide at least one error about what failed.
- A true reasonguard will provide no errors and at least one confirmation of what was checked.
- A false reasonguard will provide at least one error about what failed.

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