Comparing version 4.3.0 to 4.4.0
/* eslint-disable prettier/prettier */ | ||
const isCircular = require("./checkers/isCircular"); | ||
const isJSONable = require("./checkers/isJSONable"); | ||
@@ -13,3 +14,6 @@ // Checkers. | ||
function isFalsy(v) { return !v; } | ||
function isNumber(v) { return typeof v === "number" && Number.isFinite(v); } | ||
function isZero(v) { return v === 0; } | ||
function isOne(v) { return v === 1; } | ||
function isNaN(v) { return Number.isNaN(v); } | ||
function isFiniteNumber(v) { return typeof v === "number" && Number.isFinite(v); } | ||
function isPositiveNumber(v) { return typeof v === "number" && Number.isFinite(v) && v >= 0; } | ||
@@ -56,3 +60,6 @@ function isNegativeNumber(v) { return typeof v === "number" && Number.isFinite(v) && v <= 0; } | ||
isFalsy.desc = "falsy" | ||
isNumber.desc = "finite number" | ||
isZero.desc = "zero" | ||
isOne.desc = "one" | ||
isNaN.desc = "NaN" | ||
isFiniteNumber.desc = "finite number" | ||
isPositiveNumber.desc = "positive finite number" | ||
@@ -100,3 +107,6 @@ isNegativeNumber.desc = "negative finite number" | ||
"falsy": isFalsy, | ||
"number": isNumber, "num": isNumber, | ||
"zero": isZero, | ||
"one": isOne, | ||
"nan": isNaN, | ||
"number": isFiniteNumber, "num": isFiniteNumber, | ||
"number+": isPositiveNumber, "num+": isPositiveNumber, | ||
@@ -122,4 +132,3 @@ "number-": isNegativeNumber, "num-": isNegativeNumber, | ||
"date": isDate, | ||
"date+": isFutureDate, | ||
"future": isFutureDate, | ||
"date+": isFutureDate, "future": isFutureDate, | ||
"date-": isPastDate, "past": isPastDate, | ||
@@ -136,2 +145,3 @@ "map": isMap, | ||
"circular": isCircular, | ||
"json": isJSONable, | ||
}; | ||
@@ -138,0 +148,0 @@ |
@@ -40,3 +40,6 @@ /** | ||
// Description. | ||
isCircular.desc = "containing circular references"; | ||
// Exports. | ||
module.exports = isCircular; |
{ | ||
"name": "blork", | ||
"description": "Blork! Mini runtime type checking in Javascript", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"license": "0BSD", | ||
@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>", |
@@ -265,46 +265,50 @@ # Blork! Mini runtime type checking in Javascript | ||
| Type string reference | Description | ||
|---------------------------------|------------------- | ||
| `null` | Value is **null** | ||
| `undefined`, `undef`, `void` | Value is **undefined** | ||
| `defined`, `def` | Value is **not undefined** | ||
| `boolean`, `bool` | Value is **true** or **false** | ||
| `true` | Value is **true** | ||
| `false` | Value is **false** | ||
| `truthy` | Any truthy values (i.e. **== true**) | ||
| `falsy` | Any falsy values (i.e. **== false**) | ||
| `number`, `num` | Numbers excluding NaN/Infinity (using **typeof** and finite check) | ||
| `number+`, `num+` | Numbers more than or equal to zero | ||
| `number-`, `num-` | Numbers less than or equal to zero | ||
| `integer`, `int` | Integers (using **Number.isInteger()**) | ||
| `integer+`, `int+` | Positive integers including zero | ||
| `integer-`, `int-` | Negative integers including zero | ||
| `string`, `str` | Strings (using **typeof**) | ||
| `string+`, `str+` | Non-empty strings (using **str.length**) | ||
| `lowercase`, `lower` | Strings with no uppercase characters | ||
| `lowercase+`, `lower+` | Non-empty strings with no uppercase characters | ||
| `uppercase`, `upper` | Strings with no lowercase characters | ||
| `uppercase+`, `upper+` | Non-empty strings with no lowercase characters | ||
| `function`, `func` | Functions (using **instanceof Function**) | ||
| `object`, `obj` | Plain objects (using **instanceof Object** and constructor check) | ||
| `object+`, `obj+` | Plain objects with one or more properties (using **Object.keys().length**) | ||
| `objectlike` | Any object-like object (using **instanceof Object**) | ||
| `iterable` | Objects with a **Symbol.iterator** method (that can be used with **for..of** loops) | ||
| `circular` | Objects with one or more _circular references_ | ||
| `array`, `arr` | Plain instances of Array (using **instanceof Array** and constructor check) | ||
| `array+`, `arr+` | Plain instances of **Array** with one or more items | ||
| `arraylike` | Any object, not just arrays, with numeric **.length** property | ||
| `arguments`, `args` | Arguments objects (any object, not just arrays, with numeric **.length** property) | ||
| `map` | Instances of **Map** | ||
| `map+` | Instances of **Map** with one or more items | ||
| `weakmap` | Instances of **WeakMap** | ||
| `set` | Instances of **Set** | ||
| `set+` | Instances of **Set** with one or more items | ||
| `weakset` | Instances of **WeakSet** | ||
| `promise` | Instances of **Promise** | ||
| `date` | Instances of **Date** | ||
| `date+`, `future` | Instances of **Date** with a value in the future | ||
| `date-`, `past` | Instances of **Date** with a value in the past | ||
| `regex`, `regexp` | Instances of **RegExp** (regular expressions) | ||
| `any`, `mixed` | Allow any value (transparently passes through with no error) | ||
| Type string reference | Description | ||
|--------------------------------------|------------------- | ||
| `null` | Value is **null** | ||
| `undefined`, `undef`, `void` | Value is **undefined** | ||
| `defined`, `def` | Value is **not undefined** | ||
| `boolean`, `bool` | Value is **true** or **false** | ||
| `true` | Value is **true** | ||
| `false` | Value is **false** | ||
| `truthy` | Any truthy values (i.e. **== true**) | ||
| `falsy` | Any falsy values (i.e. **== false**) | ||
| `zero` | Value is **0** | ||
| `one` | Value is **1** | ||
| `nan` | Value is **NaN** | ||
| `number`, `num` | Numbers excluding NaN/Infinity (using **typeof** and finite check) | ||
| `number+`, `num+`, | Numbers more than or equal to zero | ||
| `number-`, `num-` | Numbers less than or equal to zero | ||
| `integer`, `int` | Integers (using **Number.isInteger()**) | ||
| `integer+`, `int+` | Positive integers including zero | ||
| `integer-`, `int-` | Negative integers including zero | ||
| `string`, `str` | Strings (using **typeof**) | ||
| `string+`, `str+` | Non-empty strings (using **str.length**) | ||
| `lowercase`, `lower` | Strings with no uppercase characters | ||
| `lowercase+`, `lower+` | Non-empty strings with no uppercase characters | ||
| `uppercase`, `upper` | Strings with no lowercase characters | ||
| `uppercase+`, `upper+` | Non-empty strings with no lowercase characters | ||
| `function`, `func` | Functions (using **instanceof Function**) | ||
| `object`, `obj` | Plain objects (using **instanceof Object** and constructor check) | ||
| `object+`, `obj+` | Plain objects with one or more properties (using **Object.keys().length**) | ||
| `objectlike` | Any object-like object (using **instanceof Object**) | ||
| `iterable` | Objects with a **Symbol.iterator** method (that can be used with **for..of** loops) | ||
| `circular` | Objects with one or more _circular references_ (use `!circular` to disallow circular references) | ||
| `array`, `arr` | Plain instances of Array (using **instanceof Array** and constructor check) | ||
| `array+`, `arr+` | Plain instances of **Array** with one or more items | ||
| `arraylike` | Any object, not just arrays, with numeric **.length** property | ||
| `arguments`, `args` | Arguments objects (any object, not just arrays, with numeric **.length** property) | ||
| `map` | Instances of **Map** | ||
| `map+` | Instances of **Map** with one or more items | ||
| `weakmap` | Instances of **WeakMap** | ||
| `set` | Instances of **Set** | ||
| `set+` | Instances of **Set** with one or more items | ||
| `weakset` | Instances of **WeakSet** | ||
| `promise` | Instances of **Promise** | ||
| `date` | Instances of **Date** | ||
| `date+`, `future` | Instances of **Date** with a value in the future | ||
| `date-`, `past` | Instances of **Date** with a value in the past | ||
| `regex`, `regexp` | Instances of **RegExp** (regular expressions) | ||
| `any`, `mixed` | Allow any value (transparently passes through with no error) | ||
| `json`, `jsonable` | **JSON-friendly** values (null, true, false, finite numbers, strings, plain objects, plain arrays) | ||
@@ -515,2 +519,4 @@ ```js | ||
- 4.4.0 | ||
- Add `json` checker to check for JSON-friendly values (null, true, false, finite numbers, strings, plain objects, plain arrays) | ||
- 4.3.0 | ||
@@ -517,0 +523,0 @@ - Add `circular` checker to check for objects with circular references |
@@ -28,2 +28,5 @@ const checkers = require("../lib/checkers"); | ||
// Numbers. | ||
expect(check(0, "zero")).toBe(undefined); | ||
expect(check(1, "one")).toBe(undefined); | ||
expect(check(NaN, "nan")).toBe(undefined); | ||
expect(check(1.5, "number")).toBe(undefined); | ||
@@ -97,4 +100,5 @@ expect(check(1.5, "num")).toBe(undefined); | ||
// Circular. | ||
// Advanced. | ||
expect(check(circular, "circular")).toBe(undefined); | ||
expect(check({ num: 123, str: "abc" }, "json")).toBe(undefined); | ||
}); | ||
@@ -119,2 +123,5 @@ test("Every named type fails correctly", () => { | ||
// Numbers. | ||
expect(() => check(1, "zero")).toThrow(TypeError); | ||
expect(() => check(0, "one")).toThrow(TypeError); | ||
expect(() => check(1, "nan")).toThrow(TypeError); | ||
expect(() => check("1", "number")).toThrow(TypeError); | ||
@@ -188,5 +195,6 @@ expect(() => check("1", "num")).toThrow(TypeError); | ||
// Circular. | ||
// Advanced. | ||
expect(() => check([], "circular")).toThrow(TypeError); | ||
expect(() => check(undefined, "json")).toThrow(TypeError); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
109574
36
1854
540
0