Skip to content

Commit

Permalink
Add ow.bigint (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
TagawaHirotaka authored Jun 5, 2021
1 parent 909b670 commit 0441b98
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
10 changes: 10 additions & 0 deletions source/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {TypedArray} from 'type-fest';
import {StringPredicate} from './predicates/string';
import {NumberPredicate} from './predicates/number';
import {BigIntPredicate} from './predicates/bigint';
import {BooleanPredicate} from './predicates/boolean';
import {Predicate, PredicateOptions} from './predicates/predicate';
import {ArrayPredicate} from './predicates/array';
Expand Down Expand Up @@ -28,6 +29,11 @@ export interface Predicates {
*/
readonly number: NumberPredicate;

/**
Test the value to be an bigint.
*/
readonly bigint: BigIntPredicate;

/**
Test the value to be a boolean.
*/
Expand Down Expand Up @@ -212,6 +218,9 @@ export default <T>(object: T, options?: PredicateOptions): T & Predicates => {
number: {
get: (): NumberPredicate => new NumberPredicate(options)
},
bigint: {
get: (): BigIntPredicate => new BigIntPredicate(options)
},
boolean: {
get: (): BooleanPredicate => new BooleanPredicate(options)
},
Expand Down Expand Up @@ -319,6 +328,7 @@ export default <T>(object: T, options?: PredicateOptions): T & Predicates => {
export {
StringPredicate,
NumberPredicate,
BigIntPredicate,
BooleanPredicate,
ArrayPredicate,
ObjectPredicate,
Expand Down
10 changes: 10 additions & 0 deletions source/predicates/bigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Predicate, PredicateOptions} from './predicate';

export class BigIntPredicate extends Predicate<bigint> {
/**
@hidden
*/
constructor(options?: PredicateOptions) {
super('bigint', options);
}
}
18 changes: 18 additions & 0 deletions test/bigint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava';
import ow from '../source';

test('bigint', t => {
t.notThrows(() => {
// eslint-disable-next-line node/no-unsupported-features/es-builtins
ow(BigInt(9007199254740991), ow.bigint);
});

t.notThrows(() => {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
ow(9007199254740991n, ow.bigint);
});

t.throws(() => {
ow(10, ow.bigint);
}, 'Expected argument to be of type `bigint` but received type `number`');
});
3 changes: 3 additions & 0 deletions test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ function typeTests(value: unknown): Array<(() => void)> {
const tests: Tests = {
array: expect => expect.toBeArray(),
arrayBuffer: expect => expect.toEqualTypeOf<ArrayBuffer>(),
// @ts-expect-error
// eslint-disable-next-line node/no-unsupported-features/es-builtins
bigint: expect => expect.toEqualTypeOf<BigInt>(),
boolean: expect => expect.toBeBoolean(),
buffer: expect => expect.toEqualTypeOf<Buffer>(),
dataView: expect => expect.toEqualTypeOf<DataView>(),
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"outDir": "dist",
"target": "es2018",
"target": "es2020",
"lib": [
"es2018"
"es2020"
]
},
"include": [
Expand Down

0 comments on commit 0441b98

Please sign in to comment.