update, text, response

This commit is contained in:
2025-11-02 11:09:14 +01:00
parent 14776c86b0
commit eed8a4ddcf
2794 changed files with 156786 additions and 129204 deletions

16
node_modules/type/.editorconfig generated vendored
View File

@@ -1,16 +0,0 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
[*.md]
indent_size = 2
indent_style = space
trim_trailing_whitespace = false

90
node_modules/type/CHANGELOG.md generated vendored
View File

@@ -2,6 +2,96 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.7.3](https://github.com/medikoo/type/compare/v2.7.2...v2.7.3) (2024-05-30)
### Maintenance Improvements
- Add security vulnerability policy ([a28cc58](https://github.com/medikoo/type/commit/a28cc586882ee8b1f0af6789b5af927cc4f14227))
- Prettify ([aaa9256](https://github.com/medikoo/type/commit/aaa92561a812d756ece952e1afade7d4aa0f116c))
- Upgrade `prettier-elastic` to v3 ([7f10b2c](https://github.com/medikoo/type/commit/7f10b2c995bb590903b2d3d2c1eacfd7e045d73b))
### [2.7.2](https://github.com/medikoo/type/compare/v2.7.1...v2.7.2) (2022-08-05)
### Maintenance Improvements
- **TS:** Improve `ensure` options handling ([#8](https://github.com/medikoo/type/issues/8)) ([4a54066](https://github.com/medikoo/type/commit/4a54066d7b55cef14ac4aa25a6f070296a043a6f)) ([Marco](https://github.com/borracciaBlu))
### [2.7.1](https://github.com/medikoo/type/compare/v2.7.0...v2.7.1) (2022-08-04)
### Maintenance Improvements
- **TS:** Fix support for `isOptional` in `ensure` options ([#7](https://github.com/medikoo/type/issues/7)) ([320f89b](https://github.com/medikoo/type/commit/320f89b89237e3e0ceff5e26b67cb18bd52cb42d)) ([Marco](https://github.com/borracciaBlu))
## [2.7.0](https://github.com/medikoo/type/compare/v2.6.1...v2.7.0) (2022-08-03)
### Features
- `BigInt.coerce` and `BigInt.ensure` ([e49ad78](https://github.com/medikoo/type/commit/e49ad787bd3aa67b7aa9f7a8ea4cde22a08bebc5))
### [2.6.1](https://github.com/medikoo/type/compare/v2.6.0...v2.6.1) (2022-07-29)
### Maintenance Improvements
- Declare TS types ([#6](https://github.com/medikoo/type/issues/6)) ([6378e2c](https://github.com/medikoo/type/commit/6378e2c457670bcb8a9b898e0f2502ed5b942d44)) ([Marco](https://github.com/borracciaBlu))
## [2.6.0](https://github.com/medikoo/type/compare/v2.5.0...v2.6.0) (2022-02-02)
### Features
- `constructor` validation utils ([74b99bb](https://github.com/medikoo/type/commit/74b99bbf6be27083bf9a053961edb2a585ae3e77))
## [2.5.0](https://github.com/medikoo/type/compare/v2.4.0...v2.5.0) (2021-03-08)
### Features
- `errorCode` option for `ensure*` utils ([777a1f2](https://github.com/medikoo/type/commit/777a1f2c9fd76defcd24d3a30cce49491947fef7))
## [2.4.0](https://github.com/medikoo/type/compare/v2.3.0...v2.4.0) (2021-03-08)
### Features
- `set/is` and `set/ensure` utils ([083ec23](https://github.com/medikoo/type/commit/083ec2351718c310f316dcfd8c624a13201e227f))
## [2.3.0](https://github.com/medikoo/type/compare/v2.2.0...v2.3.0) (2021-02-16)
### Features
- `map/is` and `map/ensure` utils ([aafd1cb](https://github.com/medikoo/type/commit/aafd1cbd8c888fda98d39fd17e59f38b078d7bcf))
## [2.2.0](https://github.com/medikoo/type/compare/v2.1.0...v2.2.0) (2021-02-11)
### Features
- Support `ensureItem` option in `array/ensure` ([8f74973](https://github.com/medikoo/type/commit/8f749739df9bfebf44087093e09c8f7341a33a09))
## [2.1.0](https://github.com/medikoo/type/compare/v2.0.0...v2.1.0) (2020-08-21)
### Features
- `ensure` util for cumulated input validation ([814c5a8](https://github.com/medikoo/type/commit/814c5a801ecac23d06d8a5f4bcafc4763a04408c))
- Provide an alternative error message with `options.name` ([c7751c0](https://github.com/medikoo/type/commit/c7751c084ee4f3d3ed10500db0edde2ff00e03a1))
- Support `%n` (meaningful name) token in error message resolver ([b0f374e](https://github.com/medikoo/type/commit/b0f374e54345c714fe37a90887ecfe60577ce133))
- Support `min` validation for natural numbers ([e703512](https://github.com/medikoo/type/commit/e70351248818d3e113110106ad174b42c5fd9b25))
- Support custom Error constructors ([c6ecb90](https://github.com/medikoo/type/commit/c6ecb90e21c1c778210934204cbe393fb89ef2f6))
### Bug Fixes
- Fix typo in error message ([2735533](https://github.com/medikoo/type/commit/2735533de28d33dfa13222743698169c92d08c09))
## [2.0.0](https://github.com/medikoo/type/compare/v1.2.0...v2.0.0) (2019-10-10)
### Features
- `allowedKeys` option for plain-object/ensure ([f81e72e](https://github.com/medikoo/type/commit/f81e72e))
- `ensurePropertyValue` option for plain-object/ensure ([c5ff8fb](https://github.com/medikoo/type/commit/c5ff8fb))
- Replace `coerceItem` with `ensureItem` option in iterable/ensure ([721494f](https://github.com/medikoo/type/commit/721494f))
- Seclude lib/resolve-error-message ([12636d9](https://github.com/medikoo/type/commit/12636d9))
- Validate options.ensureItem in iterable/ensure ([78da6c1](https://github.com/medikoo/type/commit/78da6c1))
### BREAKING CHANGES
- iterable/ensure no longer supports `coerceItem` option. Instead `ensureItem` was introduced
## [1.2.0](https://github.com/medikoo/type/compare/v1.1.0...v1.2.0) (2019-09-20)
### Bug Fixes

2
node_modules/type/LICENSE generated vendored
View File

@@ -1,6 +1,6 @@
ISC License
Copyright (c) 2019, Mariusz Nowak, @medikoo, medikoo.com
Copyright (c) 2019-2024, Mariusz Nowak, @medikoo, medikoo.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above

801
node_modules/type/README.md generated vendored
View File

@@ -1,5 +1,4 @@
[![*nix build status][nix-build-image]][nix-build-url]
[![Windows build status][win-build-image]][win-build-url]
[![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]
@@ -11,6 +10,12 @@
- Allows coercion in restricted forms (rejects clearly invalid input, normalizes permissible type deviations)
- No transpilation implied, written to work in all ECMAScript 3+ engines
## Use case
Validate arguments input in public API endpoints.
_For validation of more sophisticated input structures (as deeply nested configuration objects) it's recommended to consider more powerful schema based utlities (as [AJV](https://ajv.js.org/) or [@hapi/joi](https://hapi.dev/family/joi/))_
### Example usage
Bulletproof input arguments normalization and validation:
@@ -40,7 +45,7 @@ npm install type
## Utilities
Serves following kind of utilities:
Aside of general [`ensure`](docs/ensure.md) validation util, following kind of utilities for recognized JavaScript types are provided:
##### `*/coerce`
@@ -58,704 +63,110 @@ Each `*/ensure` utility, accepts following options (eventually passed with secon
- `isOptional` - Makes `null` or `undefined` accepted as valid value. In such case instead of `TypeError` being thrown, `null` is returned.
- `default` - A value to be returned if `null` or `undefined` is passed as an input value.
- `errorMessage` - Custom error message (`%v` can be used as a placeholder for input value)
---
### Value
_Value_, any value that's neither `null` nor `undefined` .
#### `value/is`
Confirms whether passed argument is a _value_
```javascript
const isValue = require("type/value/is");
isValue({}); // true
isValue(null); // false
```
#### `value/ensure`
Ensures if given argument is a _value_. If it's a value it is returned back, if not `TypeError` is thrown
```javascript
const ensureValue = require("type/value/ensure");
const obj = {};
ensureValue(obj); // obj
ensureValue(null); // Thrown TypeError: Cannot use null
```
---
### Object
_Object_, any non-primitive value
#### `object/is`
Confirms if passed value is an object
```javascript
const isObject = require("type/object/is");
isObject({}); // true
isObject(true); // false
isObject(null); // false
```
#### `object/ensure`
If given argument is an object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureObject = require("type/object/ensure");
const obj = {};
ensureObject(obj); // obj
ensureString(null); // Thrown TypeError: null is not an object
```
---
### String
_string_ primitive
#### `string/coerce`
Restricted string coercion. Returns string presentation for every value that follows below constraints
- is implicitly coercible to string
- is neither`null` nor `undefined`
- its `toString` method is not `Object.prototype.toString`
For all other values `null` is returned
```javascript
const coerceToString = require("type/string/coerce");
coerceToString(12); // "12"
coerceToString(undefined); // null
```
#### `string/ensure`
If given argument is a string coercible value (via [`string/coerce`](#stringcoerce)) returns result string.
Otherwise `TypeError` is thrown.
```javascript
const ensureString = require("type/string/ensure");
ensureString(12); // "12"
ensureString(null); // Thrown TypeError: null is not a string
```
---
### Number
_number_ primitive
#### `number/coerce`
Restricted number coercion. Returns number presentation for every value that follows below constraints
- is implicitly coercible to number
- is neither `null` nor `undefined`
- is not `NaN` and doesn't coerce to `NaN`
For all other values `null` is returned
```javascript
const coerceToNumber = require("type/number/coerce");
coerceToNumber("12"); // 12
coerceToNumber({}); // null
coerceToNumber(null); // null
```
#### `number/ensure`
If given argument is a number coercible value (via [`number/coerce`](#numbercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureNumber = require("type/number/ensure");
ensureNumber(12); // "12"
ensureNumber(null); // Thrown TypeError: null is not a number
```
---
#### Finite Number
Finite _number_ primitive
##### `finite/coerce`
Follows [`number/coerce`](#numbercoerce) additionally rejecting `Infinity` and `-Infinity` values (`null` is returned if given values coerces to them)
```javascript
const coerceToFinite = require("type/finite/coerce");
coerceToFinite("12"); // 12
coerceToFinite(Infinity); // null
coerceToFinite(null); // null
```
##### `finite/ensure`
If given argument is a finite number coercible value (via [`finite/coerce`](#finitecoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureFinite = require("type/finite/ensure");
ensureFinite(12); // "12"
ensureFinite(null); // Thrown TypeError: null is not a finite number
```
---
#### Integer Number
Integer _number_ primitive
##### `integer/coerce`
Follows [`finite/coerce`](#finitecoerce) additionally stripping decimal part from the number
```javascript
const coerceToInteger = require("type/integer/coerce");
coerceToInteger("12.95"); // 12
coerceToInteger(Infinity); // null
coerceToInteger(null); // null
```
##### `integer/ensure`
If given argument is an integer coercible value (via [`integer/coerce`](#integercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureInteger = require("type/integer/ensure");
ensureInteger(12.93); // "12"
ensureInteger(null); // Thrown TypeError: null is not an integer
```
---
#### Safe Integer Number
Safe integer _number_ primitive
##### `safe-integer/coerce`
Follows [`integer/coerce`](#integercoerce) but returns `null` in place of values which are beyond `Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER` range.
```javascript
const coerceToSafeInteger = require("type/safe-integer/coerce");
coerceToInteger("12.95"); // 12
coerceToInteger(9007199254740992); // null
coerceToInteger(null); // null
```
##### `safe-integer/ensure`
If given argument is a safe integer coercible value (via [`safe-integer/coerce`](#safe-integercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureSafeInteger = require("type/safe-integer/ensure");
ensureSafeInteger(12.93); // "12"
ensureSafeInteger(9007199254740992); // Thrown TypeError: null is not a safe integer
```
---
#### Natural Number
Natural _number_ primitive
##### `natural-number/coerce`
Follows [`integer/coerce`](#integercoerce) but returns `null` for values below `0`
```javascript
const coerceToNaturalNumber = require("type/natural-number/coerce");
coerceToNaturalNumber("12.95"); // 12
coerceToNaturalNumber(-120); // null
coerceToNaturalNumber(null); // null
```
##### `natural-number/ensure`
If given argument is a natural number coercible value (via [`natural-number/coerce`](#natural-numbercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureNaturalNumber = require("type/natural-number/ensure");
ensureNaturalNumber(12.93); // "12"
ensureNaturalNumber(-230); // Thrown TypeError: null is not a natural number
```
---
### Plain Object
A _plain object_
- Inherits directly from `Object.prototype` or `null`
- Is not a constructor's `prototype` property
#### `plain-object/is`
Confirms if given object is a _plain object_
```javascript
const isPlainObject = require("type/plain-object/is");
isPlainObject({}); // true
isPlainObject(Object.create(null)); // true
isPlainObject([]); // false
```
#### `plain-object/ensure`
If given argument is a plain object it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePlainObject = require("type/plain-object/ensure");
ensurePlainObject({}); // {}
ensureArray("foo"); // Thrown TypeError: foo is not a plain object
```
---
### Array
_Array_ instance
#### `array/is`
Confirms if given object is a native array
```javascript
const isArray = require("type/array/is");
isArray([]); // true
isArray({}); // false
isArray("foo"); // false
```
#### `array/ensure`
If given argument is an array, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureArray = require("type/array/ensure");
ensureArray(["foo"]); // ["foo"]
ensureArray("foo"); // Thrown TypeError: foo is not an array
```
---
#### Array Like
_Array-like_ value (any value with `length` property)
#### `array-like/is`
Restricted _array-like_ confirmation. Returns true for every value that meets following contraints
- is an _object_ (or with `allowString` option, a _string_)
- is not a _function_
- Exposes `length` that meets [`array-length`](#array-lengthcoerce) constraints
```javascript
const isArrayLike = require("type/array-like/is");
isArrayLike([]); // true
isArrayLike({}); // false
isArrayLike({ length: 0 }); // true
isArrayLike("foo"); // false
isArrayLike("foo", { allowString: true }); // true
```
#### `array-like/ensure`
If given argument is an _array-like_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureArrayLike = require("type/array-like/ensure");
ensureArrayLike({ length: 0 }); // { length: 0 }
ensureArrayLike("foo", { allowString: true }); // "foo"
ensureArrayLike({}); // Thrown TypeError: null is not an iterable
```
---
#### Array length
_number_ primitive that conforms as valid _array length_
##### `array-length/coerce`
Follows [`safe-integer/coerce`](#safe-integercoerce) but returns `null` in place of values which are below `0`
```javascript
const coerceToArrayLength = require("type/safe-integer/coerce");
coerceToArrayLength("12.95"); // 12
coerceToArrayLength(9007199254740992); // null
coerceToArrayLength(null); // null
```
##### `array-length/ensure`
If given argument is an _array length_ coercible value (via [`array-length/coerce`](#array-lengthcoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureArrayLength = require("type/array-length/ensure");
ensureArrayLength(12.93); // "12"
ensureArrayLength(9007199254740992); // Thrown TypeError: null is not a valid array length
```
---
### Iterable
Value which implements _iterable_ protocol
#### `iterable/is`
Confirms if given object is an _iterable_ and is not a _string_ (unless `allowString` option is passed)
```javascript
const isIterable = require("type/iterable/is");
isIterable([]); // true
isIterable({}); // false
isIterable("foo"); // false
isIterable("foo", { allowString: true }); // true
```
Supports also `denyEmpty` option
```javascript
isIterable([], { denyEmpty: true }); // false
isIterable(["foo"], { denyEmpty: true }); // true
```
#### `iterable/ensure`
If given argument is an _iterable_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureIterable = require("type/iterable/ensure");
ensureIterable([]); // []
ensureIterable("foo", { allowString: true }); // "foo"
ensureIterable({}); // Thrown TypeError: null is not expected iterable
```
Additionally items can be coreced with `coerceItem` option. Note that in this case:
- A newly created array with coerced values is returned
- Validation crashes if any of the items is not coercible
```javascript
ensureIterable(new Set(["foo", 12])); // ["foo", "12"]
ensureIterable(new Set(["foo", {}])); // Thrown TypeError: Set({ "foo", {} }) is not expected iterable
```
---
### Date
_Date_ instance
#### `date/is`
Confirms if given object is a native date, and is not an _Invalid Date_
```javascript
const isDate = require("type/date/is");
isDate(new Date()); // true
isDate(new Date("Invalid date")); // false
isDate(Date.now()); // false
isDate("foo"); // false
```
#### `date/ensure`
If given argument is a date object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureDate = require("type/date/ensure");
const date = new Date();
ensureDate(date); // date
ensureDate(123123); // Thrown TypeError: 123123 is not a date object
```
---
### Time value
_number_ primitive which is a valid _time value_ (as used internally in _Date_ instances)
#### `time-value/coerce`
Follows [`integer/coerce`](#integercoerce) but returns `null` in place of values which go beyond 100 000 0000 days from unix epoch
```javascript
const coerceToTimeValue = require("type/time-value/coerce");
coerceToTimeValue(12312312); // true
coerceToTimeValue(Number.MAX_SAFE_INTEGER); // false
coerceToTimeValue("foo"); // false
```
##### `time-value/ensure`
If given argument is a _time value_ coercible value (via [`time-value/coerce`](#time-valuecoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureTimeValue = require("type/time-value/ensure");
ensureTimeValue(12.93); // "12"
ensureTimeValue(Number.MAX_SAFE_INTEGER); // Thrown TypeError: null is not a natural number
```
---
### Function
_Function_ instance
#### `function/is`
Confirms if given object is a native function
```javascript
const isFunction = require("type/function/is");
isFunction(function () {}); // true
isFunction(() => {}); // true
isFunction(class {}); // true
isFunction("foo"); // false
```
#### `function/ensure`
If given argument is a function object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureFunction = require("type/function/ensure");
const fn = function () {};
ensureFunction(fn); // fn
ensureFunction(/foo/); // Thrown TypeError: /foo/ is not a function
```
---
#### Plain Function
A _Function_ instance that is not a _Class_
##### `plain-function/is`
Confirms if given object is a _plain function_
```javascript
const isPlainFunction = require("type/plain-function/is");
isPlainFunction(function () {}); // true
isPlainFunction(() => {}); // true
isPlainFunction(class {}); // false
isPlainFunction("foo"); // false
```
##### `plain-function/ensure`
If given argument is a _plain function_ object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePlainFunction = require("type/function/ensure");
const fn = function () {};
ensurePlainFunction(fn); // fn
ensurePlainFunction(class {}); // Thrown TypeError: class is not a plain function
```
---
### RegExp
_RegExp_ instance
#### `reg-exp/is`
Confirms if given object is a native regular expression object
```javascript
const isRegExp = require("type/reg-exp/is");
isRegExp(/foo/);
isRegExp({}); // false
isRegExp("foo"); // false
```
#### `reg-exp/ensure`
If given argument is a regular expression object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureRegExp = require("type/reg-exp/ensure");
ensureRegExp(/foo/); // /foo/
ensureRegExp("foo"); // Thrown TypeError: null is not a regular expression object
```
---
### Promise
_Promise_ instance
#### `promise/is`
Confirms if given object is a native _promise_
```javascript
const isPromise = require("type/promise/is");
isPromise(Promise.resolve()); // true
isPromise({ then: () => {} }); // false
isPromise({}); // false
```
##### `promise/ensure`
If given argument is a promise, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePromise = require("type/promise/ensure");
const promise = Promise.resolve();
ensurePromise(promise); // promise
eensurePromise({}); // Thrown TypeError: [object Object] is not a promise
```
---
#### Thenable
_Thenable_ object (an object with `then` method)
##### `thenable/is`
Confirms if given object is a _thenable_
```javascript
const isThenable = require("type/thenable/is");
isThenable(Promise.resolve()); // true
isThenable({ then: () => {} }); // true
isThenable({}); // false
```
##### `thenable/ensure`
If given argument is a _thenable_ object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureThenable = require("type/thenable/ensure");
const promise = Promise.resolve();
ensureThenable(promise); // promise
ensureThenable({}); // Thrown TypeError: [object Object] is not a thenable object
```
---
### Error
_Error_ instance
#### `error/is`
Confirms if given object is a native error object
```javascript
const isError = require("type/error/is");
isError(new Error()); // true
isError({ message: "Fake error" }); // false
```
#### `error/ensure`
If given argument is an error object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureError = require("type/error/ensure");
const someError = new Error("Some error");
ensureError(someError); // someError
ensureError({ message: "Fake error" }); // Thrown TypeError: [object Object] is not an error object
```
---
### Prototype
Some constructor's `prototype` property
#### `prototype/is`
Confirms if given object serves as a _prototype_ property
```javascript
const isPrototype = require("type/prototype/is");
isPrototype({}); // false
isPrototype(Object.prototype); // true
isPrototype(Array.prototype); // true
```
- `errorMessage` - Custom error message. Following placeholders can be used:
- `%v` - To be replaced with short string representation of invalid value
- `%n` - To be replaced with meaninfgul name (to be passed with `name` option) of validated value. Not effective if `name` option is not present
- `errorCode` - Eventual error code to be exposed on `.code` error property
- `name` - Meaningful name for validated value, to be used in error message, assuming it contains `%n` placeholder
- `Error` - Alternative error constructor to be used (defaults to `TypeError`)
### Index
#### General utils:
- [`ensure`](docs/ensure.md)
#### Type specific utils:
- **Value**
- [`value/is`](docs/value.md#valueis)
- [`value/ensure`](docs/value.md#valueensure)
- **Object**
- [`object/is`](docs/object.md#objectis)
- [`object/ensure`](docs/object.md#objectensure)
- **Plain Object**
- [`plain-object/is`](docs/plain-object.md#plain-objectis)
- [`plain-object/ensure`](docs/plain-object.md#plain-objectensure)
- **String**
- [`string/coerce`](docs/string.md#stringcoerce)
- [`string/ensure`](docs/string.md#stringensure)
- **Number**
- [`number/coerce`](docs/number.md#numbercoerce)
- [`number/ensure`](docs/number.md#numberensure)
- **Finite Number**
- [`finite/coerce`](docs/finite.md#finitecoerce)
- [`finite/ensure`](docs/finite.md#finiteensure)
- **Integer Number**
- [`integer/coerce`](docs/integer.md#integercoerce)
- [`integer/ensure`](docs/integer.md#integerensure)
- **Safe Integer Number**
- [`safe-integer/coerce`](docs/safe-integer.md#safe-integercoerce)
- [`safe-integer/ensure`](docs/.md#safe-integerensure)
- **Natural Number**
- [`natural-number/coerce`](docs/natural-number.md#natural-numbercoerce)
- [`natural-number/ensure`](docs/natural-number.md#natural-numberensure)
- **Array Length**
- [`array-length/coerce`](docs/array-length.md#array-lengthcoerce)
- [`array-length/ensure`](docs/array-length.md#array-lengthensure)
- **Time Value**
- [`time-value/coerce`](docs/time-value.md#time-valuecoerce)
- [`time-value/ensure`](docs/time-value.md#time-valueensure)
- **BigInt**
- [`big-int/coerce`](docs/big-int.md#big-intcoerce)
- [`big-int/ensure`](docs/big-int.md#big-intensure)
- **Array Like**
- [`array-like/is`](docs/array-like.md#array-likeis)
- [`array-like/ensure`](docs/array-like.md#array-likeensure)
- **Array**
- [`array/is`](docs/array.md#arrayis)
- [`array/ensure`](docs/array.md#arrayensure)
- **Iterable**
- [`iterable/is`](docs/iterable.md#iterableis)
- [`iterable/ensure`](docs/iterable.md#iterableensure)
- **Set**
- [`set/is`](docs/set.md#setis)
- [`set/ensure`](docs/set.md#setensure)
- **Map**
- [`map/is`](docs/map.md#mapis)
- [`map/ensure`](docs/map.md#mapensure)
- **Date**
- [`date/is`](docs/date.md#dateis)
- [`date/ensure`](docs/date.md#dateensure)
- **Function**
- [`function/is`](docs/function.md#functionis)
- [`function/ensure`](docs/function.md#functionensure)
- **Constructor**
- [`constructor/is`](docs/constructor.md#plain-functionis)
- [`constructor/ensure`](docs/constructor.md#plain-functionensure)
- **Plain Function**
- [`plain-function/is`](docs/plain-function.md#plain-functionis)
- [`plain-function/ensure`](docs/plain-function.md#plain-functionensure)
- **Reg Exp**
- [`reg-exp/is`](docs/reg-exp.md#reg-expis)
- [`reg-exp/ensure`](docs/.md#reg-expensure)
- **Thenable**
- [`thenable/is`](docs/thenable.md#thenableis)
- [`thenable/ensure`](docs/thenable.md#thenableensure)
- **Promise**
- [`promise/is`](docs/promise.md#promiseis)
- [`promise/ensure`](docs/promise.md#promiseensure)
- **Error**
- [`error/is`](docs/error.md#erroris)
- [`error/ensure`](docs/error.md#errorensure)
- **Prototype**
- [`prototype/is`](docs/prototype.md#prototypeis)
### Tests
$ npm test
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/type/branches/master/shields_badge.svg
[nix-build-url]: https://semaphoreci.com/medikoo-org/type
[win-build-image]: https://ci.appveyor.com/api/projects/status/8nrtluuwsb5k9l8d?svg=true
[win-build-url]: https://ci.appveyor.com/api/project/medikoo/type
[build-image]: https://github.com/medikoo/type/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/type/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/type.svg
[cov-url]: https://codecov.io/gh/medikoo/type
[npm-image]: https://img.shields.io/npm/v/type.svg
[npm-url]: https://www.npmjs.com/package/type
## Security contact information
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.

View File

@@ -6,5 +6,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a valid array length", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected an array length for %n, received %v"
: "%v is not an array length";
return resolveException(value, errorMessage, options);
};

View File

@@ -5,5 +5,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value, arguments[1])) return value;
return resolveException(value, "%v is not an array like value", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected an array like for %n, received %v"
: "%v is not an array like";
return resolveException(value, errorMessage, options);
};

42
node_modules/type/array/ensure.js generated vendored
View File

@@ -1,9 +1,43 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, is = require("./is");
var resolveException = require("../lib/resolve-exception")
, resolveErrorMessage = require("../lib/resolve-error-message")
, toShortString = require("../lib/to-short-string")
, ensurePlainFunction = require("../plain-function/ensure")
, is = require("./is");
var objHasOwnProperty = Object.prototype.hasOwnProperty, invalidItemsLimit = 3;
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not an array object", arguments[1]);
var options = arguments[1];
var mainErrorMessage =
options && options.name ? "Expected an array for %n, received %v" : "%v is not an array";
if (!is(value)) return resolveException(value, mainErrorMessage, options);
if (!options) return value;
var ensureItem = ensurePlainFunction(options.ensureItem, { isOptional: true });
if (ensureItem) {
var coercedValue = [], invalidItems;
for (var index = 0, length = value.length; index < length; ++index) {
if (!objHasOwnProperty.call(value, index)) continue;
var coercedItem;
try {
coercedItem = ensureItem(value[index]);
} catch (error) {
if (!invalidItems) invalidItems = [];
if (invalidItems.push(toShortString(value[index])) === invalidItemsLimit) break;
}
if (invalidItems) continue;
coercedValue[index] = coercedItem;
}
if (invalidItems) {
throw new TypeError(
resolveErrorMessage(mainErrorMessage, value, options) +
".\n Following items are invalid: " +
invalidItems.join(", ")
);
}
return coercedValue;
}
return value;
};

13
node_modules/type/big-int/coerce.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
"use strict";
var isValue = require("../value/is");
// Sanity BigInt support check
BigInt(0);
module.exports = function (value) {
if (!isValue(value)) return null;
if (typeof value === "bigint") return value;
try { return BigInt(value); }
catch (error) { return null; }
};

13
node_modules/type/big-int/ensure.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, coerce = require("./coerce");
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected bigint for %n, received %v" : "%v is not a bigint";
return resolveException(value, errorMessage, options);
};

14
node_modules/type/constructor/ensure.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, is = require("./is");
module.exports = function (value/*, options*/) {
if (is(value)) return value;
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a constructor function for %n, received %v"
: "%v is not a constructor function";
return resolveException(value, errorMessage, options);
};

12
node_modules/type/constructor/is.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
var isFunction = require("../function/is");
var constructorRe = /^\s*(?:class[\s{/}]|function[\s(])/
, functionToString = Function.prototype.toString;
module.exports = function (value) {
if (!isFunction(value)) return false;
if (!constructorRe.test(functionToString.call(value))) return false;
return true;
};

5
node_modules/type/date/ensure.js generated vendored
View File

@@ -5,5 +5,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a date object", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a date for %n, received %v" : "%v is not a date";
return resolveException(value, errorMessage, options);
};

27
node_modules/type/docs/array-length.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Array length
_number_ primitive that conforms as valid _array length_
## `array-length/coerce`
Follows [`safe-integer/coerce`](safe-integer.md#safe-integercoerce) but returns `null` in place of values which are below `0`
```javascript
const coerceToArrayLength = require("type/safe-integer/coerce");
coerceToArrayLength("12.95"); // 12
coerceToArrayLength(9007199254740992); // null
coerceToArrayLength(null); // null
```
## `array-length/ensure`
If given argument is an _array length_ coercible value (via [`array-length/coerce`](#array-lengthcoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureArrayLength = require("type/array-length/ensure");
ensureArrayLength(12.93); // "12"
ensureArrayLength(9007199254740992); // Thrown TypeError: 9007199254740992 is not a valid array length
```

33
node_modules/type/docs/array-like.md generated vendored Normal file
View File

@@ -0,0 +1,33 @@
# Array Like
_Array-like_ value (any value with `length` property)
## `array-like/is`
Restricted _array-like_ confirmation. Returns true for every value that meets following contraints
- is an _object_ (or with `allowString` option, a _string_)
- is not a _function_
- Exposes `length` that meets [`array-length`](array-length.md#array-lengthcoerce) constraints
```javascript
const isArrayLike = require("type/array-like/is");
isArrayLike([]); // true
isArrayLike({}); // false
isArrayLike({ length: 0 }); // true
isArrayLike("foo"); // false
isArrayLike("foo", { allowString: true }); // true
```
## `array-like/ensure`
If given argument is an _array-like_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureArrayLike = require("type/array-like/ensure");
ensureArrayLike({ length: 0 }); // { length: 0 }
ensureArrayLike("foo", { allowString: true }); // "foo"
ensureArrayLike({}); // Thrown TypeError: null is not an iterable
```

46
node_modules/type/docs/array.md generated vendored Normal file
View File

@@ -0,0 +1,46 @@
# Array
_Array_ instance
## `array/is`
Confirms if given object is a native array
```javascript
const isArray = require("type/array/is");
isArray([]); // true
isArray({}); // false
isArray("foo"); // false
```
## `array/ensure`
If given argument is an array, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureArray = require("type/array/ensure");
ensureArray(["foo"]); // ["foo"]
ensureArray("foo"); // Thrown TypeError: foo is not an array
```
### Confirming on items
Items can be validated by passing `ensureItem` option. Note that in this case:
- A newly created instance of an array with coerced item values is returned
- Error message lists up to three items which are invalid
```javascript
const ensureString = require("type/string/ensure");
ensureArray([12], { ensureItem: ensureString }); // ["12"]
/*
Below invocation with crash with:
TypeError: 23, [object Object], [object Object] is not a valid array.
Following items are invalid: [object Object], [object Object]
*/
ensureArray([23, {}, {}], { ensureItem: ensureString });
```

27
node_modules/type/docs/big-int.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# BigInt
_bigint_ primitive
## `big-int/coerce`
BigInt coercion. If value can be coerced by `BigInt` its result is returned.
For all other values `null` is returned
```javascript
const coerceToBigInt = require("type/big-int/coerce");
coerceToBigInt(12); // 12n
coerceToBigInt(undefined); // null
```
## `big-int/ensure`
If given argument is a _bigint_ coercible value (via [`big-int/coerce`](#big-intcoerce)) returns result bigint.
Otherwise `TypeError` is thrown.
```javascript
const ensureBigInt = require("type/big-int/ensure");
ensureBigInt(12); // 12n
ensureBigInt(null); // Thrown TypeError: null is not a bigint
```

28
node_modules/type/docs/constructor.md generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Constructor
A _Function_ instance that's a _constructor_ (either regular function or _class_)
## `constructor/is`
Confirms if given object is a constructor function\_
```javascript
const isConstructor = require("type/constructor/is");
isConstructor(function () {}); // true
isConstructor(() => {}); // false
isConstructor(class {}); // true
isConstructor("foo"); // false
```
## `constructor/ensure`
If given argument is a _constructor function_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureConstructor = require("type/constructor/ensure");
const fn = function () {};
ensureConstructor(fn); // fn
ensureConstructor(() => {}); // Thrown TypeError: () => {} is not a constructor function
```

28
node_modules/type/docs/date.md generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Date
_Date_ instance
## `date/is`
Confirms if given object is a native date, and is not an _Invalid Date_
```javascript
const isDate = require("type/date/is");
isDate(new Date()); // true
isDate(new Date("Invalid date")); // false
isDate(Date.now()); // false
isDate("foo"); // false
```
## `date/ensure`
If given argument is a date object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureDate = require("type/date/ensure");
const date = new Date();
ensureDate(date); // date
ensureDate(123123); // Thrown TypeError: 123123 is not a date object
```

40
node_modules/type/docs/ensure.md generated vendored Normal file
View File

@@ -0,0 +1,40 @@
# `ensure(validationDatum1[, ...validationDatumN[, options]])`
Provides a complete cumulated input validation for an API endpoint. Validates multiple input arguments and consolidates eventual errors into one.
## Arguments
### `validationDatum1[, ...validationDatumN]`
For each argument to be validated a `validationDatum` of following stucture should be defined:
```javascript
[argumentName, inputValue, ensureFunction, (options = {})];
```
- `argumentName` - Name of validated argument (used for meaningful error messaging)
- `inputValue` - An argument value as passed to function
- `ensureFunction` - An `ensureX` function with which argument should be validated (e.g. if we're after string, then we need [string/ensure](string.md#stringensure))
- `options` - Optional, extra options to be passed to `ensureX` function
### `[options]`
Eventual options be passed to underlying `ensureX` functions. If custom error constructor is passed with an `Error` option, then cumulated error is created with this constructor.
## Usage example
```javascript
const ensure = require("type/ensure");
const ensureString = require("type/string/ensure");
const ensureNaturalNumber = require("type/natural-number/ensure");
const resolveRepositoryIssue = (repoName, issueNumber) => {
// Validate input
[repoName, issueNumber] = ensure(
["repoName", repoName, ensureString],
["issueNumber", issueNumber, ensureNaturalNumber],
{ Error: UserError }
);
// ... logic
};
```

26
node_modules/type/docs/error.md generated vendored Normal file
View File

@@ -0,0 +1,26 @@
# Error
_Error_ instance
## `error/is`
Confirms if given object is a native error object
```javascript
const isError = require("type/error/is");
isError(new Error()); // true
isError({ message: "Fake error" }); // false
```
## `error/ensure`
If given argument is an error object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureError = require("type/error/ensure");
const someError = new Error("Some error");
ensureError(someError); // someError
ensureError({ message: "Fake error" }); // Thrown TypeError: [object Object] is not an error object
```

27
node_modules/type/docs/finite.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Finite Number
Finite _number_ primitive
## `finite/coerce`
Follows [`number/coerce`](number.md#numbercoerce) additionally rejecting `Infinity` and `-Infinity` values (`null` is returned if given values coerces to them)
```javascript
const coerceToFinite = require("type/finite/coerce");
coerceToFinite("12"); // 12
coerceToFinite(Infinity); // null
coerceToFinite(null); // null
```
## `finite/ensure`
If given argument is a finite number coercible value (via [`finite/coerce`](#finitecoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureFinite = require("type/finite/ensure");
ensureFinite(12); // "12"
ensureFinite(null); // Thrown TypeError: null is not a finite number
```

28
node_modules/type/docs/function.md generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Function
_Function_ instance
## `function/is`
Confirms if given object is a native function
```javascript
const isFunction = require("type/function/is");
isFunction(function () {}); // true
isFunction(() => {}); // true
isFunction(class {}); // true
isFunction("foo"); // false
```
## `function/ensure`
If given argument is a function object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureFunction = require("type/function/ensure");
const fn = function () {};
ensureFunction(fn); // fn
ensureFunction(/foo/); // Thrown TypeError: /foo/ is not a function
```

27
node_modules/type/docs/integer.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Integer Number
Integer _number_ primitive
## `integer/coerce`
Follows [`finite/coerce`](finite.md#finitecoerce) additionally stripping decimal part from the number
```javascript
const coerceToInteger = require("type/integer/coerce");
coerceToInteger("12.95"); // 12
coerceToInteger(Infinity); // null
coerceToInteger(null); // null
```
## `integer/ensure`
If given argument is an integer coercible value (via [`integer/coerce`](#integercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureInteger = require("type/integer/ensure");
ensureInteger(12.93); // "12"
ensureInteger(null); // Thrown TypeError: null is not an integer
```

65
node_modules/type/docs/iterable.md generated vendored Normal file
View File

@@ -0,0 +1,65 @@
# Iterable
Value which implements _iterable_ protocol
## `iterable/is`
Confirms if given object is an _iterable_ and is not a _string_ (unless `allowString` option is passed)
```javascript
const isIterable = require("type/iterable/is");
isIterable([]); // true
isIterable({}); // false
isIterable("foo"); // false
isIterable("foo", { allowString: true }); // true
```
Supports also `denyEmpty` option
```javascript
isIterable([], { denyEmpty: true }); // false
isIterable(["foo"], { denyEmpty: true }); // true
```
## `iterable/ensure`
If given argument is an _iterable_, it is returned back. Otherwise `TypeError` is thrown.
By default _string_ primitives are rejected unless `allowString` option is passed.
```javascript
const ensureIterable = require("type/iterable/ensure");
ensureIterable([]); // []
ensureIterable("foo", { allowString: true }); // "foo"
ensureIterable({}); // Thrown TypeError: null is not expected iterable
```
### Denying empty iterables
Pass `denyEmpty` option to require non empty iterables
```javascript
ensureIterable([], { denyEmpty: true }); // Thrown TypeError: [] is not expected iterable
```
### Confirming on items
Items can be validated by passing `ensureItem` option. Note that in this case:
- A newly created instance of array with coerced values is returned
- Error message lists up to three invalid items
```javascript
const ensureString = require("type/string/ensure");
ensureIterable(new Set(["foo", 12]), { ensureItem: ensureString }); // ["foo", "12"]
/*
Below invocation with crash with:
TypeError: [object Set] is not expected iterable value.
Following items are invalid:
- [object Object]
*/
ensureIterable(new Set(["foo", {}]), { ensureItem: ensureString });
```

27
node_modules/type/docs/map.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Map
_Map_ instance
## `map/is`
Confirms if given object is a native _map_
```javascript
const isMap = require("type/map/is");
isMap(new Map()); // true
isMap(new Set()); // false
isMap({}); // false
```
## `map/ensure`
If given argument is a _map_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureMap = require("type/map/ensure");
const map = new Map();
ensureMap(map); // map
eensureMap({}); // Thrown TypeError: [object Object] is not a map
```

27
node_modules/type/docs/natural-number.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Natural Number
Natural _number_ primitive
## `natural-number/coerce`
Follows [`integer/coerce`](integer.md#integercoerce) but returns `null` for values below `0`
```javascript
const coerceToNaturalNumber = require("type/natural-number/coerce");
coerceToNaturalNumber("12.95"); // 12
coerceToNaturalNumber(-120); // null
coerceToNaturalNumber(null); // null
```
## `natural-number/ensure`
If given argument is a natural number coercible value (via [`natural-number/coerce`](#natural-numbercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureNaturalNumber = require("type/natural-number/ensure");
ensureNaturalNumber(12.93); // "12"
ensureNaturalNumber(-230); // Thrown TypeError: null is not a natural number
```

33
node_modules/type/docs/number.md generated vendored Normal file
View File

@@ -0,0 +1,33 @@
# Number
_number_ primitive
## `number/coerce`
Restricted number coercion. Returns number presentation for every value that follows below constraints
- is implicitly coercible to number
- is neither `null` nor `undefined`
- is not `NaN` and doesn't coerce to `NaN`
For all other values `null` is returned
```javascript
const coerceToNumber = require("type/number/coerce");
coerceToNumber("12"); // 12
coerceToNumber({}); // null
coerceToNumber(null); // null
```
## `number/ensure`
If given argument is a number coercible value (via [`number/coerce`](#numbercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureNumber = require("type/number/ensure");
ensureNumber(12); // "12"
ensureNumber(null); // Thrown TypeError: null is not a number
```

28
node_modules/type/docs/object.md generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Object
_Object_, any non-primitive value
## `object/is`
Confirms if passed value is an object
```javascript
const isObject = require("type/object/is");
isObject({}); // true
isObject(true); // false
isObject(null); // false
```
## `object/ensure`
If given argument is an object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureObject = require("type/object/ensure");
const obj = {};
ensureObject(obj); // obj
ensureString(null); // Thrown TypeError: null is not an object
```

28
node_modules/type/docs/plain-function.md generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Plain Function
A _Function_ instance that is not a _Class_
## `plain-function/is`
Confirms if given object is a _plain function_
```javascript
const isPlainFunction = require("type/plain-function/is");
isPlainFunction(function () {}); // true
isPlainFunction(() => {}); // true
isPlainFunction(class {}); // false
isPlainFunction("foo"); // false
```
## `plain-function/ensure`
If given argument is a _plain function_ object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePlainFunction = require("type/function/ensure");
const fn = function () {};
ensurePlainFunction(fn); // fn
ensurePlainFunction(class {}); // Thrown TypeError: class is not a plain function
```

69
node_modules/type/docs/plain-object.md generated vendored Normal file
View File

@@ -0,0 +1,69 @@
# Plain Object
A _plain object_
- Inherits directly from `Object.prototype` or `null`
- Is not a constructor's `prototype` property
## `plain-object/is`
Confirms if given object is a _plain object_
```javascript
const isPlainObject = require("type/plain-object/is");
isPlainObject({}); // true
isPlainObject(Object.create(null)); // true
isPlainObject([]); // false
```
## `plain-object/ensure`
If given argument is a plain object it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePlainObject = require("type/plain-object/ensure");
ensurePlainObject({}); // {}
ensurePlainObject("foo"); // Thrown TypeError: foo is not a plain object
```
### Confirming on keys
Keys can be validated by passing `allowedKeys` option. Note that in this case:
- Error message lists up to three invalid keys
```javascript
const allowedKeys = ["foo"];
ensurePlainObject({}, { allowedKeys }); // {}
ensurePlainObject({ foo: "bar" }, { allowedKeys }); // { foo: 'bar' }
/*
Below invocation with crash with:
TypeError: [object Object] is not a valid plain object.
Following keys are unexpected: lorem, ipsum
*/
ensurePlainObject({ foo: "bar", lorem: 1, ipsum: 2 }, { allowedKeys });
```
### Confirming on property values
Property values can be validated by passing `ensurePropertyValue` option. Note that in this case:
- A newly created instance of plain object with coerced values is returned
- Error message lists up to three keys that contain invalid values
```javascript
const ensureString = require("type/string/ensure");
ensurePlainObject({ foo: 12 }, { ensurePropertyValue: ensureString }); // { foo: '12' }
/*
Below invocation with crash with:
TypeError: [object Object] is not a valid plain object.
Valuees for following keys are invalid: lorem, ipsum
*/
ensurePlainObject({ foo: 23, lorem: {}, ipsum: {} }, { ensurePropertyValue: ensureString });
```

27
node_modules/type/docs/promise.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Promise
_Promise_ instance
## `promise/is`
Confirms if given object is a native _promise_
```javascript
const isPromise = require("type/promise/is");
isPromise(Promise.resolve()); // true
isPromise({ then: () => {} }); // false
isPromise({}); // false
```
## `promise/ensure`
If given argument is a promise, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensurePromise = require("type/promise/ensure");
const promise = Promise.resolve();
ensurePromise(promise); // promise
eensurePromise({}); // Thrown TypeError: [object Object] is not a promise
```

15
node_modules/type/docs/prototype.md generated vendored Normal file
View File

@@ -0,0 +1,15 @@
# Prototype
Some constructor's `prototype` property
## `prototype/is`
Confirms if given object serves as a _prototype_ property
```javascript
const isPrototype = require("type/prototype/is");
isPrototype({}); // false
isPrototype(Object.prototype); // true
isPrototype(Array.prototype); // true
```

26
node_modules/type/docs/reg-exp.md generated vendored Normal file
View File

@@ -0,0 +1,26 @@
# RegExp
_RegExp_ instance
## `reg-exp/is`
Confirms if given object is a native regular expression object
```javascript
const isRegExp = require("type/reg-exp/is");
isRegExp(/foo/);
isRegExp({}); // false
isRegExp("foo"); // false
```
## `reg-exp/ensure`
If given argument is a regular expression object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureRegExp = require("type/reg-exp/ensure");
ensureRegExp(/foo/); // /foo/
ensureRegExp("foo"); // Thrown TypeError: null is not a regular expression object
```

27
node_modules/type/docs/safe-integer.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Safe Integer Number
Safe integer _number_ primitive
## `safe-integer/coerce`
Follows [`integer/coerce`](integer.md#integercoerce) but returns `null` in place of values which are beyond `Number.MIN_SAFE_INTEGER` and `Number.MAX_SAFE_INTEGER` range.
```javascript
const coerceToSafeInteger = require("type/safe-integer/coerce");
coerceToInteger("12.95"); // 12
coerceToInteger(9007199254740992); // null
coerceToInteger(null); // null
```
## `safe-integer/ensure`
If given argument is a safe integer coercible value (via [`safe-integer/coerce`](#safe-integercoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureSafeInteger = require("type/safe-integer/ensure");
ensureSafeInteger(12.93); // "12"
ensureSafeInteger(9007199254740992); // Thrown TypeError: null is not a safe integer
```

27
node_modules/type/docs/set.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Set
_Set_ instance
## `set/is`
Confirms if given object is a native set\_
```javascript
const isSet = require("type/set/is");
isSet(new Set()); // true
isSet(new Map()); // false
isSet({}); // false
```
## `Set/ensure`
If given argument is a _set_, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureSet = require("type/set/ensure");
const set = new Set();
ensureSet(set); // set
eensureSet({}); // Thrown TypeError: [object Object] is not a set
```

32
node_modules/type/docs/string.md generated vendored Normal file
View File

@@ -0,0 +1,32 @@
# String
_string_ primitive
## `string/coerce`
Restricted string coercion. Returns string presentation for every value that follows below constraints
- is implicitly coercible to string
- is neither`null` nor `undefined`
- its `toString` method is not `Object.prototype.toString`
For all other values `null` is returned
```javascript
const coerceToString = require("type/string/coerce");
coerceToString(12); // "12"
coerceToString(undefined); // null
```
## `string/ensure`
If given argument is a string coercible value (via [`string/coerce`](#stringcoerce)) returns result string.
Otherwise `TypeError` is thrown.
```javascript
const ensureString = require("type/string/ensure");
ensureString(12); // "12"
ensureString(null); // Thrown TypeError: null is not a string
```

27
node_modules/type/docs/thenable.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Thenable
_Thenable_ object (an object with `then` method)
## `thenable/is`
Confirms if given object is a _thenable_
```javascript
const isThenable = require("type/thenable/is");
isThenable(Promise.resolve()); // true
isThenable({ then: () => {} }); // true
isThenable({}); // false
```
## `thenable/ensure`
If given argument is a _thenable_ object, it is returned back. Otherwise `TypeError` is thrown.
```javascript
const ensureThenable = require("type/thenable/ensure");
const promise = Promise.resolve();
ensureThenable(promise); // promise
ensureThenable({}); // Thrown TypeError: [object Object] is not a thenable object
```

27
node_modules/type/docs/time-value.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Time value
_number_ primitive which is a valid _time value_ (as used internally in _Date_ instances)
## `time-value/coerce`
Follows [`integer/coerce`](integer.md#integercoerce) but returns `null` in place of values which go beyond 100 000 0000 days from unix epoch
```javascript
const coerceToTimeValue = require("type/time-value/coerce");
coerceToTimeValue(12312312); // true
coerceToTimeValue(Number.MAX_SAFE_INTEGER); // false
coerceToTimeValue("foo"); // false
```
## `time-value/ensure`
If given argument is a _time value_ coercible value (via [`time-value/coerce`](#time-valuecoerce)) returns result number.
Otherwise `TypeError` is thrown.
```javascript
const ensureTimeValue = require("type/time-value/ensure");
ensureTimeValue(12.93); // "12"
ensureTimeValue(Number.MAX_SAFE_INTEGER); // Thrown TypeError: null is not a natural number
```

27
node_modules/type/docs/value.md generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# Value
_Value_, any value that's neither `null` nor `undefined` .
## `value/is`
Confirms whether passed argument is a _value_
```javascript
const isValue = require("type/value/is");
isValue({}); // true
isValue(null); // false
```
## `value/ensure`
Ensures if given argument is a _value_. If it's a value it is returned back, if not `TypeError` is thrown
```javascript
const ensureValue = require("type/value/ensure");
const obj = {};
ensureValue(obj); // obj
ensureValue(null); // Thrown TypeError: Cannot use null
```

51
node_modules/type/ensure.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
var isArray = require("./array/is")
, toShortString = require("./lib/to-short-string");
var objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable;
var assign = function (target, source) {
for (var key in source) {
if (objPropertyIsEnumerable.call(source, key)) target[key] = source[key];
}
};
module.exports = function (validationDatum1/*, ...validationDatumN, options */) {
var validationData = [validationDatum1];
var globalOptions;
if (arguments.length > 1) {
var hasOptions = !isArray(arguments[arguments.length - 1]);
if (hasOptions) globalOptions = arguments[arguments.length - 1];
var lastDatumIndex = hasOptions ? arguments.length - 2 : arguments.length - 1;
for (var i = 1; i <= lastDatumIndex; ++i) validationData.push(arguments[i]);
}
var result = [], errors;
for (var j = 0; j < validationData.length; ++j) {
var validationDatum = validationData[j];
var options = { name: validationDatum[0] };
if (globalOptions) assign(options, globalOptions);
if (validationDatum[3]) assign(options, validationDatum[3]);
var resultItem;
if (typeof validationDatum[2] !== "function") {
throw new TypeError(toShortString(validationDatum[2]) + " is not a function");
}
try {
resultItem = validationDatum[2](validationDatum[1], options);
} catch (error) {
if (!errors) errors = [];
errors.push(error);
}
if (errors) continue;
result.push(resultItem);
}
if (!errors) return result;
if (errors.length === 1) throw errors[0];
var ErrorConstructor = (globalOptions && globalOptions.Error) || TypeError;
var errorMessage = "Approached following errors:";
for (var k = 0; k < errors.length; ++k) {
errorMessage += "\n - " + errors[k].message.split("\n").join("\n ");
}
throw new ErrorConstructor(errorMessage);
};

5
node_modules/type/error/ensure.js generated vendored
View File

@@ -5,5 +5,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not an error object", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected an error for %n, received %v" : "%v is not an error";
return resolveException(value, errorMessage, options);
};

7
node_modules/type/finite/ensure.js generated vendored
View File

@@ -6,5 +6,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a finite number", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a finite number for %n, received %v"
: "%v is not a finite number";
return resolveException(value, errorMessage, options);
};

View File

@@ -5,5 +5,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a function", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a function for %n, received %v"
: "%v is not a function";
return resolveException(value, errorMessage, options);
};

View File

@@ -6,5 +6,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not an integer", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected an integer for %n, received %v"
: "%v is not an integer";
return resolveException(value, errorMessage, options);
};

62
node_modules/type/iterable/ensure.js generated vendored
View File

@@ -1,29 +1,49 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, isValue = require("../value/is")
, is = require("./is");
var resolveException = require("../lib/resolve-exception")
, resolveErrorMessage = require("../lib/resolve-error-message")
, toShortString = require("../lib/to-short-string")
, ensurePlainFunction = require("../plain-function/ensure")
, is = require("./is");
var invalidItemsLimit = 3;
var resolveCoercedValue = function (value, coerceItem) {
var coercedValue = [];
var iterator = value[Symbol.iterator]();
var item;
while (!(item = iterator.next()).done) {
var newItemValue = coerceItem(item.value);
if (!isValue(newItemValue)) throw new Error("Stop propagation");
coercedValue.push(newItemValue);
}
return coercedValue;
};
module.exports = function (value/*, options*/) {
var options = arguments[1];
if (is(value, options)) {
if (!options) return value;
if (typeof options.coerceItem !== "function") return value;
try { return resolveCoercedValue(value, options.coerceItem); }
catch (error) {
// Ignore, let validation error propagate
var mainErrorMessage =
options && options.name
? "Expected an iterable for %n, received %v"
: "%v is not expected iterable";
if (!is(value, options)) return resolveException(value, mainErrorMessage, options);
if (!options) return value;
var ensureItem = ensurePlainFunction(options.ensureItem, { isOptional: true });
if (ensureItem) {
var coercedValue = [];
var iterator = value[Symbol.iterator]();
var item, invalidItems;
while (!(item = iterator.next()).done) {
var newItemValue;
try {
newItemValue = ensureItem(item.value);
} catch (error) {
if (!invalidItems) invalidItems = [];
if (invalidItems.push(item.value) === invalidItemsLimit) break;
}
if (invalidItems) continue;
coercedValue.push(newItemValue);
}
if (invalidItems) {
var errorMessage =
resolveErrorMessage(mainErrorMessage, value, options) +
".\n Following items are invalid:";
for (var i = 0; i < invalidItems.length; ++i) {
errorMessage += "\n - " + toShortString(invalidItems[i]);
}
throw new TypeError(errorMessage);
}
return coercedValue;
}
return resolveException(value, "%v is not expected iterable value", options);
return value;
};

12
node_modules/type/lib/ensure/min.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
var resolveException = require("../resolve-exception");
module.exports = function (value, coerced, options) {
if (coerced >= options.min) return coerced;
var errorMessage =
options && options.name
? "Expected %n to be greater or equal " + options.min + ", received %v"
: "%v is not greater or equal " + options.min;
return resolveException(value, errorMessage, options);
};

52
node_modules/type/lib/resolve-error-message.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
"use strict";
var stringCoerce = require("../string/coerce")
, toShortString = require("./to-short-string");
module.exports = function (errorMessage, value, inputOptions) {
if (inputOptions && inputOptions.errorMessage) {
errorMessage = stringCoerce(inputOptions.errorMessage);
}
var valueInsertIndex = errorMessage.indexOf("%v");
var valueToken = valueInsertIndex > -1 ? toShortString(value) : null;
if (inputOptions && inputOptions.name) {
var nameInsertIndex = errorMessage.indexOf("%n");
if (nameInsertIndex > -1) {
if (valueInsertIndex > -1) {
var firstToken, secondToken, firstInsertIndex, secondInsertIndex;
if (nameInsertIndex > valueInsertIndex) {
firstToken = valueToken;
firstInsertIndex = valueInsertIndex;
secondToken = inputOptions.name;
secondInsertIndex = nameInsertIndex;
} else {
firstToken = inputOptions.name;
firstInsertIndex = nameInsertIndex;
secondToken = valueToken;
secondInsertIndex = valueInsertIndex;
}
return (
errorMessage.slice(0, firstInsertIndex) +
firstToken +
errorMessage.slice(firstInsertIndex + 2, secondInsertIndex) +
secondToken +
errorMessage.slice(secondInsertIndex + 2)
);
}
return (
errorMessage.slice(0, nameInsertIndex) +
inputOptions.name +
errorMessage.slice(nameInsertIndex + 2)
);
}
}
if (valueInsertIndex > -1) {
return (
errorMessage.slice(0, valueInsertIndex) +
valueToken +
errorMessage.slice(valueInsertIndex + 2)
);
}
return errorMessage;
};

View File

@@ -1,21 +1,15 @@
"use strict";
var isValue = require("../value/is")
, isObject = require("../object/is")
, stringCoerce = require("../string/coerce")
, toShortString = require("./to-short-string");
var resolveMessage = function (message, value) {
return message.replace("%v", toShortString(value));
};
var isValue = require("../value/is")
, resolveErrorMessage = require("./resolve-error-message");
module.exports = function (value, defaultMessage, inputOptions) {
if (!isObject(inputOptions)) throw new TypeError(resolveMessage(defaultMessage, value));
if (!isValue(value)) {
if (inputOptions && !isValue(value)) {
if ("default" in inputOptions) return inputOptions["default"];
if (inputOptions.isOptional) return null;
}
var errorMessage = stringCoerce(inputOptions.errorMessage);
if (!isValue(errorMessage)) errorMessage = defaultMessage;
throw new TypeError(resolveMessage(errorMessage, value));
var ErrorConstructor = (inputOptions && inputOptions.Error) || TypeError;
var error = new ErrorConstructor(resolveErrorMessage(defaultMessage, value, inputOptions));
if (inputOptions && inputOptions.errorCode) error.code = inputOptions.errorCode;
throw error;
};

12
node_modules/type/map/ensure.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, is = require("./is");
module.exports = function (value/*, options*/) {
if (is(value)) return value;
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a map for %n, received %v" : "%v is not a map";
return resolveException(value, errorMessage, options);
};

28
node_modules/type/map/is.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
"use strict";
var isPrototype = require("../prototype/is");
// In theory we could rely on Symbol.toStringTag directly,
// still early native implementation (e.g. in FF) predated symbols
var objectToString = Object.prototype.toString, objectTaggedString = objectToString.call(new Map());
module.exports = function (value) {
if (!value) return false;
// Sanity check (reject objects which do not expose common Promise interface)
try {
if (typeof value.set !== "function") return false;
if (typeof value.get !== "function") return false;
if (typeof value.has !== "function") return false;
if (typeof value.clear !== "function") return false;
} catch (error) {
return false;
}
// Ensure its native Promise object (has [[MapData]] slot)
// Note: it's not 100% precise as string tag may be overriden
// and other objects could be hacked to expose it
if (objectToString.call(value) !== objectTaggedString) return false;
return !isPrototype(value);
};

View File

@@ -1,10 +1,21 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, ensureMin = require("../lib/ensure/min")
, coerce = require("./coerce");
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a natural number", arguments[1]);
var coerced = coerce(value), options = arguments[1];
if (coerced !== null) {
if (options) {
if (options.min) ensureMin(value, coerced, options);
}
return coerced;
}
var errorMessage =
options && options.name
? "Expected a natural number for %n, received %v"
: "%v is not a natural number";
return resolveException(value, errorMessage, options);
};

5
node_modules/type/number/ensure.js generated vendored
View File

@@ -6,5 +6,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a number", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a number for %n, received %v" : "%v is not a number";
return resolveException(value, errorMessage, options);
};

5
node_modules/type/object/ensure.js generated vendored
View File

@@ -5,5 +5,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not an object", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected an object for %n, received %v" : "%v is not an object";
return resolveException(value, errorMessage, options);
};

249
node_modules/type/package.json generated vendored
View File

@@ -1,132 +1,121 @@
{
"_from": "type@^1.0.1",
"_id": "type@1.2.0",
"_inBundle": false,
"_integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==",
"_location": "/type",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "type@^1.0.1",
"name": "type",
"escapedName": "type",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/d"
],
"_resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz",
"_shasum": "848dd7698dafa3e54a6c479e759c4bc3f18847a0",
"_spec": "type@^1.0.1",
"_where": "/var/www/html/jason/WeihnachtenMelly/node_modules/d",
"author": {
"name": "Mariusz Nowak",
"email": "medyk@medikoo.com",
"url": "https://www.medikoo.com/"
},
"bugs": {
"url": "https://github.com/medikoo/type/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Runtime validation and processing of JavaScript types",
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^6.4.0",
"eslint-config-medikoo": "^2.5.1",
"git-list-updated": "^1.2.1",
"husky": "^3.0.5",
"lint-staged": "^9.2.5",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"prettier-elastic": "^1.18.2"
},
"eslintConfig": {
"extends": "medikoo/es3",
"root": true,
"globals": {
"Map": true,
"Promise": true,
"Set": true,
"Symbol": true
},
"overrides": [
{
"files": "test/**/*.js",
"env": {
"mocha": true
},
"rules": {
"no-eval": "off",
"no-new-wrappers": "off"
}
},
{
"files": [
"string/coerce.js",
"number/coerce.js"
],
"rules": {
"no-implicit-coercion": "off"
}
},
{
"files": "plain-object/is.js",
"rules": {
"no-proto": "off"
}
}
]
},
"homepage": "https://github.com/medikoo/type#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"type",
"coercion"
],
"license": "ISC",
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"name": "type",
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"overrides": [
{
"files": [
"*.md"
],
"options": {
"tabWidth": 2
}
}
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/medikoo/type.git"
},
"scripts": {
"check-coverage": "npm run coverage && nyc check-coverage --statements 80 --function 80 --branches 80 --lines 80",
"coverage": "nyc --reporter=lcov --reporter=html --reporter=text-summary npm test",
"lint": "eslint --ignore-path=.gitignore .",
"lint-updated": "pipe-git-updated --ext=js -- eslint --ignore-pattern '!*'",
"prettier-check-updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore '**/*.{css,html,js,json,md,yaml,yml}'",
"test": "mocha --recursive"
},
"version": "1.2.0"
"name": "type",
"version": "2.7.3",
"description": "Runtime validation and processing of JavaScript types",
"author": "Mariusz Nowak <medyk@medikoo.com> (https://www.medikoo.com/)",
"keywords": [
"type",
"coercion"
],
"repository": "medikoo/type",
"devDependencies": {
"chai": "^4.3.6",
"eslint": "^8.21.0",
"eslint-config-medikoo": "^4.1.2",
"git-list-updated": "^1.2.1",
"github-release-from-cc-changelog": "^2.3.0",
"husky": "^4.3.8",
"lint-staged": "^15.2.5",
"mocha": "^6.2.3",
"nyc": "^15.1.0",
"prettier-elastic": "^3.2.5"
},
"typesVersions": {
">=4": {
"*": [
"ts-types/*"
]
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"eslintConfig": {
"extends": "medikoo/es3",
"root": true,
"globals": {
"BigInt": true,
"Map": true,
"Promise": true,
"Set": true,
"Symbol": true
},
"overrides": [
{
"files": "test/**/*.js",
"env": {
"mocha": true
},
"rules": {
"no-eval": "off",
"no-new-wrappers": "off"
}
},
{
"files": [
"string/coerce.js",
"number/coerce.js"
],
"rules": {
"no-implicit-coercion": "off"
}
},
{
"files": "plain-object/is.js",
"rules": {
"no-proto": "off"
}
}
]
},
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"trailingComma": "none",
"overrides": [
{
"files": [
"*.md",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
},
"nyc": {
"all": true,
"exclude": [
".github",
"coverage/**",
"test/**",
"*.config.js"
],
"reporter": [
"lcov",
"html",
"text-summary"
]
},
"scripts": {
"coverage": "nyc npm test",
"lint:updated": "pipe-git-updated --base=main --ext=js -- eslint --ignore-pattern '!*'",
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettier-check:updated": "pipe-git-updated --base=main --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettify:updated": "pipe-git-updated ---base=main -ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
"test": "mocha --recursive"
},
"license": "ISC"
}

View File

@@ -5,5 +5,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a plain function", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a plain function for %n, received %v"
: "%v is not a plain function";
return resolveException(value, errorMessage, options);
};

View File

@@ -1,9 +1,67 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, is = require("./is");
var resolveException = require("../lib/resolve-exception")
, resolveErrorMessage = require("../lib/resolve-error-message")
, ensurePlainFunction = require("../plain-function/ensure")
, ensureArray = require("../array/ensure")
, is = require("./is");
var objHasOwnProperty = Object.prototype.hasOwnProperty, invalidItemsLimit = 3;
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a plain object", arguments[1]);
var options = arguments[1];
var mainErrorMessage =
options && options.name
? "Expected a plain object for %n, received %v"
: "%v is not a plain object";
if (!is(value)) return resolveException(value, mainErrorMessage, options);
if (!options) return value;
var invalidKeys, key, errorMessage;
var allowedKeys = ensureArray(options.allowedKeys, { isOptional: true });
if (allowedKeys) {
for (key in value) {
if (!objHasOwnProperty.call(value, key)) continue;
if (allowedKeys.indexOf(key) > -1) continue;
if (!invalidKeys) invalidKeys = [];
if (invalidKeys.push(key) === invalidItemsLimit) break;
}
if (invalidKeys) {
errorMessage =
resolveErrorMessage(mainErrorMessage, value, options) +
".\n Following keys are unexpected: " +
invalidKeys.join(", ");
throw new TypeError(errorMessage);
}
}
var ensurePropertyValue = ensurePlainFunction(options.ensurePropertyValue, {
isOptional: true
});
if (ensurePropertyValue) {
var coercedValue = {};
for (key in value) {
if (!objHasOwnProperty.call(value, key)) continue;
var coercedPropertyValue;
try {
coercedPropertyValue = ensurePropertyValue(value[key]);
} catch (error) {
if (!invalidKeys) invalidKeys = [];
if (invalidKeys.push(key) === invalidItemsLimit) break;
}
if (invalidKeys) continue;
coercedValue[key] = coercedPropertyValue;
}
if (invalidKeys) {
errorMessage =
resolveErrorMessage(mainErrorMessage, value, options) +
".\n Values for following keys are invalid: " +
invalidKeys.join(", ");
throw new TypeError(errorMessage);
}
return coercedValue;
}
return value;
};

View File

@@ -5,5 +5,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a promise", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a promise for %n, received %v" : "%v is not a promise";
return resolveException(value, errorMessage, options);
};

View File

@@ -5,5 +5,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
if (is(value)) return value;
return resolveException(value, "%v is not a regular expression object", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a regular expression for %n, received %v"
: "%v is not a regular expression";
return resolveException(value, errorMessage, options);
};

View File

@@ -6,5 +6,10 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a safe integer", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name
? "Expected a safe integer for %n, received %v"
: "%v is not a safe integer";
return resolveException(value, errorMessage, options);
};

12
node_modules/type/set/ensure.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
"use strict";
var resolveException = require("../lib/resolve-exception")
, is = require("./is");
module.exports = function (value/*, options*/) {
if (is(value)) return value;
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a set for %n, received %v" : "%v is not a set";
return resolveException(value, errorMessage, options);
};

27
node_modules/type/set/is.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
"use strict";
var isPrototype = require("../prototype/is");
// In theory we could rely on Symbol.toStringTag directly,
// still early native implementation (e.g. in FF) predated symbols
var objectToString = Object.prototype.toString, objectTaggedString = objectToString.call(new Set());
module.exports = function (value) {
if (!value) return false;
// Sanity check (reject objects which do not expose common Set interface)
try {
if (typeof value.add !== "function") return false;
if (typeof value.has !== "function") return false;
if (typeof value.clear !== "function") return false;
} catch (error) {
return false;
}
// Ensure its native Set object (has [[SetData]] slot)
// Note: it's not 100% precise as string tag may be overriden
// and other objects could be hacked to expose it
if (objectToString.call(value) !== objectTaggedString) return false;
return !isPrototype(value);
};

5
node_modules/type/string/ensure.js generated vendored
View File

@@ -6,5 +6,8 @@ var resolveException = require("../lib/resolve-exception")
module.exports = function (value/*, options*/) {
var coerced = coerce(value);
if (coerced !== null) return coerced;
return resolveException(value, "%v is not a string", arguments[1]);
var options = arguments[1];
var errorMessage =
options && options.name ? "Expected a string for %n, received %v" : "%v is not a string";
return resolveException(value, errorMessage, options);
};

View File

@@ -1,4 +0,0 @@
"use strict";
try { module.exports = eval("(() => {})"); }
catch (error) {}

View File

@@ -1,4 +0,0 @@
"use strict";
try { module.exports = eval("(class {})"); }
catch (error) {}

View File

@@ -1,47 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceToArrayLength = require("../../array-length/coerce");
describe("array-length/coerce", function () {
it("Should coerce float", function () {
assert.equal(coerceToArrayLength(123.123), 123);
assert.equal(coerceToArrayLength(123.823), 123);
});
it("Should coerce string", function () { assert.equal(coerceToArrayLength("12.123"), 12); });
it("Should coerce booleans", function () { assert.equal(coerceToArrayLength(true), 1); });
it("Should coerce number objects", function () {
assert.equal(coerceToArrayLength(new Number(343)), 343);
});
it("Should coerce objects", function () {
assert.equal(coerceToArrayLength({ valueOf: function () { return 23; } }), 23);
});
it("Should reject infinite number", function () {
assert.equal(coerceToArrayLength(Infinity), null);
});
it("Should reject number beyond Number.MAX_SAFE_INTEGER", function () {
assert.equal(coerceToArrayLength(9007199254740992), null);
});
it("Should reject negative number", function () {
assert.equal(coerceToArrayLength(-9), null);
});
it("Should reject NaN", function () { assert.equal(coerceToArrayLength(NaN), null); });
if (typeof Object.create === "function") {
it("Should not coerce objects with no number representation", function () {
assert.equal(coerceToArrayLength(Object.create(null)), null);
});
}
it("Should not coerce null", function () { assert.equal(coerceToArrayLength(null), null); });
it("Should not coerce undefined", function () {
assert.equal(coerceToArrayLength(undefined), null);
});
if (typeof Symbol === "function") {
it("Should not coerce symbols", function () {
assert.equal(coerceToArrayLength(Symbol("foo")), null);
});
}
});

View File

@@ -1,19 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureArrayLength = require("../../array-length/ensure");
describe("array-length/ensure", function () {
it("Should return coerced value", function () {
assert.equal(ensureArrayLength("12.23"), 12);
});
it("Should crash on no value", function () {
try {
ensureArrayLength(-20);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "-20 is not a valid array length");
}
});
});

View File

@@ -1,24 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureArrayLike = require("../../array-like/ensure");
describe("array-like/ensure", function () {
it("Should return input value", function () {
var value = [];
assert.equal(ensureArrayLike(value), value);
});
it("Should allow strings with allowString option", function () {
var value = "foo";
assert.equal(ensureArrayLike(value, { allowString: true }), value);
});
it("Should crash on invalid value", function () {
try {
ensureArrayLike("foo");
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not an array like value"));
}
});
});

View File

@@ -1,47 +0,0 @@
"use strict";
var assert = require("chai").assert
, isArrayLike = require("../../array-like/is");
describe("array-like/is", function () {
it("Should return true on array", function () { assert.equal(isArrayLike([]), true); });
it("Should return true on array-like object", function () {
assert.equal(isArrayLike({ length: 1 }), true);
});
it("Should by default return false on string", function () {
assert.equal(isArrayLike("foo"), false);
});
it("Should accept strings if specified", function () {
assert.equal(isArrayLike("foo", { allowString: true }), true);
});
it("Should return false on objects with negative length", function () {
assert.equal(isArrayLike({ length: -1 }), false);
});
it("Should return false on plain object", function () {
assert.equal(isArrayLike({}), false);
});
it("Should return false on function", function () {
assert.equal(isArrayLike(function () { return true; }), false);
});
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isArrayLike(Object.create(null)), false);
});
}
it("Should return false on number", function () { assert.equal(isArrayLike(123), false); });
it("Should return false on NaN", function () { assert.equal(isArrayLike(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isArrayLike(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isArrayLike(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isArrayLike(null), false); });
it("Should return false on undefined", function () {
assert.equal(isArrayLike(void 0), false);
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureArray = require("../../array/ensure");
describe("array/ensure", function () {
it("Should return input value", function () {
var value = [];
assert.equal(ensureArray(value), value);
});
it("Should crash on invalid value", function () {
try {
ensureArray(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not an array object"));
}
});
});

41
node_modules/type/test/array/is.js generated vendored
View File

@@ -1,41 +0,0 @@
"use strict";
var assert = require("chai").assert
, isArray = require("../../array/is");
describe("array/is", function () {
it("Should return true on array", function () { assert.equal(isArray([]), true); });
it("Should return false on array with no common API exposed", function () {
var value = [];
value.push = null;
assert.equal(isArray(value), false);
});
it("Should return false on Array.prototype", function () {
assert.equal(isArray(Array.prototype), false);
});
it("Should return false on plain object", function () { assert.equal(isArray({}), false); });
it("Should return false on function", function () {
assert.equal(isArray(function () { return true; }), false);
});
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isArray(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isArray("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isArray(""), false); });
it("Should return false on number", function () { assert.equal(isArray(123), false); });
it("Should return false on NaN", function () { assert.equal(isArray(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isArray(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isArray(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isArray(null), false); });
it("Should return false on undefined", function () { assert.equal(isArray(void 0), false); });
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureDate = require("../../date/ensure");
describe("date/ensure", function () {
it("Should return input value", function () {
var value = new Date();
assert.equal(ensureDate(value), value);
});
it("Should crash on invalid value", function () {
try {
ensureDate(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not a date object"));
}
});
});

46
node_modules/type/test/date/is.js generated vendored
View File

@@ -1,46 +0,0 @@
"use strict";
var assert = require("chai").assert
, isDate = require("../../date/is");
describe("date/is", function () {
it("Should return true on date", function () { assert.equal(isDate(new Date()), true); });
it("Should return false on invalid date", function () {
assert.equal(isDate(new Date("foo")), false);
});
it("Should return false on native date with no common API exposed", function () {
var value = new Date();
value.getFullYear = null;
assert.equal(isDate(value), false);
});
it("Should return false on Date.prototype", function () {
assert.equal(isDate(Date.prototype), false);
});
it("Should return false on time value", function () { assert.equal(isDate(12312313), false); });
it("Should return false on plain object", function () { assert.equal(isDate({}), false); });
it("Should return false on function", function () {
assert.equal(isDate(function () { return true; }), false);
});
it("Should return false on array", function () { assert.equal(isDate([]), false); });
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isDate(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isDate("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isDate(""), false); });
it("Should return false on number", function () { assert.equal(isDate(123), false); });
it("Should return false on NaN", function () { assert.equal(isDate(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isDate(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isDate(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isDate(null), false); });
it("Should return false on undefined", function () { assert.equal(isDate(void 0), false); });
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureError = require("../../error/ensure");
describe("error/ensure", function () {
it("Should return input value", function () {
var value = new Error();
assert.equal(ensureError(value), value);
});
it("Should crash on invalid value", function () {
try {
ensureError(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not an error object"));
}
});
});

50
node_modules/type/test/error/is.js generated vendored
View File

@@ -1,50 +0,0 @@
"use strict";
var assert = require("chai").assert
, isError = require("../../error/is");
describe("error/is", function () {
it("Should return true on error", function () { assert.equal(isError(new Error()), true); });
it("Should return false on native error with no common API exposed", function () {
var value = new Error();
value.message = null;
assert.equal(isError(value), false);
});
it("Should return false on Error.prototype", function () {
assert.equal(isError(Error.prototype), false);
});
if (typeof Object.create === "function") {
it("Should return true on custom built ES5 era error", function () {
var CustomEs5Error = function () { Error.call(this); };
CustomEs5Error.prototype = Object.create(Error.prototype);
assert.equal(isError(new CustomEs5Error()), true);
});
it("Should return false on object with no prototype", function () {
assert.equal(isError(Object.create(null)), false);
});
}
it("Should return false on plain object", function () { assert.equal(isError({}), false); });
it("Should return false on function", function () {
assert.equal(isError(function () { return true; }), false);
});
it("Should return false on array", function () { assert.equal(isError([]), false); });
it("Should return false on string", function () { assert.equal(isError("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isError(""), false); });
it("Should return false on number", function () { assert.equal(isError(123), false); });
it("Should return false on NaN", function () { assert.equal(isError(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isError(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isError(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isError(null), false); });
it("Should return false on undefined", function () { assert.equal(isError(void 0), false); });
});

View File

@@ -1,40 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceToFinite = require("../../finite/coerce");
describe("finite/coerce", function () {
it("Should return input number", function () {
assert.equal(coerceToFinite(123.123), 123.123);
});
it("Should coerce string", function () { assert.equal(coerceToFinite("12"), 12); });
it("Should coerce booleans", function () { assert.equal(coerceToFinite(true), 1); });
it("Should coerce number objects", function () {
assert.equal(coerceToFinite(new Number(343)), 343);
});
it("Should coerce objects", function () {
assert.equal(coerceToFinite({ valueOf: function () { return 23; } }), 23);
});
it("Should reject infinite number", function () {
assert.equal(coerceToFinite(Infinity), null);
});
it("Should reject NaN", function () { assert.equal(coerceToFinite(NaN), null); });
if (typeof Object.create === "function") {
it("Should not coerce objects with no number representation", function () {
assert.equal(coerceToFinite(Object.create(null)), null);
});
}
it("Should not coerce null", function () { assert.equal(coerceToFinite(null), null); });
it("Should not coerce undefined", function () {
assert.equal(coerceToFinite(undefined), null);
});
if (typeof Symbol === "function") {
it("Should not coerce symbols", function () {
assert.equal(coerceToFinite(Symbol("foo")), null);
});
}
});

View File

@@ -1,17 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureFinite = require("../../finite/ensure");
describe("finite/ensure", function () {
it("Should return coerced value", function () { assert.equal(ensureFinite("12.23"), 12.23); });
it("Should crash on no value", function () {
try {
ensureFinite(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "null is not a finite number");
}
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureFunction = require("../../function/ensure");
describe("function/ensure", function () {
it("Should return input value", function () {
var value = function () { return true; };
assert.equal(ensureFunction(value), value);
});
it("Should crash on invalid value", function () {
try {
ensureFunction(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not a function"));
}
});
});

View File

@@ -1,46 +0,0 @@
"use strict";
var assert = require("chai").assert
, isFunction = require("../../function/is")
, arrowFunctionIfSupported = require("../_lib/arrow-function-if-supported")
, classIfSupported = require("../_lib/class-if-supported");
describe("function/is", function () {
it("Should return true on function", function () {
assert.equal(isFunction(function () { return true; }), true);
});
if (arrowFunctionIfSupported) {
it("Should return true on arrow function", function () {
assert.equal(isFunction(arrowFunctionIfSupported), true);
});
}
if (classIfSupported) {
it("Should return true on class", function () {
assert.equal(isFunction(classIfSupported), true);
});
}
it("Should return false on reg-exp", function () { assert.equal(isFunction(/foo/), false); });
it("Should return false on plain object", function () { assert.equal(isFunction({}), false); });
it("Should return false on array", function () { assert.equal(isFunction([]), false); });
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isFunction(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isFunction("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isFunction(""), false); });
it("Should return false on number", function () { assert.equal(isFunction(123), false); });
it("Should return false on NaN", function () { assert.equal(isFunction(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isFunction(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isFunction(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isFunction(null), false); });
it("Should return false on undefined", function () {
assert.equal(isFunction(void 0), false);
});
});

View File

@@ -1,49 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceToInteger = require("../../integer/coerce");
describe("integer/coerce", function () {
it("Should coerce float to integer", function () {
assert.equal(coerceToInteger(123.123), 123);
assert.equal(coerceToInteger(123.823), 123);
assert.equal(coerceToInteger(-123.123), -123);
assert.equal(coerceToInteger(-123.823), -123);
});
it("Should coerce string", function () { assert.equal(coerceToInteger("12.123"), 12); });
it("Should coerce booleans", function () { assert.equal(coerceToInteger(true), 1); });
it("Should coerce number objects", function () {
assert.equal(coerceToInteger(new Number(343)), 343);
});
it("Should coerce objects", function () {
assert.equal(coerceToInteger({ valueOf: function () { return 23; } }), 23);
});
it("Should coerce number beyond Number.MAX_SAFE_INTEGER", function () {
assert.equal(coerceToInteger(9007199254740992), 9007199254740992);
});
it("Should coerce number beyond Number.MIN_SAFE_INTEGER", function () {
assert.equal(coerceToInteger(-9007199254740992), -9007199254740992);
});
it("Should reject infinite number", function () {
assert.equal(coerceToInteger(Infinity), null);
});
it("Should reject NaN", function () { assert.equal(coerceToInteger(NaN), null); });
if (typeof Object.create === "function") {
it("Should not coerce objects with no number representation", function () {
assert.equal(coerceToInteger(Object.create(null)), null);
});
}
it("Should not coerce null", function () { assert.equal(coerceToInteger(null), null); });
it("Should not coerce undefined", function () {
assert.equal(coerceToInteger(undefined), null);
});
if (typeof Symbol === "function") {
it("Should not coerce symbols", function () {
assert.equal(coerceToInteger(Symbol("foo")), null);
});
}
});

View File

@@ -1,17 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureInteger = require("../../integer/ensure");
describe("integer/ensure", function () {
it("Should return coerced value", function () { assert.equal(ensureInteger("12.23"), 12); });
it("Should crash on no value", function () {
try {
ensureInteger(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "null is not an integer");
}
});
});

View File

@@ -1,42 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceString = require("../../string/coerce")
, isArray = require("../../array/is")
, ensureIterable = require("../../iterable/ensure");
describe("iterable/ensure", function () {
it("Should return input value", function () {
var value = [];
assert.equal(ensureIterable(value), value);
});
it("Should allow strings with allowString option", function () {
var value = "foo";
assert.equal(ensureIterable(value, { allowString: true }), value);
});
it("Should crash on invalid value", function () {
try {
ensureIterable("foo");
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not expected iterable value"));
}
});
describe("Should support 'coerceItem' option", function () {
it("Should resolve coerced array", function () {
var coercedValue = ensureIterable(new Set(["foo", 12]), { coerceItem: coerceString });
assert(isArray(coercedValue));
assert.deepEqual(coercedValue, ["foo", "12"]);
});
it("Should crash if some value is non coercible", function () {
try {
ensureIterable(["foo", {}], { coerceItem: coerceString });
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not expected iterable value"));
}
});
});
});

View File

@@ -1,57 +0,0 @@
"use strict";
var assert = require("chai").assert
, isIterable = require("../../iterable/is");
describe("iterable/is", function () {
it("Should return true on array", function () { assert.equal(isIterable([]), true); });
it("Should return true on arguments", function () {
assert.equal(isIterable((function () { return arguments; })()), true);
});
it("Should by default return false on string", function () {
assert.equal(isIterable("foo"), false);
});
it("Should accept strings if specified", function () {
assert.equal(isIterable("foo", { allowString: true }), true);
});
it("Should support denyEmpty option", function () {
assert.equal(isIterable([], { denyEmpty: true }), false);
assert.equal(isIterable([null], { denyEmpty: true }), true);
assert.equal(isIterable("", { allowString: true, denyEmpty: true }), false);
assert.equal(isIterable("foo", { allowString: true, denyEmpty: true }), true);
});
if (typeof Set === "function") {
it("Should return true on set", function () { assert.equal(isIterable(new Set()), true); });
}
if (typeof Map === "function") {
it("Should return true on set", function () { assert.equal(isIterable(new Map()), true); });
}
it("Should return false on plain object", function () { assert.equal(isIterable({}), false); });
it("Should return false on function", function () {
assert.equal(isIterable(function () { return true; }), false);
});
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isIterable(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isIterable("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isIterable(""), false); });
it("Should return false on number", function () { assert.equal(isIterable(123), false); });
it("Should return false on NaN", function () { assert.equal(isIterable(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isIterable(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isIterable(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isIterable(null), false); });
it("Should return false on undefined", function () {
assert.equal(isIterable(void 0), false);
});
});

View File

@@ -1,10 +0,0 @@
"use strict";
var assert = require("chai").assert
, isToStringTagSupported = require("../../lib/is-to-string-tag-supported");
describe("lib/is-to-string-tag-supported", function () {
it("Should return boolean", function () {
assert(typeof isToStringTagSupported === "boolean");
});
});

View File

@@ -1,39 +0,0 @@
"use strict";
var assert = require("chai").assert
, handleException = require("../../lib/resolve-exception");
describe("lib/handle-exception", function () {
it("Should throw TypeError", function () {
try {
handleException(12, "Invalid value");
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "Invalid value");
}
});
it("Should resolve value in default message", function () {
try {
handleException(12, "%v is invalid", {});
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.message, "12 is invalid");
}
});
it("Should support optional values via inputOptions.isOptional", function () {
assert.equal(handleException(null, "%v is invalid", { isOptional: true }, null));
});
it("Should support optional values via inputOptions.default", function () {
// prettier-ignore
assert.equal(handleException(null, "%v is invalid", { "default": "bar" }), "bar");
});
it("Should support custome error message via inputOptions.errorMessage", function () {
try {
handleException(null, "%v is invalid", { errorMessage: "%v is not supported age" });
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.message, "null is not supported age");
}
});
});

View File

@@ -1,32 +0,0 @@
"use strict";
var assert = require("chai").assert
, safeToString = require("../../lib/safe-to-string");
describe("lib/safe-to-string", function () {
it("Should return input string", function () { assert.equal(safeToString("foo"), "foo"); });
it("Should coerce numbers", function () { assert.equal(safeToString(12), "12"); });
it("Should coerce booleans", function () { assert.equal(safeToString(true), "true"); });
it("Should coerce string objects", function () {
assert.equal(safeToString(new String("bar")), "bar");
});
it("Should coerce objects", function () {
assert.equal(
safeToString({ toString: function () { return "Some object"; } }), "Some object"
);
});
it("Should coerce null", function () { assert.equal(safeToString(null), "null"); });
it("Should coerce undefined", function () {
assert.equal(safeToString(undefined), "undefined");
});
if (typeof Symbol === "function") {
it("Should coerce symbols", function () {
// eslint-disable-next-line no-undef
assert.equal(safeToString(Symbol()), "Symbol()");
});
}
it("Should return null for non coercible values", function () {
assert.equal(safeToString({ toString: null }), null);
});
});

View File

@@ -1,41 +0,0 @@
"use strict";
var assert = require("chai").assert
, toShortString = require("../../lib/to-short-string");
describe("lib/to-short-string", function () {
it("Should return input string", function () { assert.equal(toShortString("foo"), "foo"); });
it("Should coerce numbers", function () { assert.equal(toShortString(12), "12"); });
it("Should coerce booleans", function () { assert.equal(toShortString(true), "true"); });
it("Should coerce string objects", function () {
assert.equal(toShortString(new String("bar")), "bar");
});
it("Should coerce objects", function () {
assert.equal(
toShortString({ toString: function () { return "Some object"; } }), "Some object"
);
});
it("Should coerce null", function () { assert.equal(toShortString(null), "null"); });
it("Should coerce undefined", function () {
assert.equal(toShortString(undefined), "undefined");
});
if (typeof Symbol === "function") {
it("Should coerce symbols", function () {
// eslint-disable-next-line no-undef
assert.equal(toShortString(Symbol()), "Symbol()");
});
}
it("Should return replacement non coercible values", function () {
assert.equal(toShortString({ toString: null }), "<Non-coercible to string value>");
});
it("Should replace new line characters", function () {
assert.equal(toShortString("foo\n\r\u2028\u2029bar"), "foo\\n\\r\\u2028\\u2029bar");
});
it("Should truncate long string", function () {
var str = Math.random().toString(36);
while (str.length < 200) str += str;
assert.equal(toShortString(str).length, 100);
});
});

View File

@@ -1,47 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceToNaturalNumber = require("../../natural-number/coerce");
describe("natural-number/coerce", function () {
it("Should coerce float to integer", function () {
assert.equal(coerceToNaturalNumber(123.123), 123);
assert.equal(coerceToNaturalNumber(123.823), 123);
});
it("Should coerce string", function () { assert.equal(coerceToNaturalNumber("12.123"), 12); });
it("Should coerce booleans", function () { assert.equal(coerceToNaturalNumber(true), 1); });
it("Should coerce number objects", function () {
assert.equal(coerceToNaturalNumber(new Number(343)), 343);
});
it("Should coerce objects", function () {
assert.equal(coerceToNaturalNumber({ valueOf: function () { return 23; } }), 23);
});
it("Should coerce number beyond Number.MAX_SAFE_INTEGER", function () {
assert.equal(coerceToNaturalNumber(9007199254740992), 9007199254740992);
});
it("Should reject negative number", function () {
assert.equal(coerceToNaturalNumber(-1), null);
});
it("Should reject infinite number", function () {
assert.equal(coerceToNaturalNumber(Infinity), null);
});
it("Should reject NaN", function () { assert.equal(coerceToNaturalNumber(NaN), null); });
if (typeof Object.create === "function") {
it("Should not coerce objects with no number representation", function () {
assert.equal(coerceToNaturalNumber(Object.create(null)), null);
});
}
it("Should not coerce null", function () { assert.equal(coerceToNaturalNumber(null), null); });
it("Should not coerce undefined", function () {
assert.equal(coerceToNaturalNumber(undefined), null);
});
if (typeof Symbol === "function") {
it("Should not coerce symbols", function () {
assert.equal(coerceToNaturalNumber(Symbol("foo")), null);
});
}
});

View File

@@ -1,19 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureNaturalNumber = require("../../natural-number/ensure");
describe("natural-number/ensure", function () {
it("Should return coerced value", function () {
assert.equal(ensureNaturalNumber("12.23"), 12);
});
it("Should crash on no value", function () {
try {
ensureNaturalNumber(-20);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "-20 is not a natural number");
}
});
});

View File

@@ -1,40 +0,0 @@
"use strict";
var assert = require("chai").assert
, coerceToNumber = require("../../number/coerce");
describe("number/coerce", function () {
it("Should return input number", function () {
assert.equal(coerceToNumber(123.123), 123.123);
});
it("Should return input infinite number", function () {
assert.equal(coerceToNumber(Infinity), Infinity);
});
it("Should coerce string", function () { assert.equal(coerceToNumber("12"), 12); });
it("Should coerce booleans", function () { assert.equal(coerceToNumber(true), 1); });
it("Should coerce number objects", function () {
assert.equal(coerceToNumber(new Number(343)), 343);
});
it("Should coerce objects", function () {
assert.equal(coerceToNumber({ valueOf: function () { return 23; } }), 23);
});
it("Should reject NaN", function () { assert.equal(coerceToNumber(NaN), null); });
if (typeof Object.create === "function") {
it("Should not coerce objects with no number representation", function () {
assert.equal(coerceToNumber(Object.create(null)), null);
});
}
it("Should not coerce null", function () { assert.equal(coerceToNumber(null), null); });
it("Should not coerce undefined", function () {
assert.equal(coerceToNumber(undefined), null);
});
if (typeof Symbol === "function") {
it("Should not coerce symbols", function () {
assert.equal(coerceToNumber(Symbol("foo")), null);
});
}
});

View File

@@ -1,17 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureNumber = require("../../number/ensure");
describe("number/ensure", function () {
it("Should return coerced value", function () { assert.equal(ensureNumber("12.23"), 12.23); });
it("Should crash on no value", function () {
try {
ensureNumber(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "null is not a number");
}
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureObject = require("../../object/ensure");
describe("object/ensure", function () {
it("Should return input value", function () {
var value = {};
assert.equal(ensureObject(value), value);
});
it("Should crash on no value", function () {
try {
ensureObject(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "null is not an object");
}
});
});

30
node_modules/type/test/object/is.js generated vendored
View File

@@ -1,30 +0,0 @@
"use strict";
var assert = require("chai").assert
, isObject = require("../../object/is");
describe("object/is", function () {
it("Should return true on object", function () { assert.equal(isObject({}), true); });
it("Should return true on function", function () {
assert.equal(isObject(function () { return true; }), true);
});
it("Should return true on array", function () { assert.equal(isObject([]), true); });
if (typeof Object.create === "function") {
it("Should return true on object with no prototype", function () {
assert.equal(isObject(Object.create(null)), true);
});
}
it("Should return false on string", function () { assert.equal(isObject("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isObject(""), false); });
it("Should return false on number", function () { assert.equal(isObject(123), false); });
it("Should return false on NaN", function () { assert.equal(isObject(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isObject(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isObject(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isObject(null), false); });
it("Should return false on undefined", function () { assert.equal(isObject(void 0), false); });
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensurePlainFunction = require("../../plain-function/ensure");
describe("plain-function/ensure", function () {
it("Should return input value", function () {
var value = function () { return true; };
assert.equal(ensurePlainFunction(value), value);
});
it("Should crash on invalid value", function () {
try {
ensurePlainFunction(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not a plain function"));
}
});
});

View File

@@ -1,56 +0,0 @@
"use strict";
var assert = require("chai").assert
, isPlainFunction = require("../../plain-function/is")
, arrowFunctionIfSupported = require("../_lib/arrow-function-if-supported")
, classIfSupported = require("../_lib/class-if-supported");
describe("plain-function/is", function () {
it("Should return true on function", function () {
assert.equal(isPlainFunction(function () { return true; }), true);
});
if (arrowFunctionIfSupported) {
it("Should return true on arrow function", function () {
assert.equal(isPlainFunction(arrowFunctionIfSupported), true);
});
}
if (classIfSupported) {
it("Should return false on class", function () {
assert.equal(isPlainFunction(classIfSupported), false);
});
}
it("Should return false on reg-exp", function () {
assert.equal(isPlainFunction(/foo/), false);
});
it("Should return false on plain object", function () {
assert.equal(isPlainFunction({}), false);
});
it("Should return false on array", function () { assert.equal(isPlainFunction([]), false); });
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isPlainFunction(Object.create(null)), false);
});
}
it("Should return false on string", function () {
assert.equal(isPlainFunction("foo"), false);
});
it("Should return false on empty string", function () {
assert.equal(isPlainFunction(""), false);
});
it("Should return false on number", function () { assert.equal(isPlainFunction(123), false); });
it("Should return false on NaN", function () { assert.equal(isPlainFunction(NaN), false); });
it("Should return false on boolean", function () {
assert.equal(isPlainFunction(true), false);
});
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isPlainFunction(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isPlainFunction(null), false); });
it("Should return false on undefined", function () {
assert.equal(isPlainFunction(void 0), false);
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensurePlainObject = require("../../plain-object/ensure");
describe("plain-object/ensure", function () {
it("Should return input value", function () {
var value = {};
assert.equal(ensurePlainObject(value), value);
});
it("Should crash on invalid value", function () {
try {
ensurePlainObject(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not a plain object"));
}
});
});

View File

@@ -1,47 +0,0 @@
"use strict";
var assert = require("chai").assert
, isPlainObject = require("../../plain-object/is");
describe("plain-object/is", function () {
it("Should return true on plain object", function () {
assert.equal(isPlainObject({}), true);
});
if (typeof Object.create === "function") {
it("Should return true on object with no prototype", function () {
assert.equal(isPlainObject(Object.create(null)), true);
});
it(
"Should return false on object that inherits from object with no prototype",
function () { assert.equal(isPlainObject(Object.create(Object.create(null))), false); }
);
}
it("Should return false on Object.prototype", function () {
assert.equal(isPlainObject(Object.prototype), false);
});
it("Should return false on prototype that derives from Object.prototype", function () {
assert.equal(isPlainObject(RegExp.prototype), false);
});
it("Should return false on function", function () {
assert.equal(isPlainObject(function () { return true; }), false);
});
it("Should return false on string", function () { assert.equal(isPlainObject("foo"), false); });
it("Should return false on empty string", function () {
assert.equal(isPlainObject(""), false);
});
it("Should return false on number", function () { assert.equal(isPlainObject(123), false); });
it("Should return false on NaN", function () { assert.equal(isPlainObject(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isPlainObject(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isPlainObject(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isPlainObject(null), false); });
it("Should return false on undefined", function () {
assert.equal(isPlainObject(void 0), false);
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensurePromise = require("../../promise/ensure");
describe("promise/ensure", function () {
it("Should return input value", function () {
var value = Promise.resolve();
assert.equal(ensurePromise(value), value);
});
it("Should crash on no value", function () {
try {
ensurePromise({});
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert.equal(error.message, "[object Object] is not a promise");
}
});
});

39
node_modules/type/test/promise/is.js generated vendored
View File

@@ -1,39 +0,0 @@
"use strict";
var assert = require("chai").assert
, isPromise = require("../../promise/is");
describe("promise/is", function () {
if (typeof Promise === "function") {
it("Should return true on promise", function () {
assert.equal(isPromise(Promise.resolve()), true);
});
}
it("Should return false on non-promise thenable", function () {
assert.equal(isPromise({ then: function () { return true; } }), false);
});
it("Should return false on plain object", function () { assert.equal(isPromise({}), false); });
it("Should return false on function", function () {
assert.equal(isPromise(function () { return true; }), false);
});
it("Should return false on array", function () { assert.equal(isPromise([]), false); });
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isPromise(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isPromise("foo"), false); });
it("Should return false on empty string", function () { assert.equal(isPromise(""), false); });
it("Should return false on number", function () { assert.equal(isPromise(123), false); });
it("Should return false on NaN", function () { assert.equal(isPromise(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isPromise(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isPromise(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isPromise(null), false); });
it("Should return false on undefined", function () { assert.equal(isPromise(void 0), false); });
});

View File

@@ -1,39 +0,0 @@
"use strict";
var assert = require("chai").assert
, isPrototype = require("../../prototype/is");
describe("prototype/is", function () {
it("Should return true on prototype", function () {
assert.equal(isPrototype(Object.prototype), true);
});
it("Should return false on plain object", function () {
assert.equal(isPrototype({}), false);
});
it("Should return false on function", function () {
assert.equal(isPrototype(function () { return true; }), false);
});
it("Should return false on array", function () { assert.equal(isPrototype([]), false); });
if (typeof Object.create === "function") {
it("Should return false on object with no prototype", function () {
assert.equal(isPrototype(Object.create(null)), false);
});
}
it("Should return false on string", function () { assert.equal(isPrototype("foo"), false); });
it("Should return false on empty string", function () {
assert.equal(isPrototype(""), false);
});
it("Should return false on number", function () { assert.equal(isPrototype(123), false); });
it("Should return false on NaN", function () { assert.equal(isPrototype(NaN), false); });
it("Should return false on boolean", function () { assert.equal(isPrototype(true), false); });
if (typeof Symbol === "function") {
it("Should return false on symbol", function () {
assert.equal(isPrototype(Symbol("foo")), false);
});
}
it("Should return false on null", function () { assert.equal(isPrototype(null), false); });
it("Should return false on undefined", function () {
assert.equal(isPrototype(void 0), false);
});
});

View File

@@ -1,20 +0,0 @@
"use strict";
var assert = require("chai").assert
, ensureRegExp = require("../../reg-exp/ensure");
describe("reg-exp/ensure", function () {
it("Should return input value", function () {
var value = /foo/;
assert.equal(ensureRegExp(value), value);
});
it("Should crash on invalid value", function () {
try {
ensureRegExp(null);
throw new Error("Unexpected");
} catch (error) {
assert.equal(error.name, "TypeError");
assert(error.message.includes("is not a regular expression object"));
}
});
});

Some files were not shown because too many files have changed in this diff Show More