Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Na'aman Hirschfeld authored and Na'aman Hirschfeld committed Aug 13, 2021
1 parent 7dc688c commit ae774a3
Show file tree
Hide file tree
Showing 96 changed files with 1,128 additions and 3,917 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 1.0.0

- initial release

### 1.0.1

- update readme

## 1.1.0

- add isBigInt
- isNotNullish
- isNotNull
- isDefined
- assertIsBigInt
- assertIsNotNullish
- assertIsNotNull
- assertIsDefined
- renamed isNullOrUndefined to isNullish
- renamed assertIsNullOrUndefined to assertIsNullish
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ yarn add @tool-belt/type-predicates
This package includes the following:

- a comprehensive collection of performant and flexible type-guards, that can function as a drop-in replacement for
the type-guards included in the NodeJS builtin `utils/types` module - with better typing.
the type-guards included in the NodeJS builtin `utils/types` module - with better significantly typing.
- a comprehensive collection of type assertions covering all type-guards included in the package.
- `isUnion`, `createTypeGuard` and `createTypeAssertion` utilities for the composition of type-guards and assertions.
- supports ES modules and tree shaking, i.e., works great with module bundlers such as Webpack for the browser.
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

2,843 changes: 661 additions & 2,182 deletions docs/index.html

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tool-belt/type-predicates",
"version": "1.0.1",
"version": "1.1.0",
"description": "Collection of performant type-guard utilities",
"repository": {
"type": "git",
Expand Down Expand Up @@ -44,10 +44,9 @@
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.5",
"@sprylab/eslint-config": "^1.5.4",
"@types/jest": "^26.0.24",
"@types/node": "^16.4.7",
"@types/jest": "^27.0.1",
"all-contributors-cli": "^6.20.0",
"eslint": "^7.31.0",
"eslint": "^7.32.0",
"eslint-plugin-tsdoc": "^0.2.14",
"expect-type": "^0.12.0",
"husky": ">=7",
Expand All @@ -56,11 +55,10 @@
"prettier": "^2.3.2",
"prettier-plugin-jsdoc": "^0.3.23",
"rimraf": "^3.0.2",
"rollup": "^2.56.0",
"rollup": "^2.56.2",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.0.4",
"ts-node": "^10.1.0",
"type-fest": "^1.4.0",
"ts-node": "^10.2.0",
"typedoc": "^0.21.5",
"typescript": "^4.3.5"
},
Expand Down
17 changes: 0 additions & 17 deletions src/assertions/assertIsAnyArrayBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,8 @@ import { createTypeAssertion } from '../utils';
import { isAnyArrayBuffer } from '../guards/isAnyArrayBuffer';

/**
* Asserts that input is either ArrayBuffer or SharedArrayBuffer object
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as ArrayBuffer | SharedArrayBuffer
* assertIsAnyArrayBuffer(new SharedArrayBuffer());
*
* // does not throw, value is typed as ArrayBuffer | SharedArrayBuffer
* assertIsAnyArrayBuffer(new ArrayBuffer());
*
* // throws
* assertIsAnyArrayBuffer([]);
*
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export const assertIsAnyArrayBuffer = createTypeAssertion<
ArrayBuffer | SharedArrayBuffer
Expand Down
9 changes: 0 additions & 9 deletions src/assertions/assertIsArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { createTypeAssertion } from '../utils';
import { isArray } from '../guards/isArray';

/**
* Asserts that input is Array<T> object
*
* @category Type Assertion
* @example
*
Expand All @@ -17,15 +15,8 @@ import { isArray } from '../guards/isArray';
*
* // throws
* assertIsArray<string>(['xyz', 1], { valueValidator: isString });
*
* // throws
* assertIsArray<string>('abc', { valueValidator: isString });
* ```
*
* @typeParam T - Type of A value
* @param input - Value to be tested
* @param options - Optional valueValidator
* @returns Void
* @throws TypeError
*/
export function assertIsArray(input: unknown): asserts input is any[];
Expand Down
14 changes: 0 additions & 14 deletions src/assertions/assertIsArrayBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@ import { createTypeAssertion } from '../utils';
import { isArrayBuffer } from '../guards/isArrayBuffer';

