Skip to content

Commit

Permalink
feat: version 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
santi100a committed Aug 21, 2023
1 parent bb80ae6 commit bbf2661
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
## Version 2.0.1

- Added `assertMatch` and `assertDefined`.

## Version 2.0.2

- Fixed circular dependency bug with `assertTypeOf` and `assertOneOf`.
5 changes: 2 additions & 3 deletions cjs/one-of.js
Original file line number Diff line number Diff line change
@@ -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; }; }
Expand All @@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/one-of.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assertTypeOf = require('./type-of');

/**
* Asserts `arg` is one of `choices`. Throws a `TypeError` otherwise.
*
Expand Down Expand Up @@ -54,12 +52,14 @@ function assertOneOf<T = unknown>(
'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;
Expand Down

0 comments on commit bbf2661

Please sign in to comment.