diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c224af..e982eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,3 +23,7 @@ ## Version 2.0.1 - Added `assertMatch` and `assertDefined`. + +## Version 2.0.2 + +- Fixed circular dependency bug with `assertTypeOf` and `assertOneOf`. diff --git a/cjs/one-of.js b/cjs/one-of.js index fa8f5a9..cd47229 100644 --- a/cjs/one-of.js +++ b/cjs/one-of.js @@ -1,5 +1,4 @@ "use strict"; -var assertTypeOf = require("./type-of"); /** Implementation */ function assertOneOf(arg, name, choices, comparator) { if (comparator === void 0) { comparator = function (a, b) { return a === b; }; } @@ -13,9 +12,9 @@ function assertOneOf(arg, name, choices, comparator) { if (typeof comparator === 'boolean') throw new TypeError('The `shallow` argument is no longer valid. Please pass a function instead.'); else if (typeof comparator !== 'function') - assertTypeOf(comparator, 'function', 'comparator'); + throw new TypeError("\"comparator\" must be of type \"function\". Got ".concat(comparator, " of type \"").concat(typeof comparator, "\".")); if (__indexOf(choices, arg) === -1) - throw new TypeError("\"".concat(name, "\" must be one of \"").concat(choices.join(', '), "\". Got \"").concat(arg, "\" of type \"").concat(typeof arg, "\".")); + throw new TypeError("\"".concat(name, "\" must be one of ").concat(choices.join(', '), ". Got \"").concat(arg, "\" of type \"").concat(typeof arg, "\".")); } assertOneOf.assertOneOf = assertOneOf; module.exports = assertOneOf; diff --git a/package.json b/package.json index f9b02f9..6584b0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@santi100/assertion-lib", - "version": "2.0.1", + "version": "2.0.2", "main": "cjs/index.js", "typings": "cjs/index.d.ts", "module": "./index.mjs", diff --git a/src/one-of.ts b/src/one-of.ts index ca9272d..5aa0c80 100644 --- a/src/one-of.ts +++ b/src/one-of.ts @@ -1,5 +1,3 @@ -import assertTypeOf = require('./type-of'); - /** * Asserts `arg` is one of `choices`. Throws a `TypeError` otherwise. * @@ -54,12 +52,14 @@ function assertOneOf( 'The `shallow` argument is no longer valid. Please pass a function instead.' ); else if (typeof comparator !== 'function') - assertTypeOf(comparator, 'function', 'comparator'); + throw new TypeError(`"comparator" must be of type "function". Got ${ + comparator + } of type "${typeof comparator}".`); if (__indexOf(choices, arg as T) === -1) throw new TypeError( - `"${name}" must be one of "${choices.join( + `"${name}" must be one of ${choices.join( ', ' - )}". Got "${arg}" of type "${typeof arg}".` + )}. Got "${arg}" of type "${typeof arg}".` ); } assertOneOf.assertOneOf = assertOneOf;