/**
* Asserts that input is ArrayBuffer object
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as ArrayBuffer
* assertIsArrayBuffer(new ArrayBuffer());
*
* // throws
* assertIsArrayBuffer([]);
*
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export const assertIsArrayBuffer =
createTypeAssertion<ArrayBuffer>(isArrayBuffer);
21 changes: 1 addition & 20 deletions src/assertions/assertIsAsyncFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,10 @@ import { AsyncFunction, isAsyncFunction } from '../guards/isAsyncFunction';
import { createTypeAssertion } from '../utils';

/**
* Asserts that input is AsyncFunction<T> object
*
* @remarks
* - This assertion works only in ES2018 and above
*
* This assertion works only in ES2018 and above
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as AsyncFunction<unknown>
* assertIsAsyncFunction(async () => await Promise.resolve())
*
* // does not throw, value is typed as AsyncFunction<boolean>
* assertIsAsyncFunction<boolean>(async () => await Promise.resolve(true))
*
* // throws
* assertIsAsyncFunction([]);
*
* @typeParam T - Type of Promise return value, defaults to unknown
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export function assertIsAsyncFunction<T = unknown>(
input: unknown,
Expand Down
31 changes: 1 addition & 30 deletions src/assertions/assertIsAsyncGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,10 @@ import { createTypeAssertion } from '../utils';
import { isAsyncGenerator } from '../guards/isAsyncGenerator';

/**
* Asserts that input is AsyncGenerator<Y, R, N> object
*
* @remarks
* - This assertion works only in ES2018 and above
*
* This assertion works only in ES2018 and above
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as AsyncGenerator<unknown, unknown, unknown>
* assertIsAsyncGenerator((async function* () {
* while (true) {
* yield await Promise.resolve(true);
* }
* })());
*
* // does not throw, value is typed as AsyncGenerator<boolean, unknown, unknown>
* assertIsAsyncGenerator<boolean>((async function* () {
* while (true) {
* yield await Promise.resolve(true);
* }
* })());
*
* // throws
* assertIsAsyncGenerator((function* () {})());
*
* @typeParam Y - Type of yield value, defaults to unknown
* @typeParam R - Type of return value, defaults to unknown
* @typeParam N - Type of .next() args, defaults to unknown
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export function assertIsAsyncGenerator<Y = unknown, R = unknown, N = unknown>(
input: unknown,
Expand Down
31 changes: 0 additions & 31 deletions src/assertions/assertIsAsyncGeneratorFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,8 @@ import {
import { createTypeAssertion } from '../utils';

/**
* Asserts that input is TypedAsyncGeneratorFunction<Y, R, N> object
*
* @remarks
* - This assertion works only in ES2018 and above
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as TypedAsyncGeneratorFunction<unknown, unknown, unknown>
* assertIsAsyncGeneratorFunction(async function* () {
* while (true) {
* yield await Promise.resolve(true);
* }
* });
*
* // does not throw, value is typed as TypedAsyncGeneratorFunction<boolean, unknown, unknown>
* assertIsAsyncGeneratorFunction(async function* () {
* while (true) {
* yield await Promise.resolve(true);
* }
* });
*
* // throws
* assertIsAsyncGeneratorFunction(function* () {});
*
* @typeParam Y - Type of yield value, defaults to unknown
* @typeParam R - Type of return value, defaults to unknown
* @typeParam N - Type of .next() args, defaults to unknown
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export function assertIsAsyncGeneratorFunction<
Y = unknown,
Expand Down
27 changes: 2 additions & 25 deletions src/assertions/assertIsAsyncIterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@ import { createTypeAssertion } from '../utils';
import { isAsyncIterable } from '../guards/isAsyncIterable';

/**
* Asserts that input is AsyncIterable<T> object
*
* @remarks
* - This guard tests for Symbol.asyncIterator. See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator}
*
* This guard tests for Symbol.asyncIterator. See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator}
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as AsyncIterable<unknown>
* assertIsAsyncIterable((async function* () {
* yield Promise.resolve(true);
* }()))
*
* // does not throw, value is typed as AsyncIterable<boolean>
* assertIsAsyncIterable<boolean>((async function* () {
* yield Promise.resolve(true);
* }()))
*
* // throws
* assertIsAsyncIterable({});
*
* @typeParam T - Type of AsyncIterable, defaults to unknown
* @param input - Value to be tested
* @returns void
* @throws TypeError
* ```
*/
export function assertIsAsyncIterable<T = unknown>(
input: unknown,
Expand Down
18 changes: 18 additions & 0 deletions src/assertions/assertIsBigInt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createTypeAssertion } from '../utils';
import { isBigInt } from '../guards/isBigInt';

/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw
* assertIsBigInt(BigInt(9007199254740991));
*
* // throws
* assertIsBigInt(9007199254740991n);
* ```
*
* @throws TypeError
*/
export const assertIsBigInt = createTypeAssertion<bigint>(isBigInt);
14 changes: 0 additions & 14 deletions src/assertions/assertIsBoolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { createTypeAssertion } from '../utils';
import { isBoolean } from '../guards/isBoolean';

/**
* Asserts that input is boolean primitive
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as boolean
* assertIsBoolean(false);
*
* // throws
* assertIsBoolean(null);
* ```
*
* @param input - Value to be tested
* @returns Void
* @throws TypeError
*/
export const assertIsBoolean = createTypeAssertion<boolean>(isBoolean);
14 changes: 0 additions & 14 deletions src/assertions/assertIsBooleanObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { createTypeAssertion } from '../utils';
import { isBooleanObject } from '../guards/isBooleanObject';

/**
* Asserts that input is Boolean object
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as Boolean
* assertIsBooleanObject(new Boolean(false));
*
* // throws
* assertIsBooleanObject(false);
* ```
*
* @param input - Value to be tested
* @returns Void
* @throws TypeError
*/
export const assertIsBooleanObject =
Expand Down
14 changes: 0 additions & 14 deletions src/assertions/assertIsBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { createTypeAssertion } from '../utils';
import { isBuffer } from '../guards/isBuffer';

/**
* Asserts that input is Buffer object
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as Buffer
* assertIsBuffer(Buffer.alloc(8);
*
* // throws
* assertIsBuffer('abc');
* ```
*
* @param input - Value to be tested
* @returns Void
* @throws TypeError
*/
export const assertIsBuffer = createTypeAssertion<Buffer>(isBuffer);
14 changes: 0 additions & 14 deletions src/assertions/assertIsDataView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { createTypeAssertion } from '../utils';
import { isDataView } from '../guards/isDataView';

/**
* Asserts that input is DataView object
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as DataView
* assertIsDataView(new DateView(new ArrayBuffer(8));
*
* // throws
* assertIsDataView('abc');
* ```
*
* @param input - Value to be tested
* @returns Void
* @throws TypeError
*/
export const assertIsDataView = createTypeAssertion<DataView>(isDataView);
Loading

0 comments on commit ae774a3

Please sign in to comment.