From ffe7cf6698ecdffe680941e6a227c3238558bcfb Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sat, 16 Oct 2021 23:34:04 +0200 Subject: [PATCH 01/22] output esm --- package.json | 3 ++- source/argument-error.ts | 2 +- source/index.ts | 16 ++++++------- source/modifiers.ts | 4 ++-- source/operators/not.ts | 6 ++--- source/predicates.ts | 36 ++++++++++++++--------------- source/predicates/any.ts | 10 ++++---- source/predicates/array-buffer.ts | 2 +- source/predicates/array.ts | 12 +++++----- source/predicates/base-predicate.ts | 2 +- source/predicates/bigint.ts | 2 +- source/predicates/boolean.ts | 2 +- source/predicates/data-view.ts | 2 +- source/predicates/date.ts | 2 +- source/predicates/error.ts | 2 +- source/predicates/map.ts | 8 +++---- source/predicates/number.ts | 2 +- source/predicates/object.ts | 16 ++++++------- source/predicates/predicate.ts | 10 ++++---- source/predicates/set.ts | 8 +++---- source/predicates/string.ts | 4 ++-- source/predicates/typed-array.ts | 2 +- source/predicates/weak-map.ts | 4 ++-- source/predicates/weak-set.ts | 4 ++-- source/test.ts | 2 +- source/utils/infer-label.ts | 4 ++-- source/utils/match-shape.ts | 6 ++--- source/utils/of-type-deep.ts | 4 ++-- source/utils/of-type.ts | 4 ++-- tsconfig.json | 10 ++++---- 30 files changed, 95 insertions(+), 96 deletions(-) diff --git a/package.json b/package.json index fdf3f0d..e815008 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", "main": "dist/index.js", "engines": { "node": ">=12" @@ -68,7 +69,7 @@ "nyc": "^15.1.0", "ts-node": "^10.2.1", "typedoc": "^0.22.5", - "typescript": "^4.4.3", + "typescript": "^4.5.0-beta", "xo": "^0.38.2" }, "browser": { diff --git a/source/argument-error.ts b/source/argument-error.ts index afdcbce..8c062cf 100644 --- a/source/argument-error.ts +++ b/source/argument-error.ts @@ -1,4 +1,4 @@ -import {generateStackTrace} from './utils/generate-stack'; +import {generateStackTrace} from './utils/generate-stack.js'; const wrapStackTrace = (error: ArgumentError, stack: string): string => `${error.name}: ${error.message}\n${stack}`; diff --git a/source/index.ts b/source/index.ts index 88f5d3b..bb2937c 100644 --- a/source/index.ts +++ b/source/index.ts @@ -1,10 +1,10 @@ import callsites from 'callsites'; -import {inferLabel} from './utils/infer-label'; -import {Predicate} from './predicates/predicate'; -import {BasePredicate, isPredicate} from './predicates/base-predicate'; -import modifiers, {Modifiers} from './modifiers'; -import predicates, {Predicates} from './predicates'; -import test from './test'; +import {inferLabel} from './utils/infer-label.js'; +import {Predicate} from './predicates/predicate.js'; +import {BasePredicate, isPredicate} from './predicates/base-predicate.js'; +import modifiers, {Modifiers} from './modifiers.js'; +import predicates, {Predicates} from './predicates.js'; +import test from './test.js'; /** @hidden @@ -149,5 +149,5 @@ const _ow: Ow = predicates(modifiers(ow)) as Ow; export default _ow; export {BasePredicate, Predicate}; -export * from './predicates'; -export {ArgumentError} from './argument-error'; +export * from './predicates.js'; +export {ArgumentError} from './argument-error.js'; diff --git a/source/modifiers.ts b/source/modifiers.ts index 267104c..9723e6c 100644 --- a/source/modifiers.ts +++ b/source/modifiers.ts @@ -1,5 +1,5 @@ -import {BasePredicate} from '.'; -import predicates, {Predicates} from './predicates'; +import {BasePredicate} from './index.js'; +import predicates, {Predicates} from './predicates.js'; type Optionalify

= P extends BasePredicate ? P & BasePredicate diff --git a/source/operators/not.ts b/source/operators/not.ts index f21bd91..3565cff 100644 --- a/source/operators/not.ts +++ b/source/operators/not.ts @@ -1,6 +1,6 @@ -import randomId from '../utils/random-id'; -import {validatorSymbol} from '../predicates/predicate'; -import type {Predicate, Validator} from '../predicates/predicate'; +import randomId from '../utils/random-id.js'; +import {validatorSymbol} from '../predicates/predicate.js'; +import type {Predicate, Validator} from '../predicates/predicate.js'; /** Operator which inverts the following validation. diff --git a/source/predicates.ts b/source/predicates.ts index b83aa75..5d5bd56 100644 --- a/source/predicates.ts +++ b/source/predicates.ts @@ -1,22 +1,22 @@ 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'; -import {ObjectPredicate, Shape} from './predicates/object'; -import {DatePredicate} from './predicates/date'; -import {ErrorPredicate} from './predicates/error'; -import {MapPredicate} from './predicates/map'; -import {WeakMapPredicate} from './predicates/weak-map'; -import {SetPredicate} from './predicates/set'; -import {WeakSetPredicate} from './predicates/weak-set'; -import {TypedArrayPredicate} from './predicates/typed-array'; -import {ArrayBufferPredicate} from './predicates/array-buffer'; -import {DataViewPredicate} from './predicates/data-view'; -import {BasePredicate} from './predicates/base-predicate'; -import {AnyPredicate} from './predicates/any'; +import {StringPredicate} from './predicates/string.js'; +import {NumberPredicate} from './predicates/number.js'; +import {BigIntPredicate} from './predicates/bigint.js'; +import {BooleanPredicate} from './predicates/boolean.js'; +import {Predicate, PredicateOptions} from './predicates/predicate.js'; +import {ArrayPredicate} from './predicates/array.js'; +import {ObjectPredicate, Shape} from './predicates/object.js'; +import {DatePredicate} from './predicates/date.js'; +import {ErrorPredicate} from './predicates/error.js'; +import {MapPredicate} from './predicates/map.js'; +import {WeakMapPredicate} from './predicates/weak-map.js'; +import {SetPredicate} from './predicates/set.js'; +import {WeakSetPredicate} from './predicates/weak-set.js'; +import {TypedArrayPredicate} from './predicates/typed-array.js'; +import {ArrayBufferPredicate} from './predicates/array-buffer.js'; +import {DataViewPredicate} from './predicates/data-view.js'; +import {BasePredicate} from './predicates/base-predicate.js'; +import {AnyPredicate} from './predicates/any.js'; export interface Predicates { /** diff --git a/source/predicates/any.ts b/source/predicates/any.ts index ae62b8c..ffe902e 100644 --- a/source/predicates/any.ts +++ b/source/predicates/any.ts @@ -1,8 +1,8 @@ -import {ArgumentError} from '../argument-error'; -import {BasePredicate, testSymbol} from './base-predicate'; -import {PredicateOptions} from './predicate'; -import {Main} from '..'; -import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message'; +import {ArgumentError} from '../argument-error.js'; +import {BasePredicate, testSymbol} from './base-predicate.js'; +import {PredicateOptions} from './predicate.js'; +import {Main} from '../index.js'; +import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js'; /** @hidden diff --git a/source/predicates/array-buffer.ts b/source/predicates/array-buffer.ts index 2e4bfdc..fbf2fe5 100644 --- a/source/predicates/array-buffer.ts +++ b/source/predicates/array-buffer.ts @@ -1,4 +1,4 @@ -import {Predicate} from './predicate'; +import {Predicate} from './predicate.js'; export class ArrayBufferPredicate extends Predicate { /** diff --git a/source/predicates/array.ts b/source/predicates/array.ts index 7f4e416..b866c73 100644 --- a/source/predicates/array.ts +++ b/source/predicates/array.ts @@ -1,9 +1,9 @@ -import isEqual = require('lodash.isequal'); -import {BasePredicate} from './base-predicate'; -import {Predicate, PredicateOptions} from './predicate'; -import {Shape} from './object'; -import {exact} from '../utils/match-shape'; -import ofType from '../utils/of-type'; +import isEqual from 'lodash.isequal'; +import {BasePredicate} from './base-predicate.js'; +import {Predicate, PredicateOptions} from './predicate.js'; +import {Shape} from './object.js'; +import {exact} from '../utils/match-shape.js'; +import ofType from '../utils/of-type.js'; export class ArrayPredicate extends Predicate { /** diff --git a/source/predicates/base-predicate.ts b/source/predicates/base-predicate.ts index c722a75..a80dd30 100644 --- a/source/predicates/base-predicate.ts +++ b/source/predicates/base-predicate.ts @@ -1,4 +1,4 @@ -import {Main} from '..'; +import {Main} from '../index.js'; /** @hidden diff --git a/source/predicates/bigint.ts b/source/predicates/bigint.ts index 4e60edc..a11f6cf 100644 --- a/source/predicates/bigint.ts +++ b/source/predicates/bigint.ts @@ -1,4 +1,4 @@ -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class BigIntPredicate extends Predicate { /** diff --git a/source/predicates/boolean.ts b/source/predicates/boolean.ts index cfa57ac..89a3ea3 100644 --- a/source/predicates/boolean.ts +++ b/source/predicates/boolean.ts @@ -1,4 +1,4 @@ -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class BooleanPredicate extends Predicate { /** diff --git a/source/predicates/data-view.ts b/source/predicates/data-view.ts index b82f843..392e050 100644 --- a/source/predicates/data-view.ts +++ b/source/predicates/data-view.ts @@ -1,4 +1,4 @@ -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class DataViewPredicate extends Predicate { /** diff --git a/source/predicates/date.ts b/source/predicates/date.ts index 17eed08..ca721dd 100644 --- a/source/predicates/date.ts +++ b/source/predicates/date.ts @@ -1,4 +1,4 @@ -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class DatePredicate extends Predicate { /** diff --git a/source/predicates/error.ts b/source/predicates/error.ts index b9cba5d..cfe9736 100644 --- a/source/predicates/error.ts +++ b/source/predicates/error.ts @@ -1,4 +1,4 @@ -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class ErrorPredicate extends Predicate { /** diff --git a/source/predicates/map.ts b/source/predicates/map.ts index 0b4b1ab..3e3c311 100644 --- a/source/predicates/map.ts +++ b/source/predicates/map.ts @@ -1,7 +1,7 @@ -import isEqual = require('lodash.isequal'); -import hasItems from '../utils/has-items'; -import ofType from '../utils/of-type'; -import {Predicate, PredicateOptions} from './predicate'; +import isEqual from 'lodash.isequal'; +import hasItems from '../utils/has-items.js'; +import ofType from '../utils/of-type.js'; +import {Predicate, PredicateOptions} from './predicate.js'; export class MapPredicate extends Predicate> { /** diff --git a/source/predicates/number.ts b/source/predicates/number.ts index d862886..9b9493d 100644 --- a/source/predicates/number.ts +++ b/source/predicates/number.ts @@ -1,5 +1,5 @@ import is from '@sindresorhus/is'; -import {Predicate, PredicateOptions} from './predicate'; +import {Predicate, PredicateOptions} from './predicate.js'; export class NumberPredicate extends Predicate { /** diff --git a/source/predicates/object.ts b/source/predicates/object.ts index 118c089..844f712 100644 --- a/source/predicates/object.ts +++ b/source/predicates/object.ts @@ -1,13 +1,13 @@ import is from '@sindresorhus/is'; -import dotProp = require('dot-prop'); -import isEqual = require('lodash.isequal'); -import hasItems from '../utils/has-items'; -import ofType from '../utils/of-type'; -import ofTypeDeep from '../utils/of-type-deep'; -import {partial, exact, Shape, TypeOfShape} from '../utils/match-shape'; -import {Predicate, PredicateOptions} from './predicate'; -import {BasePredicate} from './base-predicate'; +import dotProp from 'dot-prop'; +import isEqual from 'lodash.isequal'; +import hasItems from '../utils/has-items.js'; +import ofType from '../utils/of-type.js'; +import ofTypeDeep from '../utils/of-type-deep.js'; +import {partial, exact, Shape, TypeOfShape} from '../utils/match-shape.js'; +import {Predicate, PredicateOptions} from './predicate.js'; +import {BasePredicate} from './base-predicate.js'; export {Shape}; diff --git a/source/predicates/predicate.ts b/source/predicates/predicate.ts index e1e949f..e8f2414 100644 --- a/source/predicates/predicate.ts +++ b/source/predicates/predicate.ts @@ -1,9 +1,9 @@ import is from '@sindresorhus/is'; -import {ArgumentError} from '../argument-error'; -import {not} from '../operators/not'; -import {BasePredicate, testSymbol} from './base-predicate'; -import {Main} from '..'; -import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message'; +import {ArgumentError} from '../argument-error.js'; +import {not} from '../operators/not.js'; +import {BasePredicate, testSymbol} from './base-predicate.js'; +import {Main} from '../index.js'; +import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js'; /** Function executed when the provided validation fails. diff --git a/source/predicates/set.ts b/source/predicates/set.ts index ecb47bb..51e3147 100644 --- a/source/predicates/set.ts +++ b/source/predicates/set.ts @@ -1,7 +1,7 @@ -import isEqual = require('lodash.isequal'); -import hasItems from '../utils/has-items'; -import ofType from '../utils/of-type'; -import {Predicate, PredicateOptions} from './predicate'; +import isEqual from 'lodash.isequal'; +import hasItems from '../utils/has-items.js'; +import ofType from '../utils/of-type.js'; +import {Predicate, PredicateOptions} from './predicate.js'; export class SetPredicate extends Predicate> { /** diff --git a/source/predicates/string.ts b/source/predicates/string.ts index 97e6a17..2e5343d 100644 --- a/source/predicates/string.ts +++ b/source/predicates/string.ts @@ -1,6 +1,6 @@ import is from '@sindresorhus/is'; -import valiDate = require('vali-date'); -import {Predicate, PredicateOptions} from './predicate'; +import valiDate from 'vali-date'; +import {Predicate, PredicateOptions} from './predicate.js'; export class StringPredicate extends Predicate { /** diff --git a/source/predicates/typed-array.ts b/source/predicates/typed-array.ts index 3e6d868..cf54bce 100644 --- a/source/predicates/typed-array.ts +++ b/source/predicates/typed-array.ts @@ -1,5 +1,5 @@ import {TypedArray} from 'type-fest'; -import {Predicate} from './predicate'; +import {Predicate} from './predicate.js'; export class TypedArrayPredicate extends Predicate { /** diff --git a/source/predicates/weak-map.ts b/source/predicates/weak-map.ts index faad313..eae4348 100644 --- a/source/predicates/weak-map.ts +++ b/source/predicates/weak-map.ts @@ -1,5 +1,5 @@ -import hasItems from '../utils/has-items'; -import {Predicate, PredicateOptions} from './predicate'; +import hasItems from '../utils/has-items.js'; +import {Predicate, PredicateOptions} from './predicate.js'; export class WeakMapPredicate extends Predicate> { /** diff --git a/source/predicates/weak-set.ts b/source/predicates/weak-set.ts index 1a9e803..1685b2e 100644 --- a/source/predicates/weak-set.ts +++ b/source/predicates/weak-set.ts @@ -1,5 +1,5 @@ -import hasItems from '../utils/has-items'; -import {Predicate, PredicateOptions} from './predicate'; +import hasItems from '../utils/has-items.js'; +import {Predicate, PredicateOptions} from './predicate.js'; export class WeakSetPredicate extends Predicate> { /** diff --git a/source/test.ts b/source/test.ts index 8dea8a3..156e243 100644 --- a/source/test.ts +++ b/source/test.ts @@ -1,4 +1,4 @@ -import {testSymbol, BasePredicate} from './predicates/base-predicate'; +import {testSymbol, BasePredicate} from './predicates/base-predicate.js'; /** Validate the value against the provided predicate. diff --git a/source/utils/infer-label.ts b/source/utils/infer-label.ts index a13e663..6496d07 100644 --- a/source/utils/infer-label.ts +++ b/source/utils/infer-label.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import {CallSite} from 'callsites'; -import isValidIdentifier from './is-valid-identifier'; -import isNode from './node/is-node'; +import isValidIdentifier from './is-valid-identifier.js'; +import isNode from './node/is-node.js'; // Regex to extract the label out of the `ow` function call const labelRegex = /^.*?\((?

= P extends BasePredicate ? P & BasePredicate @@ -14,12 +14,14 @@ export interface Modifiers { }; } -export default (object: T): T & Modifiers => { +const modifiers = (object: T): T & Modifiers => { Object.defineProperties(object, { optional: { - get: (): Predicates => predicates({}, {optional: true}) - } + get: (): Predicates => predicates({}, {optional: true}), + }, }); return object as T & Modifiers; }; + +export default modifiers; diff --git a/source/operators/not.ts b/source/operators/not.ts index 3565cff..6155eb3 100644 --- a/source/operators/not.ts +++ b/source/operators/not.ts @@ -17,9 +17,9 @@ export const not = (predicate: Predicate): Predicate => { const placeholder = randomId(); validator.message = (value: unknown, label: string): string => ( - negatedMessage ? - negatedMessage(value, label) : - message(value, placeholder).replace(/ to /, '$¬ ').replace(placeholder, label) + negatedMessage + ? negatedMessage(value, label) + : message(value, placeholder).replace(/ to /, '$¬ ').replace(placeholder, label) ); validator.validator = (value: unknown): unknown => !fn(value); diff --git a/source/predicates.ts b/source/predicates.ts index 5d5bd56..1140ae0 100644 --- a/source/predicates.ts +++ b/source/predicates.ts @@ -1,3 +1,4 @@ +import type {Buffer} from 'node:buffer'; import {TypedArray} from 'type-fest'; import {StringPredicate} from './predicates/string.js'; import {NumberPredicate} from './predicates/number.js'; @@ -210,121 +211,123 @@ export interface Predicates { & ((...predicate: BasePredicate[]) => AnyPredicate); } -export default (object: T, options?: PredicateOptions): T & Predicates => { +const predicates = (object: T, options?: PredicateOptions): T & Predicates => { Object.defineProperties(object, { string: { - get: (): StringPredicate => new StringPredicate(options) + get: (): StringPredicate => new StringPredicate(options), }, number: { - get: (): NumberPredicate => new NumberPredicate(options) + get: (): NumberPredicate => new NumberPredicate(options), }, bigint: { - get: (): BigIntPredicate => new BigIntPredicate(options) + get: (): BigIntPredicate => new BigIntPredicate(options), }, boolean: { - get: (): BooleanPredicate => new BooleanPredicate(options) + get: (): BooleanPredicate => new BooleanPredicate(options), }, undefined: { - get: (): Predicate => new Predicate('undefined', options) + get: (): Predicate => new Predicate('undefined', options), }, null: { - get: (): Predicate => new Predicate('null', options) + get: (): Predicate => new Predicate('null', options), }, nullOrUndefined: { - get: (): Predicate => new Predicate('nullOrUndefined', options) + get: (): Predicate => new Predicate('nullOrUndefined', options), }, nan: { - get: (): Predicate => new Predicate('nan', options) + get: (): Predicate => new Predicate('nan', options), }, symbol: { - get: (): Predicate => new Predicate('symbol', options) + get: (): Predicate => new Predicate('symbol', options), }, array: { - get: (): ArrayPredicate => new ArrayPredicate(options) + get: (): ArrayPredicate => new ArrayPredicate(options), }, object: { - get: (): ObjectPredicate => new ObjectPredicate(options) + get: (): ObjectPredicate => new ObjectPredicate(options), }, date: { - get: (): DatePredicate => new DatePredicate(options) + get: (): DatePredicate => new DatePredicate(options), }, error: { - get: (): ErrorPredicate => new ErrorPredicate(options) + get: (): ErrorPredicate => new ErrorPredicate(options), }, map: { - get: (): MapPredicate => new MapPredicate(options) + get: (): MapPredicate => new MapPredicate(options), }, weakMap: { - get: (): WeakMapPredicate => new WeakMapPredicate(options) + get: (): WeakMapPredicate => new WeakMapPredicate(options), }, set: { - get: (): SetPredicate => new SetPredicate(options) + get: (): SetPredicate => new SetPredicate(options), }, weakSet: { - get: (): WeakSetPredicate => new WeakSetPredicate(options) + get: (): WeakSetPredicate => new WeakSetPredicate(options), }, function: { - get: (): Predicate => new Predicate('Function', options) + get: (): Predicate => new Predicate('Function', options), }, buffer: { - get: (): Predicate => new Predicate('Buffer', options) + get: (): Predicate => new Predicate('Buffer', options), }, regExp: { - get: (): Predicate => new Predicate('RegExp', options) + get: (): Predicate => new Predicate('RegExp', options), }, promise: { - get: (): Predicate => new Predicate('Promise', options) + get: (): Predicate => new Predicate('Promise', options), }, typedArray: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('TypedArray', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('TypedArray', options), }, int8Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Int8Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Int8Array', options), }, uint8Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint8Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint8Array', options), }, uint8ClampedArray: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint8ClampedArray', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint8ClampedArray', options), }, int16Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Int16Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Int16Array', options), }, uint16Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint16Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint16Array', options), }, int32Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Int32Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Int32Array', options), }, uint32Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint32Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Uint32Array', options), }, float32Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Float32Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Float32Array', options), }, float64Array: { - get: (): TypedArrayPredicate => new TypedArrayPredicate('Float64Array', options) + get: (): TypedArrayPredicate => new TypedArrayPredicate('Float64Array', options), }, arrayBuffer: { - get: (): ArrayBufferPredicate => new ArrayBufferPredicate('ArrayBuffer', options) + get: (): ArrayBufferPredicate => new ArrayBufferPredicate('ArrayBuffer', options), }, sharedArrayBuffer: { - get: (): ArrayBufferPredicate => new ArrayBufferPredicate('SharedArrayBuffer', options) + get: (): ArrayBufferPredicate => new ArrayBufferPredicate('SharedArrayBuffer', options), }, dataView: { - get: (): DataViewPredicate => new DataViewPredicate(options) + get: (): DataViewPredicate => new DataViewPredicate(options), }, iterable: { - get: (): Predicate => new Predicate('Iterable', options) + get: (): Predicate => new Predicate('Iterable', options), }, any: { - value: (...predicates: BasePredicate[]): AnyPredicate => new AnyPredicate(predicates, options) - } + value: (...predicates: BasePredicate[]): AnyPredicate => new AnyPredicate(predicates, options), + }, }); return object as T & Predicates; }; +export default predicates; + export { StringPredicate, NumberPredicate, @@ -342,5 +345,5 @@ export { ArrayBufferPredicate, DataViewPredicate, AnyPredicate, - Shape + Shape, }; diff --git a/source/predicates/any.ts b/source/predicates/any.ts index ffe902e..7e5a448 100644 --- a/source/predicates/any.ts +++ b/source/predicates/any.ts @@ -1,8 +1,8 @@ import {ArgumentError} from '../argument-error.js'; -import {BasePredicate, testSymbol} from './base-predicate.js'; -import {PredicateOptions} from './predicate.js'; import {Main} from '../index.js'; import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js'; +import {BasePredicate, testSymbol} from './base-predicate.js'; +import {PredicateOptions} from './predicate.js'; /** @hidden @@ -10,7 +10,7 @@ import {generateArgumentErrorMessage} from '../utils/generate-argument-error-mes export class AnyPredicate implements BasePredicate { constructor( private readonly predicates: BasePredicate[], - private readonly options: PredicateOptions = {} + private readonly options: PredicateOptions = {}, ) {} [testSymbol](value: T, main: Main, label: string | Function, idLabel: boolean): asserts value { @@ -46,7 +46,7 @@ export class AnyPredicate implements BasePredicate { throw new ArgumentError( `Any predicate failed with the following errors:\n${message}`, main, - errors + errors, ); } } diff --git a/source/predicates/array-buffer.ts b/source/predicates/array-buffer.ts index fbf2fe5..d665d0e 100644 --- a/source/predicates/array-buffer.ts +++ b/source/predicates/array-buffer.ts @@ -9,7 +9,7 @@ export class ArrayBufferPredicate extends Predicate `Expected ${label} to have byte length of \`${byteLength}\`, got \`${value.byteLength}\``, - validator: value => value.byteLength === byteLength + validator: value => value.byteLength === byteLength, }); } @@ -22,7 +22,7 @@ export class ArrayBufferPredicate extends Predicate `Expected ${label} to have a minimum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength >= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\``, }); } @@ -35,7 +35,7 @@ export class ArrayBufferPredicate extends Predicate `Expected ${label} to have a maximum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength <= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\``, }); } } diff --git a/source/predicates/array.ts b/source/predicates/array.ts index b866c73..32e2c38 100644 --- a/source/predicates/array.ts +++ b/source/predicates/array.ts @@ -1,9 +1,9 @@ import isEqual from 'lodash.isequal'; +import {exact} from '../utils/match-shape.js'; +import ofType from '../utils/of-type.js'; import {BasePredicate} from './base-predicate.js'; import {Predicate, PredicateOptions} from './predicate.js'; import {Shape} from './object.js'; -import {exact} from '../utils/match-shape.js'; -import ofType from '../utils/of-type.js'; export class ArrayPredicate extends Predicate { /** @@ -21,7 +21,7 @@ export class ArrayPredicate extends Predicate { length(length: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to have length \`${length}\`, got \`${value.length}\``, - validator: value => value.length === length + validator: value => value.length === length, }); } @@ -34,7 +34,7 @@ export class ArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a minimum length of \`${length}\`, got \`${value.length}\``, validator: value => value.length >= length, - negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value.length}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value.length}\``, }); } @@ -47,7 +47,7 @@ export class ArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a maximum length of \`${length}\`, got \`${value.length}\``, validator: value => value.length <= length, - negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value.length}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value.length}\``, }); } @@ -59,7 +59,7 @@ export class ArrayPredicate extends Predicate { startsWith(searchElement: T): this { return this.addValidator({ message: (value, label) => `Expected ${label} to start with \`${searchElement}\`, got \`${value[0]}\``, - validator: value => value[0] === searchElement + validator: value => value[0] === searchElement, }); } @@ -71,7 +71,7 @@ export class ArrayPredicate extends Predicate { endsWith(searchElement: T): this { return this.addValidator({ message: (value, label) => `Expected ${label} to end with \`${searchElement}\`, got \`${value[value.length - 1]}\``, - validator: value => value[value.length - 1] === searchElement + validator: value => value[value.length - 1] === searchElement, }); } @@ -83,7 +83,7 @@ export class ArrayPredicate extends Predicate { includes(...searchElements: readonly T[]): this { return this.addValidator({ message: (value, label) => `Expected ${label} to include all elements of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``, - validator: value => searchElements.every(element => value.includes(element)) + validator: value => searchElements.every(element => value.includes(element)), }); } @@ -95,7 +95,7 @@ export class ArrayPredicate extends Predicate { includesAny(...searchElements: readonly T[]): this { return this.addValidator({ message: (value, label) => `Expected ${label} to include any element of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``, - validator: value => searchElements.some(element => value.includes(element)) + validator: value => searchElements.some(element => value.includes(element)), }); } @@ -105,7 +105,7 @@ export class ArrayPredicate extends Predicate { get empty(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be empty, got \`${JSON.stringify(value)}\``, - validator: value => value.length === 0 + validator: value => value.length === 0, }); } @@ -115,7 +115,7 @@ export class ArrayPredicate extends Predicate { get nonEmpty(): this { return this.addValidator({ message: (_, label) => `Expected ${label} to not be empty`, - validator: value => value.length > 0 + validator: value => value.length > 0, }); } @@ -127,7 +127,7 @@ export class ArrayPredicate extends Predicate { deepEqual(expected: readonly T[]): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be deeply equal to \`${JSON.stringify(expected)}\`, got \`${JSON.stringify(value)}\``, - validator: value => isEqual(value, expected) + validator: value => isEqual(value, expected), }); } @@ -143,9 +143,10 @@ export class ArrayPredicate extends Predicate { */ ofType(predicate: BasePredicate): ArrayPredicate { // TODO [typescript@>=5] If higher-kinded types are supported natively by typescript, refactor `addValidator` to use them to avoid the usage of `any`. Otherwise, bump or remove this TODO. + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: value => ofType(value, 'values', predicate) + validator: value => ofType(value, 'values', predicate), }) as ArrayPredicate; } @@ -163,8 +164,9 @@ export class ArrayPredicate extends Predicate { const shape = predicates as unknown as Shape; return this.addValidator({ + // eslint-disable-next-line @typescript-eslint/no-unsafe-call message: (_, label, message) => `${message.replace('Expected', 'Expected element')} in ${label}`, - validator: object => exact(object, shape, undefined, true) + validator: object => exact(object, shape, undefined, true), }); } } diff --git a/source/predicates/boolean.ts b/source/predicates/boolean.ts index 89a3ea3..9f630bc 100644 --- a/source/predicates/boolean.ts +++ b/source/predicates/boolean.ts @@ -14,7 +14,7 @@ export class BooleanPredicate extends Predicate { get true(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be true, got ${value}`, - validator: value => value + validator: value => value, }); } @@ -24,7 +24,7 @@ export class BooleanPredicate extends Predicate { get false(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be false, got ${value}`, - validator: value => !value + validator: value => !value, }); } } diff --git a/source/predicates/data-view.ts b/source/predicates/data-view.ts index 392e050..ae5d9d6 100644 --- a/source/predicates/data-view.ts +++ b/source/predicates/data-view.ts @@ -16,7 +16,7 @@ export class DataViewPredicate extends Predicate { byteLength(byteLength: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to have byte length of \`${byteLength}\`, got \`${value.byteLength}\``, - validator: value => value.byteLength === byteLength + validator: value => value.byteLength === byteLength, }); } @@ -29,7 +29,7 @@ export class DataViewPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength >= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\``, }); } @@ -42,7 +42,7 @@ export class DataViewPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength <= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\``, }); } } diff --git a/source/predicates/date.ts b/source/predicates/date.ts index ca721dd..c91da31 100644 --- a/source/predicates/date.ts +++ b/source/predicates/date.ts @@ -16,7 +16,7 @@ export class DatePredicate extends Predicate { before(date: Date): this { return this.addValidator({ message: (value, label) => `Expected ${label} ${value.toISOString()} to be before ${date.toISOString()}`, - validator: value => value.getTime() < date.getTime() + validator: value => value.getTime() < date.getTime(), }); } @@ -28,7 +28,7 @@ export class DatePredicate extends Predicate { after(date: Date): this { return this.addValidator({ message: (value, label) => `Expected ${label} ${value.toISOString()} to be after ${date.toISOString()}`, - validator: value => value.getTime() > date.getTime() + validator: value => value.getTime() > date.getTime(), }); } } diff --git a/source/predicates/error.ts b/source/predicates/error.ts index cfe9736..db5e3f0 100644 --- a/source/predicates/error.ts +++ b/source/predicates/error.ts @@ -16,7 +16,7 @@ export class ErrorPredicate extends Predicate { name(expected: string): this { return this.addValidator({ message: (error, label) => `Expected ${label} to have name \`${expected}\`, got \`${error.name}\``, - validator: error => error.name === expected + validator: error => error.name === expected, }); } @@ -28,7 +28,7 @@ export class ErrorPredicate extends Predicate { message(expected: string): this { return this.addValidator({ message: (error, label) => `Expected ${label} message to be \`${expected}\`, got \`${error.message}\``, - validator: error => error.message === expected + validator: error => error.message === expected, }); } @@ -40,7 +40,7 @@ export class ErrorPredicate extends Predicate { messageIncludes(message: string): this { return this.addValidator({ message: (error, label) => `Expected ${label} message to include \`${message}\`, got \`${error.message}\``, - validator: error => error.message.includes(message) + validator: error => error.message.includes(message), }); } @@ -52,7 +52,7 @@ export class ErrorPredicate extends Predicate { hasKeys(...keys: readonly string[]): this { return this.addValidator({ message: (_, label) => `Expected ${label} message to have keys \`${keys.join('`, `')}\``, - validator: error => keys.every(key => Object.prototype.hasOwnProperty.call(error, key)) + validator: error => keys.every(key => Object.prototype.hasOwnProperty.call(error, key)), }); } @@ -64,7 +64,7 @@ export class ErrorPredicate extends Predicate { instanceOf(instance: Function): this { return this.addValidator({ message: (error, label) => `Expected ${label} \`${error.name}\` to be of type \`${instance.name}\``, - validator: error => error instanceof instance + validator: error => error instanceof instance, }); } diff --git a/source/predicates/map.ts b/source/predicates/map.ts index 3e3c311..043b9ad 100644 --- a/source/predicates/map.ts +++ b/source/predicates/map.ts @@ -19,7 +19,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have size \`${size}\`, got \`${map.size}\``, - validator: map => map.size === size + validator: map => map.size === size, }); } @@ -32,7 +32,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have a minimum size of \`${size}\`, got \`${map.size}\``, validator: map => map.size >= size, - negatedMessage: (map, label) => `Expected ${label} to have a maximum size of \`${size - 1}\`, got \`${map.size}\`` + negatedMessage: (map, label) => `Expected ${label} to have a maximum size of \`${size - 1}\`, got \`${map.size}\``, }); } @@ -45,7 +45,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have a maximum size of \`${size}\`, got \`${map.size}\``, validator: map => map.size <= size, - negatedMessage: (map, label) => `Expected ${label} to have a minimum size of \`${size + 1}\`, got \`${map.size}\`` + negatedMessage: (map, label) => `Expected ${label} to have a minimum size of \`${size + 1}\`, got \`${map.size}\``, }); } @@ -57,7 +57,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``, - validator: map => hasItems(map, keys) + validator: map => hasItems(map, keys), }); } @@ -69,7 +69,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``, - validator: map => keys.some(key => map.has(key)) + validator: map => keys.some(key => map.has(key)), }); } @@ -81,7 +81,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have values \`${JSON.stringify(missingValues)}\``, - validator: map => hasItems(new Set(map.values()), values) + validator: map => hasItems(new Set(map.values()), values), }); } @@ -96,7 +96,7 @@ export class MapPredicate extends Predicate { const valueSet = new Set(map.values()); return values.some(key => valueSet.has(key)); - } + }, }); } @@ -108,7 +108,7 @@ export class MapPredicate extends Predicate): this { return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: map => ofType(map.keys(), 'keys', predicate) + validator: map => ofType(map.keys(), 'keys', predicate), }); } @@ -120,7 +120,7 @@ export class MapPredicate extends Predicate): this { return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: map => ofType(map.values(), 'values', predicate) + validator: map => ofType(map.values(), 'values', predicate), }); } @@ -130,7 +130,7 @@ export class MapPredicate extends Predicate `Expected ${label} to be empty, got \`${JSON.stringify([...map])}\``, - validator: map => map.size === 0 + validator: map => map.size === 0, }); } @@ -140,7 +140,7 @@ export class MapPredicate extends Predicate `Expected ${label} to not be empty`, - validator: map => map.size > 0 + validator: map => map.size > 0, }); } @@ -152,7 +152,7 @@ export class MapPredicate extends Predicate): this { return this.addValidator({ message: (map, label) => `Expected ${label} to be deeply equal to \`${JSON.stringify([...expected])}\`, got \`${JSON.stringify([...map])}\``, - validator: map => isEqual(map, expected) + validator: map => isEqual(map, expected), }); } } diff --git a/source/predicates/number.ts b/source/predicates/number.ts index 9b9493d..ae42ffc 100644 --- a/source/predicates/number.ts +++ b/source/predicates/number.ts @@ -18,7 +18,7 @@ export class NumberPredicate extends Predicate { inRange(start: number, end: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be in range [${start}..${end}], got ${value}`, - validator: value => is.inRange(value, [start, end]) + validator: value => is.inRange(value, [start, end]), }); } @@ -30,7 +30,7 @@ export class NumberPredicate extends Predicate { greaterThan(number: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be greater than ${number}, got ${value}`, - validator: value => value > number + validator: value => value > number, }); } @@ -42,7 +42,7 @@ export class NumberPredicate extends Predicate { greaterThanOrEqual(number: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be greater than or equal to ${number}, got ${value}`, - validator: value => value >= number + validator: value => value >= number, }); } @@ -54,7 +54,7 @@ export class NumberPredicate extends Predicate { lessThan(number: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be less than ${number}, got ${value}`, - validator: value => value < number + validator: value => value < number, }); } @@ -66,7 +66,7 @@ export class NumberPredicate extends Predicate { lessThanOrEqual(number: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be less than or equal to ${number}, got ${value}`, - validator: value => value <= number + validator: value => value <= number, }); } @@ -78,7 +78,7 @@ export class NumberPredicate extends Predicate { equal(expected: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be equal to ${expected}, got ${value}`, - validator: value => value === expected + validator: value => value === expected, }); } @@ -99,7 +99,7 @@ export class NumberPredicate extends Predicate { return `Expected ${label} to be one of \`${printedList}\`, got ${value}`; }, - validator: value => list.includes(value) + validator: value => list.includes(value), }); } @@ -109,7 +109,7 @@ export class NumberPredicate extends Predicate { get integer(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be an integer, got ${value}`, - validator: value => is.integer(value) + validator: value => is.integer(value), }); } @@ -119,7 +119,7 @@ export class NumberPredicate extends Predicate { get finite(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be finite, got ${value}`, - validator: value => !is.infinite(value) + validator: value => !is.infinite(value), }); } @@ -129,7 +129,7 @@ export class NumberPredicate extends Predicate { get infinite(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be infinite, got ${value}`, - validator: value => is.infinite(value) + validator: value => is.infinite(value), }); } @@ -139,7 +139,7 @@ export class NumberPredicate extends Predicate { get positive(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be positive, got ${value}`, - validator: value => value > 0 + validator: value => value > 0, }); } @@ -149,7 +149,7 @@ export class NumberPredicate extends Predicate { get negative(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be negative, got ${value}`, - validator: value => value < 0 + validator: value => value < 0, }); } @@ -159,7 +159,7 @@ export class NumberPredicate extends Predicate { get integerOrInfinite(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be an integer or infinite, got ${value}`, - validator: value => is.integer(value) || is.infinite(value) + validator: value => is.integer(value) || is.infinite(value), }); } @@ -174,14 +174,14 @@ export class NumberPredicate extends Predicate { Test a number to be in a valid range for a 16-bit unsigned integer. */ get uint16(): this { - return this.integer.inRange(0, 65535); + return this.integer.inRange(0, 65_535); } /** Test a number to be in a valid range for a 32-bit unsigned integer. */ get uint32(): this { - return this.integer.inRange(0, 4294967295); + return this.integer.inRange(0, 4_294_967_295); } /** @@ -195,13 +195,13 @@ export class NumberPredicate extends Predicate { Test a number to be in a valid range for a 16-bit signed integer. */ get int16(): this { - return this.integer.inRange(-32768, 32767); + return this.integer.inRange(-32_768, 32_767); } /** Test a number to be in a valid range for a 32-bit signed integer. */ get int32(): this { - return this.integer.inRange(-2147483648, 2147483647); + return this.integer.inRange(-2_147_483_648, 2_147_483_647); } } diff --git a/source/predicates/object.ts b/source/predicates/object.ts index 844f712..0246f9a 100644 --- a/source/predicates/object.ts +++ b/source/predicates/object.ts @@ -25,7 +25,7 @@ export class ObjectPredicate extends Predicate { get plain(): this { return this.addValidator({ message: (_, label) => `Expected ${label} to be a plain object`, - validator: object => is.plainObject(object) + validator: object => is.plainObject(object), }); } @@ -35,7 +35,7 @@ export class ObjectPredicate extends Predicate { get empty(): this { return this.addValidator({ message: (object, label) => `Expected ${label} to be empty, got \`${JSON.stringify(object)}\``, - validator: object => Object.keys(object).length === 0 + validator: object => Object.keys(object).length === 0, }); } @@ -45,7 +45,7 @@ export class ObjectPredicate extends Predicate { get nonEmpty(): this { return this.addValidator({ message: (_, label) => `Expected ${label} to not be empty`, - validator: object => Object.keys(object).length > 0 + validator: object => Object.keys(object).length > 0, }); } @@ -57,7 +57,7 @@ export class ObjectPredicate extends Predicate { valuesOfType(predicate: BasePredicate): this { return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: object => ofType(Object.values(object), 'values', predicate) + validator: object => ofType(Object.values(object), 'values', predicate), }); } @@ -69,7 +69,7 @@ export class ObjectPredicate extends Predicate { deepValuesOfType(predicate: Predicate): this { return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: object => ofTypeDeep(object, predicate) + validator: object => ofTypeDeep(object, predicate), }); } @@ -81,7 +81,7 @@ export class ObjectPredicate extends Predicate { deepEqual(expected: object): this { return this.addValidator({ message: (object, label) => `Expected ${label} to be deeply equal to \`${JSON.stringify(expected)}\`, got \`${JSON.stringify(object)}\``, - validator: object => isEqual(object, expected) + validator: object => isEqual(object, expected), }); } @@ -101,7 +101,7 @@ export class ObjectPredicate extends Predicate { return `Expected ${label} \`${name}\` to be of type \`${instance.name}\``; }, - validator: object => object instanceof instance + validator: object => object instanceof instance, }); } @@ -115,10 +115,10 @@ export class ObjectPredicate extends Predicate { message: (_, label, missingKeys) => `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``, validator: object => hasItems( { - has: item => dotProp.has(object, item) + has: item => dotProp.has(object, item), }, - keys - ) + keys, + ), }); } @@ -130,7 +130,7 @@ export class ObjectPredicate extends Predicate { hasAnyKeys(...keys: readonly string[]): this { return this.addValidator({ message: (_, label) => `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``, - validator: object => keys.some(key => dotProp.has(object, key)) + validator: object => keys.some(key => dotProp.has(object, key)), }); } @@ -158,8 +158,9 @@ export class ObjectPredicate extends Predicate { partialShape(shape: S): ObjectPredicate> { return this.addValidator({ // TODO: Improve this when message handling becomes smarter + // eslint-disable-next-line @typescript-eslint/no-unsafe-call message: (_, label, message) => `${message.replace('Expected', 'Expected property')} in ${label}`, - validator: object => partial(object, shape) + validator: object => partial(object, shape), }) as unknown as ObjectPredicate>; } @@ -181,10 +182,12 @@ export class ObjectPredicate extends Predicate { */ exactShape(shape: S): ObjectPredicate> { // TODO [typescript@>=5] If higher-kinded types are supported natively by typescript, refactor `addValidator` to use them to avoid the usage of `any`. Otherwise, bump or remove this TODO. + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return this.addValidator({ // TODO: Improve this when message handling becomes smarter + // eslint-disable-next-line @typescript-eslint/no-unsafe-call message: (_, label, message) => `${message.replace('Expected', 'Expected property')} in ${label}`, - validator: object => exact(object, shape) + validator: object => exact(object, shape), }) as ObjectPredicate; } } diff --git a/source/predicates/predicate.ts b/source/predicates/predicate.ts index e8f2414..f90bfc3 100644 --- a/source/predicates/predicate.ts +++ b/source/predicates/predicate.ts @@ -1,9 +1,9 @@ import is from '@sindresorhus/is'; import {ArgumentError} from '../argument-error.js'; import {not} from '../operators/not.js'; -import {BasePredicate, testSymbol} from './base-predicate.js'; import {Main} from '../index.js'; import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js'; +import {BasePredicate, testSymbol} from './base-predicate.js'; /** Function executed when the provided validation fails. @@ -67,16 +67,16 @@ export type CustomValidator = (value: T) => { */ export class Predicate implements BasePredicate { private readonly context: Context = { - validators: [] + validators: [], }; constructor( private readonly type: string, - private readonly options: PredicateOptions = {} + private readonly options: PredicateOptions = {}, ) { this.context = { ...this.context, - ...this.options + ...this.options, }; const typeString = this.type.charAt(0).toLowerCase() + this.type.slice(1); @@ -89,14 +89,15 @@ export class Predicate implements BasePredicate { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing return `Expected ${label_ || 'argument'} to be of type \`${this.type}\` but received type \`${is(value)}\``; }, - validator: value => (is as any)[typeString](value) + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call + validator: value => (is as any)[typeString](value), }); } /** @hidden */ - [testSymbol](value: T, main: Main, label: string | Function, idLabel: boolean): asserts value is T { + [testSymbol](value: T, main: Main, label: string | (() => string), idLabel: boolean): asserts value is T { // Create a map of labels -> received errors. const errors = new Map>(); @@ -121,9 +122,9 @@ export class Predicate implements BasePredicate { const label2 = is.function_(label) ? label() : label; const labelWithTick = (label2 && idLabel) ? `\`${label2}\`` : label2; - const label_ = labelWithTick ? - `${this.type} ${labelWithTick}` : - this.type; + const label_ = labelWithTick + ? `${this.type} ${labelWithTick}` + : this.type; const mapKey = label2 || this.type; @@ -172,9 +173,11 @@ export class Predicate implements BasePredicate { */ validate(customValidator: CustomValidator): this { return this.addValidator({ - message: (_, label, error) => typeof error === 'string' ? - `(${label}) ${error}` : - error(label), + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + message: (_, label, error) => typeof error === 'string' + ? `(${label}) ${error}` + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + : error(label), validator: value => { const {message, validator} = customValidator(value); @@ -183,7 +186,7 @@ export class Predicate implements BasePredicate { } return message; - } + }, }); } @@ -194,11 +197,11 @@ export class Predicate implements BasePredicate { */ is(validator: (value: T) => boolean | string): this { return this.addValidator({ - message: (value, label, error) => (error ? - `(${label}) ${error}` : - `Expected ${label} \`${value}\` to pass custom validation function` + message: (value, label, error) => (error + ? `(${label}) ${error}` + : `Expected ${label} \`${value}\` to pass custom validation function` ), - validator + validator, }); } diff --git a/source/predicates/set.ts b/source/predicates/set.ts index 51e3147..e954b25 100644 --- a/source/predicates/set.ts +++ b/source/predicates/set.ts @@ -19,7 +19,7 @@ export class SetPredicate extends Predicate> { size(size: number): this { return this.addValidator({ message: (set, label) => `Expected ${label} to have size \`${size}\`, got \`${set.size}\``, - validator: set => set.size === size + validator: set => set.size === size, }); } @@ -32,7 +32,7 @@ export class SetPredicate extends Predicate> { return this.addValidator({ message: (set, label) => `Expected ${label} to have a minimum size of \`${size}\`, got \`${set.size}\``, validator: set => set.size >= size, - negatedMessage: (set, label) => `Expected ${label} to have a maximum size of \`${size - 1}\`, got \`${set.size}\`` + negatedMessage: (set, label) => `Expected ${label} to have a maximum size of \`${size - 1}\`, got \`${set.size}\``, }); } @@ -45,7 +45,7 @@ export class SetPredicate extends Predicate> { return this.addValidator({ message: (set, label) => `Expected ${label} to have a maximum size of \`${size}\`, got \`${set.size}\``, validator: set => set.size <= size, - negatedMessage: (set, label) => `Expected ${label} to have a minimum size of \`${size + 1}\`, got \`${set.size}\`` + negatedMessage: (set, label) => `Expected ${label} to have a minimum size of \`${size + 1}\`, got \`${set.size}\``, }); } @@ -57,7 +57,7 @@ export class SetPredicate extends Predicate> { has(...items: readonly T[]): this { return this.addValidator({ message: (_, label, missingItems) => `Expected ${label} to have items \`${JSON.stringify(missingItems)}\``, - validator: set => hasItems(set, items) + validator: set => hasItems(set, items), }); } @@ -69,7 +69,7 @@ export class SetPredicate extends Predicate> { hasAny(...items: readonly T[]): this { return this.addValidator({ message: (_, label) => `Expected ${label} to have any item of \`${JSON.stringify(items)}\``, - validator: set => items.some(item => set.has(item)) + validator: set => items.some(item => set.has(item)), }); } @@ -81,7 +81,7 @@ export class SetPredicate extends Predicate> { ofType(predicate: Predicate): this { return this.addValidator({ message: (_, label, error) => `(${label}) ${error}`, - validator: set => ofType(set, 'values', predicate) + validator: set => ofType(set, 'values', predicate), }); } @@ -91,7 +91,7 @@ export class SetPredicate extends Predicate> { get empty(): this { return this.addValidator({ message: (set, label) => `Expected ${label} to be empty, got \`${JSON.stringify([...set])}\``, - validator: set => set.size === 0 + validator: set => set.size === 0, }); } @@ -101,7 +101,7 @@ export class SetPredicate extends Predicate> { get nonEmpty(): this { return this.addValidator({ message: (_, label) => `Expected ${label} to not be empty`, - validator: set => set.size > 0 + validator: set => set.size > 0, }); } @@ -113,7 +113,7 @@ export class SetPredicate extends Predicate> { deepEqual(expected: Set): this { return this.addValidator({ message: (set, label) => `Expected ${label} to be deeply equal to \`${JSON.stringify([...expected])}\`, got \`${JSON.stringify([...set])}\``, - validator: set => isEqual(set, expected) + validator: set => isEqual(set, expected), }); } } diff --git a/source/predicates/string.ts b/source/predicates/string.ts index 2e5343d..8ebd8a3 100644 --- a/source/predicates/string.ts +++ b/source/predicates/string.ts @@ -18,7 +18,7 @@ export class StringPredicate extends Predicate { length(length: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to have length \`${length}\`, got \`${value}\``, - validator: value => value.length === length + validator: value => value.length === length, }); } @@ -31,7 +31,7 @@ export class StringPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a minimum length of \`${length}\`, got \`${value}\``, validator: value => value.length >= length, - negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value}\``, }); } @@ -44,7 +44,7 @@ export class StringPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a maximum length of \`${length}\`, got \`${value}\``, validator: value => value.length <= length, - negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value}\``, }); } @@ -56,7 +56,7 @@ export class StringPredicate extends Predicate { matches(regex: RegExp): this { return this.addValidator({ message: (value, label) => `Expected ${label} to match \`${regex}\`, got \`${value}\``, - validator: value => regex.test(value) + validator: value => regex.test(value), }); } @@ -68,7 +68,7 @@ export class StringPredicate extends Predicate { startsWith(searchString: string): this { return this.addValidator({ message: (value, label) => `Expected ${label} to start with \`${searchString}\`, got \`${value}\``, - validator: value => value.startsWith(searchString) + validator: value => value.startsWith(searchString), }); } @@ -80,7 +80,7 @@ export class StringPredicate extends Predicate { endsWith(searchString: string): this { return this.addValidator({ message: (value, label) => `Expected ${label} to end with \`${searchString}\`, got \`${value}\``, - validator: value => value.endsWith(searchString) + validator: value => value.endsWith(searchString), }); } @@ -92,7 +92,7 @@ export class StringPredicate extends Predicate { includes(searchString: string): this { return this.addValidator({ message: (value, label) => `Expected ${label} to include \`${searchString}\`, got \`${value}\``, - validator: value => value.includes(searchString) + validator: value => value.includes(searchString), }); } @@ -113,7 +113,7 @@ export class StringPredicate extends Predicate { return `Expected ${label} to be one of \`${printedList}\`, got \`${value}\``; }, - validator: value => list.includes(value) + validator: value => list.includes(value), }); } @@ -123,7 +123,7 @@ export class StringPredicate extends Predicate { get empty(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be empty, got \`${value}\``, - validator: value => value === '' + validator: value => value === '', }); } @@ -133,7 +133,7 @@ export class StringPredicate extends Predicate { get nonEmpty(): this { return this.addValidator({ message: (_, label) => `Expected ${label} to not be empty`, - validator: value => value !== '' + validator: value => value !== '', }); } @@ -145,7 +145,7 @@ export class StringPredicate extends Predicate { equals(expected: string): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be equal to \`${expected}\`, got \`${value}\``, - validator: value => value === expected + validator: value => value === expected, }); } @@ -155,7 +155,7 @@ export class StringPredicate extends Predicate { get alphanumeric(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be alphanumeric, got \`${value}\``, - validator: value => /^[a-z\d]+$/i.test(value) + validator: value => /^[a-z\d]+$/i.test(value), }); } @@ -165,7 +165,7 @@ export class StringPredicate extends Predicate { get alphabetical(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be alphabetical, got \`${value}\``, - validator: value => /^[a-z]+$/gi.test(value) + validator: value => /^[a-z]+$/gi.test(value), }); } @@ -175,7 +175,7 @@ export class StringPredicate extends Predicate { get numeric(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be numeric, got \`${value}\``, - validator: value => /^[+-]?\d+$/i.test(value) + validator: value => /^[+-]?\d+$/i.test(value), }); } @@ -185,7 +185,7 @@ export class StringPredicate extends Predicate { get date(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be a date, got \`${value}\``, - validator: valiDate + validator: valiDate, }); } @@ -195,7 +195,7 @@ export class StringPredicate extends Predicate { get lowercase(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be lowercase, got \`${value}\``, - validator: value => value.trim() !== '' && value === value.toLowerCase() + validator: value => value.trim() !== '' && value === value.toLowerCase(), }); } @@ -205,7 +205,7 @@ export class StringPredicate extends Predicate { get uppercase(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be uppercase, got \`${value}\``, - validator: value => value.trim() !== '' && value === value.toUpperCase() + validator: value => value.trim() !== '' && value === value.toUpperCase(), }); } @@ -215,7 +215,7 @@ export class StringPredicate extends Predicate { get url(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be a URL, got \`${value}\``, - validator: is.urlString + validator: is.urlString, }); } } diff --git a/source/predicates/typed-array.ts b/source/predicates/typed-array.ts index cf54bce..77ae701 100644 --- a/source/predicates/typed-array.ts +++ b/source/predicates/typed-array.ts @@ -10,7 +10,7 @@ export class TypedArrayPredicate extends Predicate { byteLength(byteLength: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to have byte length of \`${byteLength}\`, got \`${value.byteLength}\``, - validator: value => value.byteLength === byteLength + validator: value => value.byteLength === byteLength, }); } @@ -23,7 +23,7 @@ export class TypedArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength >= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength - 1}\`, got \`${value.byteLength}\``, }); } @@ -36,7 +36,7 @@ export class TypedArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a maximum byte length of \`${byteLength}\`, got \`${value.byteLength}\``, validator: value => value.byteLength <= byteLength, - negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum byte length of \`${byteLength + 1}\`, got \`${value.byteLength}\``, }); } @@ -48,7 +48,7 @@ export class TypedArrayPredicate extends Predicate { length(length: number): this { return this.addValidator({ message: (value, label) => `Expected ${label} to have length \`${length}\`, got \`${value.length}\``, - validator: value => value.length === length + validator: value => value.length === length, }); } @@ -61,7 +61,7 @@ export class TypedArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a minimum length of \`${length}\`, got \`${value.length}\``, validator: value => value.length >= length, - negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value.length}\`` + negatedMessage: (value, label) => `Expected ${label} to have a maximum length of \`${length - 1}\`, got \`${value.length}\``, }); } @@ -74,7 +74,7 @@ export class TypedArrayPredicate extends Predicate { return this.addValidator({ message: (value, label) => `Expected ${label} to have a maximum length of \`${length}\`, got \`${value.length}\``, validator: value => value.length <= length, - negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value.length}\`` + negatedMessage: (value, label) => `Expected ${label} to have a minimum length of \`${length + 1}\`, got \`${value.length}\``, }); } } diff --git a/source/predicates/weak-map.ts b/source/predicates/weak-map.ts index eae4348..896612f 100644 --- a/source/predicates/weak-map.ts +++ b/source/predicates/weak-map.ts @@ -17,7 +17,7 @@ export class WeakMapPredicate extends Predicate hasKeys(...keys: readonly KeyType[]): this { return this.addValidator({ message: (_, label, missingKeys) => `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``, - validator: map => hasItems(map, keys) + validator: map => hasItems(map, keys), }); } @@ -29,7 +29,7 @@ export class WeakMapPredicate extends Predicate hasAnyKeys(...keys: readonly KeyType[]): this { return this.addValidator({ message: (_, label) => `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``, - validator: map => keys.some(key => map.has(key)) + validator: map => keys.some(key => map.has(key)), }); } } diff --git a/source/predicates/weak-set.ts b/source/predicates/weak-set.ts index 1685b2e..5a8d224 100644 --- a/source/predicates/weak-set.ts +++ b/source/predicates/weak-set.ts @@ -17,7 +17,7 @@ export class WeakSetPredicate extends Predicate `Expected ${label} to have items \`${JSON.stringify(missingItems)}\``, - validator: set => hasItems(set, items) + validator: set => hasItems(set, items), }); } @@ -29,7 +29,7 @@ export class WeakSetPredicate extends Predicate `Expected ${label} to have any item of \`${JSON.stringify(items)}\``, - validator: set => items.some(item => set.has(item)) + validator: set => items.some(item => set.has(item)), }); } } diff --git a/source/utils/has-items.ts b/source/utils/has-items.ts index 3df1b4e..f3267a8 100644 --- a/source/utils/has-items.ts +++ b/source/utils/has-items.ts @@ -14,7 +14,7 @@ Retrieve the missing values in a collection based on an array of items. @param items - Items to search for. @param maxValues - Maximum number of values after the search process is stopped. Default: 5. */ -export default (source: CollectionLike, items: readonly T[], maxValues = 5): true | T[] => { +const hasItems = (source: CollectionLike, items: readonly T[], maxValues = 5): true | T[] => { const missingValues: T[] = []; for (const value of items) { @@ -31,3 +31,5 @@ export default (source: CollectionLike, items: readonly T[], maxValues = 5 return missingValues.length === 0 ? true : missingValues; }; + +export default hasItems; diff --git a/source/utils/infer-label.ts b/source/utils/infer-label.ts index 6496d07..ccc37ed 100644 --- a/source/utils/infer-label.ts +++ b/source/utils/infer-label.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import * as fs from 'node:fs'; import {CallSite} from 'callsites'; import isValidIdentifier from './is-valid-identifier.js'; import isNode from './node/is-node.js'; diff --git a/source/utils/is-valid-identifier.ts b/source/utils/is-valid-identifier.ts index efaee30..1f55286 100644 --- a/source/utils/is-valid-identifier.ts +++ b/source/utils/is-valid-identifier.ts @@ -8,7 +8,7 @@ const reservedSet = new Set([ 'super', 'this', 'Infinity', - 'NaN' + 'NaN', ]); /** @@ -16,4 +16,6 @@ Test if the string is a valid JavaScript identifier. @param string - String to test. */ -export default (string: string | undefined): string | boolean | undefined => string && !reservedSet.has(string) && identifierRegex.test(string); +const isValidIdentifier = (string: string | undefined): string | boolean | undefined => string && !reservedSet.has(string) && identifierRegex.test(string); + +export default isValidIdentifier; diff --git a/source/utils/node/is-node.ts b/source/utils/node/is-node.ts index 6a1e87d..7bc54a9 100644 --- a/source/utils/node/is-node.ts +++ b/source/utils/node/is-node.ts @@ -1 +1,2 @@ +// eslint-disable-next-line node/prefer-global/process export default Boolean(process?.versions?.node); diff --git a/source/utils/of-type-deep.ts b/source/utils/of-type-deep.ts index 46f2c69..70c9311 100644 --- a/source/utils/of-type-deep.ts +++ b/source/utils/of-type-deep.ts @@ -18,10 +18,12 @@ Test all the values in the object against a provided predicate. @param predicate - Predicate to test every value in the given object against. */ -export default (object: unknown, predicate: Predicate): boolean | string => { +const ofTypeDeepSafe = (object: unknown, predicate: Predicate): boolean | string => { try { return ofTypeDeep(object, predicate); } catch (error: unknown) { return (error as Error).message; } }; + +export default ofTypeDeepSafe; diff --git a/source/utils/of-type.ts b/source/utils/of-type.ts index 57b7342..e622915 100644 --- a/source/utils/of-type.ts +++ b/source/utils/of-type.ts @@ -9,7 +9,7 @@ Test all the values in the collection against a provided predicate. @param name The name to call the collection of values, such as `values` or `keys`. @param predicate Predicate to test every item in the source collection against. */ -export default (source: IterableIterator | Set | T[], name: string, predicate: BasePredicate): boolean | string => { +const ofType = (source: IterableIterator | Set | T[], name: string, predicate: BasePredicate): boolean | string => { try { for (const item of source) { test(item, name, predicate, false); @@ -20,3 +20,5 @@ export default (source: IterableIterator | Set | T[], name: string, pre return (error as Error).message; } }; + +export default ofType; diff --git a/source/utils/random-id.ts b/source/utils/random-id.ts index 0996af5..01656f5 100644 --- a/source/utils/random-id.ts +++ b/source/utils/random-id.ts @@ -1 +1,3 @@ -export default (): string => Math.random().toString(16).slice(2); +const randomId = (): string => Math.random().toString(16).slice(2); + +export default randomId; diff --git a/test/any-multiple-errors.ts b/test/any-multiple-errors.ts index fa4db72..c0f2def 100644 --- a/test/any-multiple-errors.ts +++ b/test/any-multiple-errors.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import test from 'ava'; import ow, {ArgumentError, BasePredicate, Main} from '../source'; import {testSymbol} from '../source/predicates/base-predicate'; @@ -8,7 +9,7 @@ test('any predicate', t => { const error_1 = t.throws(() => { ow(5 as any, ow.any(ow.string)); }, { - message: createAnyError('Expected argument to be of type `string` but received type `number`') + message: createAnyError('Expected argument to be of type `string` but received type `number`'), }); t.is(error_1.validationErrors.size, 1, 'There should be only one error'); @@ -17,7 +18,7 @@ test('any predicate', t => { t.is(reportedError_1_1.size, 1, 'There should be only one element'); t.deepEqual(reportedError_1_1, new Set([ - 'Expected argument to be of type `string` but received type `number`' + 'Expected argument to be of type `string` but received type `number`', ])); // #endregion @@ -26,7 +27,7 @@ test('any predicate', t => { const error_2 = t.throws(() => { ow(21 as any, ow.any( ow.string.url.minLength(24), - ow.number.greaterThan(42) + ow.number.greaterThan(42), )); }, { @@ -35,13 +36,13 @@ test('any predicate', t => { [ 'Expected argument to be of type `string` but received type `number`', 'Expected string to be a URL, got `21`', - 'Expected string to have a minimum length of `24`, got `21`' - ] + 'Expected string to have a minimum length of `24`, got `21`', + ], ], [ 'number', - ['Expected number to be greater than 42, got 21'] - ]) -}); + ['Expected number to be greater than 42, got 21'], + ]), + }); t.is(error_2.validationErrors.size, 2, 'There should be two types of errors reported'); @@ -54,11 +55,11 @@ test('any predicate', t => { t.deepEqual(reportedError_2_1, new Set([ 'Expected argument to be of type `string` but received type `number`', 'Expected string to be a URL, got `21`', - 'Expected string to have a minimum length of `24`, got `21`' + 'Expected string to have a minimum length of `24`, got `21`', ])); t.deepEqual(reportedError_2_2, new Set([ - 'Expected number to be greater than 42, got 21' + 'Expected number to be greater than 42, got 21', ])); // #endregion @@ -67,13 +68,13 @@ test('any predicate', t => { const error_3 = t.throws(() => { ow(null as any, ow.any( ow.string, - ow.number + ow.number, )); }, { message: createAnyError( 'Expected argument to be of type `string` but received type `null`', - 'Expected argument to be of type `number` but received type `null`' - ) + 'Expected argument to be of type `number` but received type `null`', + ), }); t.is(error_3.validationErrors.size, 2, 'There should be two types of errors reported'); @@ -85,24 +86,24 @@ test('any predicate', t => { t.is(reportedError_3_2.size, 1, 'There should be one error reported for the number predicate'); t.deepEqual(reportedError_3_1, new Set([ - 'Expected argument to be of type `string` but received type `null`' + 'Expected argument to be of type `string` but received type `null`', ])); t.deepEqual(reportedError_3_2, new Set([ - 'Expected argument to be of type `number` but received type `null`' + 'Expected argument to be of type `number` but received type `null`', ])); const error_4 = t.throws(() => { ow(21 as any, ow.any( ow.string.url.minLength(21), - ow.string.url.minLength(42) + ow.string.url.minLength(42), )); }, { message: createAnyError( 'Expected argument to be of type `string` but received type `number`', 'Expected string to be a URL, got `21`', 'Expected string to have a minimum length of `21`, got `21`', - 'Expected string to have a minimum length of `42`, got `21`' - ) + 'Expected string to have a minimum length of `42`, got `21`', + ), }); t.is(error_4.validationErrors.size, 1, 'There should be one type of error reported'); @@ -115,7 +116,7 @@ test('any predicate', t => { 'Expected argument to be of type `string` but received type `number`', 'Expected string to be a URL, got `21`', 'Expected string to have a minimum length of `21`, got `21`', - 'Expected string to have a minimum length of `42`, got `21`' + 'Expected string to have a minimum length of `42`, got `21`', ])); // #endregion diff --git a/test/any.ts b/test/any.ts index 23ccff2..ec08715 100644 --- a/test/any.ts +++ b/test/any.ts @@ -22,7 +22,7 @@ test('any', t => { t.throws(() => { ow(1 as any, ow.any(ow.string)); }, { - message: createAnyError('Expected argument to be of type `string` but received type `number`') + message: createAnyError('Expected argument to be of type `string` but received type `number`'), }); t.throws(() => { @@ -30,8 +30,8 @@ test('any', t => { }, { message: createAnyError( 'Expected argument to be of type `number` but received type `boolean`', - 'Expected argument to be of type `string` but received type `boolean`' - ) + 'Expected argument to be of type `string` but received type `boolean`', + ), }); }); diff --git a/test/array-buffer.ts b/test/array-buffer.ts index 0357b54..8c48fd6 100644 --- a/test/array-buffer.ts +++ b/test/array-buffer.ts @@ -12,15 +12,15 @@ test('arrayBuffer', t => { t.throws(() => { ow('foo' as any, ow.arrayBuffer); - }, { message: 'Expected argument to be of type `ArrayBuffer` but received type `string`' }); + }, {message: 'Expected argument to be of type `ArrayBuffer` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.arrayBuffer); - }, { message: 'Expected `foo` to be of type `ArrayBuffer` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `ArrayBuffer` but received type `string`'}); t.throws(() => { ow(12 as any, ow.arrayBuffer); - }, { message: 'Expected argument to be of type `ArrayBuffer` but received type `number`' }); + }, {message: 'Expected argument to be of type `ArrayBuffer` but received type `number`'}); }); test('arrayBuffer.byteLength', t => { @@ -34,11 +34,11 @@ test('arrayBuffer.byteLength', t => { t.throws(() => { ow(new ArrayBuffer(1), ow.arrayBuffer.byteLength(2)); - }, { message: 'Expected ArrayBuffer to have byte length of `2`, got `1`' }); + }, {message: 'Expected ArrayBuffer to have byte length of `2`, got `1`'}); t.throws(() => { ow(new ArrayBuffer(1), 'foo', ow.arrayBuffer.byteLength(2)); - }, { message: 'Expected ArrayBuffer `foo` to have byte length of `2`, got `1`' }); + }, {message: 'Expected ArrayBuffer `foo` to have byte length of `2`, got `1`'}); }); test('arrayBuffer.minByteLength', t => { @@ -52,7 +52,7 @@ test('arrayBuffer.minByteLength', t => { t.throws(() => { ow(new ArrayBuffer(1), ow.arrayBuffer.minByteLength(2)); - }, { message: 'Expected ArrayBuffer to have a minimum byte length of `2`, got `1`' }); + }, {message: 'Expected ArrayBuffer to have a minimum byte length of `2`, got `1`'}); }); test('arrayBuffer.maxByteLength', t => { @@ -66,5 +66,5 @@ test('arrayBuffer.maxByteLength', t => { t.throws(() => { ow(new ArrayBuffer(2), ow.arrayBuffer.maxByteLength(1)); - }, { message: 'Expected ArrayBuffer to have a maximum byte length of `1`, got `2`' }); + }, {message: 'Expected ArrayBuffer to have a maximum byte length of `1`, got `2`'}); }); diff --git a/test/array.ts b/test/array.ts index 7042b9b..3c5c7d9 100644 --- a/test/array.ts +++ b/test/array.ts @@ -12,11 +12,11 @@ test('array', t => { t.throws(() => { ow('12' as any, ow.array); - }, { message: 'Expected argument to be of type `array` but received type `string`' }); + }, {message: 'Expected argument to be of type `array` but received type `string`'}); t.throws(() => { ow('12' as any, 'foo', ow.array); - }, { message: 'Expected `foo` to be of type `array` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `array` but received type `string`'}); }); test('array.length', t => { @@ -30,11 +30,11 @@ test('array.length', t => { t.throws(() => { ow(['foo'], ow.array.length(2)); - }, { message: 'Expected array to have length `2`, got `1`' }); + }, {message: 'Expected array to have length `2`, got `1`'}); t.throws(() => { ow(['foo'], 'foo', ow.array.length(2)); - }, { message: 'Expected array `foo` to have length `2`, got `1`' }); + }, {message: 'Expected array `foo` to have length `2`, got `1`'}); }); test('array.minLength', t => { @@ -48,7 +48,7 @@ test('array.minLength', t => { t.throws(() => { ow(['foo'], ow.array.minLength(2)); - }, { message: 'Expected array to have a minimum length of `2`, got `1`' }); + }, {message: 'Expected array to have a minimum length of `2`, got `1`'}); }); test('array.maxLength', t => { @@ -62,7 +62,7 @@ test('array.maxLength', t => { t.throws(() => { ow(['foo', 'bar'], ow.array.maxLength(1)); - }, { message: 'Expected array to have a maximum length of `1`, got `2`' }); + }, {message: 'Expected array to have a maximum length of `1`, got `2`'}); }); test('array.startsWith', t => { @@ -72,7 +72,7 @@ test('array.startsWith', t => { t.throws(() => { ow(['foo', 'bar'], ow.array.startsWith('bar')); - }, { message: 'Expected array to start with `bar`, got `foo`' }); + }, {message: 'Expected array to start with `bar`, got `foo`'}); }); test('array.endsWith', t => { @@ -82,7 +82,7 @@ test('array.endsWith', t => { t.throws(() => { ow(['foo', 'bar'], ow.array.endsWith('foo')); - }, { message: 'Expected array to end with `foo`, got `bar`' }); + }, {message: 'Expected array to end with `foo`, got `bar`'}); }); test('array.includes', t => { @@ -96,7 +96,7 @@ test('array.includes', t => { t.throws(() => { ow(['foo', 'bar'], ow.array.includes('foo', 'unicorn')); - }, { message: 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`' }); + }, {message: 'Expected array to include all elements of `["foo","unicorn"]`, got `["foo","bar"]`'}); }); test('array.includesAny', t => { @@ -110,7 +110,7 @@ test('array.includesAny', t => { t.throws(() => { ow(['foo', 'bar'], ow.array.includesAny('unicorn')); - }, { message: 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`' }); + }, {message: 'Expected array to include any element of `["unicorn"]`, got `["foo","bar"]`'}); }); test('array.empty', t => { @@ -120,7 +120,7 @@ test('array.empty', t => { t.throws(() => { ow(['foo'], ow.array.empty); - }, { message: 'Expected array to be empty, got `["foo"]`' }); + }, {message: 'Expected array to be empty, got `["foo"]`'}); }); test('array.nonEmpty', t => { @@ -130,7 +130,7 @@ test('array.nonEmpty', t => { t.throws(() => { ow([], ow.array.nonEmpty); - }, { message: 'Expected array to not be empty' }); + }, {message: 'Expected array to not be empty'}); }); test('array.deepEqual', t => { @@ -144,7 +144,7 @@ test('array.deepEqual', t => { t.throws(() => { ow(['foo', {id: 1}], ow.array.deepEqual(['foo', {id: 2}])); - }, { message: 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`' }); + }, {message: 'Expected array to be deeply equal to `["foo",{"id":2}]`, got `["foo",{"id":1}]`'}); }); test('array.ofType', t => { @@ -162,19 +162,19 @@ test('array.ofType', t => { t.throws(() => { ow(['foo', 'b'], ow.array.ofType(ow.string.minLength(3))); - }, { message: '(array) Expected string values to have a minimum length of `3`, got `b`' }); + }, {message: '(array) Expected string values to have a minimum length of `3`, got `b`'}); t.throws(() => { ow(['foo', 'b'], 'foo', ow.array.ofType(ow.string.minLength(3))); - }, { message: '(array `foo`) Expected string values to have a minimum length of `3`, got `b`' }); + }, {message: '(array `foo`) Expected string values to have a minimum length of `3`, got `b`'}); t.throws(() => { ow(['foo', 'bar'], 'foo', ow.array.ofType(ow.number)); - }, { message: '(array `foo`) Expected values to be of type `number` but received type `string`' }); + }, {message: '(array `foo`) Expected values to be of type `number` but received type `string`'}); t.throws(() => { ow([1, -1], 'foo', ow.array.ofType(ow.number.not.negative)); - }, { message: '(array `foo`) Expected number values to not be negative, got -1' }); + }, {message: '(array `foo`) Expected number values to not be negative, got -1'}); }); test('array.exactShape', t => { @@ -184,13 +184,13 @@ test('array.exactShape', t => { t.throws(() => { ow(['🦄', 2, 'nope', true, {isFirstCommit: true}], ow.array.exactShape([ow.string, ow.number, ow.number, ow.boolean, ow.object.exactShape({isFirstCommit: ow.string})])); - }, { message: 'Expected element `2` to be of type `number` but received type `string` in array' }); + }, {message: 'Expected element `2` to be of type `number` but received type `string` in array'}); t.throws(() => { ow(['🦄', 'nope', {isFirstCommit: true}], ow.array.exactShape([ow.string, ow.string, ow.object.exactShape({isFirstCommit: ow.boolean}), ow.number, ow.boolean])); - }, { message: 'Expected element `3` to be of type `number` but received type `undefined` in array' }); + }, {message: 'Expected element `3` to be of type `number` but received type `undefined` in array'}); t.throws(() => { - ow(['🦄', {isFirstCommit: true}, 'nope', 5, {accepted: false}], ow.array.exactShape([ow.string, ow.object.exactShape({isFirstCommit: ow.boolean}), ow.string])); - }, { message: 'Did not expect element `3` to exist, got `5` in array' }); + ow(['🦄', {isFirstCommit: true}, 'nope', 5, {accepted: false}], ow.array.exactShape([ow.string, ow.object.exactShape({isFirstCommit: ow.boolean}), ow.string])); + }, {message: 'Did not expect element `3` to exist, got `5` in array'}); }); diff --git a/test/bigint.ts b/test/bigint.ts index 267fc45..2dfaf4c 100644 --- a/test/bigint.ts +++ b/test/bigint.ts @@ -3,7 +3,7 @@ import ow from '../source'; test('bigint', t => { t.notThrows(() => { - ow(BigInt(9007199254740991), ow.bigint); + ow(BigInt(9_007_199_254_740_991), ow.bigint); }); // TODO: Enable when targeting Node.js 14. @@ -13,5 +13,5 @@ test('bigint', t => { t.throws(() => { ow(10, ow.bigint); - }, { message: 'Expected argument to be of type `bigint` but received type `number`' }); + }, {message: 'Expected argument to be of type `bigint` but received type `number`'}); }); diff --git a/test/boolean.ts b/test/boolean.ts index 79bf556..fe7670e 100644 --- a/test/boolean.ts +++ b/test/boolean.ts @@ -7,10 +7,10 @@ test('boolean', t => { }); t.throws(() => { ow('12' as any, ow.boolean); - }, { message: 'Expected argument to be of type `boolean` but received type `string`' }); + }, {message: 'Expected argument to be of type `boolean` but received type `string`'}); t.throws(() => { ow('12' as any, 'foo', ow.boolean); - }, { message: 'Expected `foo` to be of type `boolean` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `boolean` but received type `string`'}); }); test('boolean.true', t => { @@ -28,15 +28,15 @@ test('boolean.true', t => { t.throws(() => { ow(false, ow.boolean.true); - }, { message: 'Expected boolean to be true, got false' }); + }, {message: 'Expected boolean to be true, got false'}); t.throws(() => { ow(false, 'foo', ow.boolean.true); - }, { message: 'Expected boolean `foo` to be true, got false' }); + }, {message: 'Expected boolean `foo` to be true, got false'}); t.throws(() => { ow(Boolean(0), ow.boolean.true); - }, { message: 'Expected boolean to be true, got false' }); + }, {message: 'Expected boolean to be true, got false'}); }); test('boolean.false', t => { @@ -54,9 +54,9 @@ test('boolean.false', t => { t.throws(() => { ow(true, ow.boolean.false); - }, { message: 'Expected boolean to be false, got true' }); + }, {message: 'Expected boolean to be false, got true'}); t.throws(() => { ow(Boolean(1), ow.boolean.false); - }, { message: 'Expected boolean to be false, got true' }); + }, {message: 'Expected boolean to be false, got true'}); }); diff --git a/test/buffer.ts b/test/buffer.ts index c619984..dad29be 100644 --- a/test/buffer.ts +++ b/test/buffer.ts @@ -1,3 +1,4 @@ +import {Buffer} from 'node:buffer'; import test from 'ava'; import ow from '../source'; @@ -12,13 +13,13 @@ test('buffer', t => { t.throws(() => { ow('foo' as any, ow.buffer); - }, { message: 'Expected argument to be of type `Buffer` but received type `string`' }); + }, {message: 'Expected argument to be of type `Buffer` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.buffer); - }, { message: 'Expected `foo` to be of type `Buffer` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `Buffer` but received type `string`'}); t.throws(() => { ow(12 as any, ow.buffer); - }, { message: 'Expected argument to be of type `Buffer` but received type `number`' }); + }, {message: 'Expected argument to be of type `Buffer` but received type `number`'}); }); diff --git a/test/custom-message.ts b/test/custom-message.ts index d482c57..5f3127a 100644 --- a/test/custom-message.ts +++ b/test/custom-message.ts @@ -9,7 +9,7 @@ class CustomPredicate extends Predicate { get unicorn(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be \`🦄\`, got \`${value}\``, - validator: value => value === '🦄' + validator: value => value === '🦄', }); } } @@ -17,23 +17,23 @@ class CustomPredicate extends Predicate { test('custom validate message', t => { t.throws(() => { ow('🌈', 'unicorn', new CustomPredicate().unicorn.message('Expect unicorn, got rainbow')); - }, { message: 'Expect unicorn, got rainbow' }); + }, {message: 'Expect unicorn, got rainbow'}); t.throws(() => { ow('🌈', 'unicorn', new CustomPredicate().unicorn.message((value, label) => `Expected ${label}, to be \`🦄\` got \`${value}\``)); - }, { message: 'Expected string `unicorn`, to be `🦄` got `🌈`' }); + }, {message: 'Expected string `unicorn`, to be `🦄` got `🌈`'}); t.throws(() => { ow('🌈', ow.string.minLength(5).message((value, label) => `Expected ${label}, to be have a minimum length of 5, got \`${value}\``)); - }, { message: 'Expected string, to be have a minimum length of 5, got `🌈`' }); + }, {message: 'Expected string, to be have a minimum length of 5, got `🌈`'}); const error = t.throws(() => { ow('1234', ow.string.minLength(5).message((value, label) => `Expected ${label}, to be have a minimum length of 5, got \`${value}\``).url.message('This is no url')); }, { message: [ 'Expected string, to be have a minimum length of 5, got `1234`', - 'This is no url' - ].join('\n') + 'This is no url', + ].join('\n'), }); t.is(error.validationErrors.size, 1, 'There is one item in the `validationErrors` map'); @@ -44,10 +44,10 @@ test('custom validate message', t => { t.is(result1_.size, 2, 'There are two reported errors for this input'); t.deepEqual(result1_, new Set([ 'Expected string, to be have a minimum length of 5, got `1234`', - 'This is no url' + 'This is no url', ]), 'There is an error for the string length, and one for invalid URL'); t.throws(() => { ow('12345', ow.string.minLength(5).message((value, label) => `Expected ${label}, to be have a minimum length of 5, got \`${value}\``).url.message('This is no url')); - }, { message: 'This is no url' }); + }, {message: 'This is no url'}); }); diff --git a/test/custom-predicate.ts b/test/custom-predicate.ts index 1d0d5b3..2794c81 100644 --- a/test/custom-predicate.ts +++ b/test/custom-predicate.ts @@ -9,7 +9,7 @@ class CustomPredicate extends Predicate { get unicorn(): this { return this.addValidator({ message: (value, label) => `Expected ${label} to be \`🦄\`, got \`${value}\``, - validator: value => value === '🦄' + validator: value => value === '🦄', }); } } @@ -23,5 +23,5 @@ test('custom predicates', t => { t.throws(() => { ow('🌈', 'unicorn', custom.unicorn); - }, { message: 'Expected string `unicorn` to be `🦄`, got `🌈`' }); + }, {message: 'Expected string `unicorn` to be `🦄`, got `🌈`'}); }); diff --git a/test/data-view.ts b/test/data-view.ts index 54c5e7c..eed40f6 100644 --- a/test/data-view.ts +++ b/test/data-view.ts @@ -8,15 +8,15 @@ test('dataView', t => { t.throws(() => { ow(new ArrayBuffer(1) as any, ow.dataView); - }, { message: 'Expected argument to be of type `DataView` but received type `ArrayBuffer`' }); + }, {message: 'Expected argument to be of type `DataView` but received type `ArrayBuffer`'}); t.throws(() => { ow(new ArrayBuffer(1) as any, 'data', ow.dataView); - }, { message: 'Expected `data` to be of type `DataView` but received type `ArrayBuffer`' }); + }, {message: 'Expected `data` to be of type `DataView` but received type `ArrayBuffer`'}); t.throws(() => { ow(12 as any, ow.dataView); - }, { message: 'Expected argument to be of type `DataView` but received type `number`' }); + }, {message: 'Expected argument to be of type `DataView` but received type `number`'}); }); test('dataView.byteLength', t => { @@ -30,11 +30,11 @@ test('dataView.byteLength', t => { t.throws(() => { ow(new DataView(new ArrayBuffer(1)), ow.dataView.byteLength(2)); - }, { message: 'Expected DataView to have byte length of `2`, got `1`' }); + }, {message: 'Expected DataView to have byte length of `2`, got `1`'}); t.throws(() => { ow(new DataView(new ArrayBuffer(1)), 'foo', ow.dataView.byteLength(2)); - }, { message: 'Expected DataView `foo` to have byte length of `2`, got `1`' }); + }, {message: 'Expected DataView `foo` to have byte length of `2`, got `1`'}); }); test('dataView.minByteLength', t => { @@ -48,7 +48,7 @@ test('dataView.minByteLength', t => { t.throws(() => { ow(new DataView(new ArrayBuffer(1)), ow.dataView.minByteLength(2)); - }, { message: 'Expected DataView to have a minimum byte length of `2`, got `1`' }); + }, {message: 'Expected DataView to have a minimum byte length of `2`, got `1`'}); }); test('dataView.maxByteLength', t => { @@ -62,5 +62,5 @@ test('dataView.maxByteLength', t => { t.throws(() => { ow(new DataView(new ArrayBuffer(2)), ow.dataView.maxByteLength(1)); - }, { message: 'Expected DataView to have a maximum byte length of `1`, got `2`' }); + }, {message: 'Expected DataView to have a maximum byte length of `1`, got `2`'}); }); diff --git a/test/date.ts b/test/date.ts index ad438c5..0ad88b5 100644 --- a/test/date.ts +++ b/test/date.ts @@ -8,11 +8,11 @@ test('date', t => { t.throws(() => { ow('12' as any, ow.date); - }, { message: 'Expected argument to be of type `date` but received type `string`' }); + }, {message: 'Expected argument to be of type `date` but received type `string`'}); t.throws(() => { ow('12' as any, 'foo', ow.date); - }, { message: 'Expected `foo` to be of type `date` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `date` but received type `string`'}); }); test('date.before', t => { @@ -26,11 +26,11 @@ test('date.before', t => { t.throws(() => { ow(new Date('2017-11-25T12:00:00Z') as any, ow.date.before(new Date('2017-11-25T12:00:00Z'))); - }, { message: 'Expected date 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z' }); + }, {message: 'Expected date 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'}); t.throws(() => { ow(new Date('2017-11-25T12:00:00Z') as any, 'foo', ow.date.before(new Date('2017-11-25T12:00:00Z'))); - }, { message: 'Expected date `foo` 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z' }); + }, {message: 'Expected date `foo` 2017-11-25T12:00:00.000Z to be before 2017-11-25T12:00:00.000Z'}); }); test('date.after', t => { @@ -44,5 +44,5 @@ test('date.after', t => { t.throws(() => { ow(new Date('2017-11-26T12:00:00Z') as any, ow.date.after(new Date('2017-11-26T12:00:00Z'))); - }, { message: 'Expected date 2017-11-26T12:00:00.000Z to be after 2017-11-26T12:00:00.000Z' }); + }, {message: 'Expected date 2017-11-26T12:00:00.000Z to be after 2017-11-26T12:00:00.000Z'}); }); diff --git a/test/error.ts b/test/error.ts index f18848a..4904516 100644 --- a/test/error.ts +++ b/test/error.ts @@ -15,11 +15,11 @@ test('error', t => { t.throws(() => { ow('12' as any, ow.error); - }, { message: 'Expected argument to be of type `error` but received type `string`' }); + }, {message: 'Expected argument to be of type `error` but received type `string`'}); t.throws(() => { ow('12' as any, 'err', ow.error); - }, { message: 'Expected `err` to be of type `error` but received type `string`' }); + }, {message: 'Expected `err` to be of type `error` but received type `string`'}); }); test('error.name', t => { @@ -37,11 +37,11 @@ test('error.name', t => { t.throws(() => { ow(new CustomError('foo'), ow.error.name('Error')); - }, { message: 'Expected error to have name `Error`, got `CustomError`' }); + }, {message: 'Expected error to have name `Error`, got `CustomError`'}); t.throws(() => { ow(new CustomError('foo'), 'err', ow.error.name('Error')); - }, { message: 'Expected error `err` to have name `Error`, got `CustomError`' }); + }, {message: 'Expected error `err` to have name `Error`, got `CustomError`'}); }); test('error.message', t => { @@ -55,7 +55,7 @@ test('error.message', t => { t.throws(() => { ow(new CustomError('foo'), ow.error.message('bar')); - }, { message: 'Expected error message to be `bar`, got `foo`' }); + }, {message: 'Expected error message to be `bar`, got `foo`'}); }); test('error.messageIncludes', t => { @@ -73,7 +73,7 @@ test('error.messageIncludes', t => { t.throws(() => { ow(new CustomError('foo bar'), ow.error.messageIncludes('unicorn')); - }, { message: 'Expected error message to include `unicorn`, got `foo bar`' }); + }, {message: 'Expected error message to include `unicorn`, got `foo bar`'}); }); test('error.hasKeys', t => { @@ -91,11 +91,11 @@ test('error.hasKeys', t => { t.throws(() => { ow(error, ow.error.hasKeys('foo')); - }, { message: 'Expected error message to have keys `foo`' }); + }, {message: 'Expected error message to have keys `foo`'}); t.throws(() => { ow(error, ow.error.hasKeys('unicorn', 'foo')); - }, { message: 'Expected error message to have keys `unicorn`, `foo`' }); + }, {message: 'Expected error message to have keys `unicorn`, `foo`'}); }); test('error.instanceOf', t => { @@ -121,19 +121,19 @@ test('error.instanceOf', t => { t.throws(() => { ow(new Error('foo'), ow.error.instanceOf(CustomError)); - }, { message: 'Expected error `Error` to be of type `CustomError`' }); + }, {message: 'Expected error `Error` to be of type `CustomError`'}); t.throws(() => { ow(new Error('foo'), 'err', ow.error.instanceOf(CustomError)); - }, { message: 'Expected error `err` `Error` to be of type `CustomError`' }); + }, {message: 'Expected error `err` `Error` to be of type `CustomError`'}); t.throws(() => { ow(new TypeError('foo'), ow.error.instanceOf(EvalError)); - }, { message: 'Expected error `TypeError` to be of type `EvalError`' }); + }, {message: 'Expected error `TypeError` to be of type `EvalError`'}); t.throws(() => { ow(new TypeError('foo'), 'err', ow.error.instanceOf(EvalError)); - }, { message: 'Expected error `err` `TypeError` to be of type `EvalError`' }); + }, {message: 'Expected error `err` `TypeError` to be of type `EvalError`'}); }); test('error.typeError', t => { @@ -143,11 +143,11 @@ test('error.typeError', t => { t.throws(() => { ow(new Error('foo'), ow.error.typeError); - }, { message: 'Expected error `Error` to be of type `TypeError`' }); + }, {message: 'Expected error `Error` to be of type `TypeError`'}); t.throws(() => { ow(new Error('foo'), 'foo', ow.error.typeError); - }, { message: 'Expected error `foo` `Error` to be of type `TypeError`' }); + }, {message: 'Expected error `foo` `Error` to be of type `TypeError`'}); }); test('error.evalError', t => { @@ -157,7 +157,7 @@ test('error.evalError', t => { t.throws(() => { ow(new Error('foo'), ow.error.evalError); - }, { message: 'Expected error `Error` to be of type `EvalError`' }); + }, {message: 'Expected error `Error` to be of type `EvalError`'}); }); test('error.rangeError', t => { @@ -167,7 +167,7 @@ test('error.rangeError', t => { t.throws(() => { ow(new EvalError('foo'), ow.error.rangeError); - }, { message: 'Expected error `EvalError` to be of type `RangeError`' }); + }, {message: 'Expected error `EvalError` to be of type `RangeError`'}); }); test('error.referenceError', t => { @@ -177,7 +177,7 @@ test('error.referenceError', t => { t.throws(() => { ow(new Error('foo'), ow.error.referenceError); - }, { message: 'Expected error `Error` to be of type `ReferenceError`' }); + }, {message: 'Expected error `Error` to be of type `ReferenceError`'}); }); test('error.syntaxError', t => { @@ -187,7 +187,7 @@ test('error.syntaxError', t => { t.throws(() => { ow(new Error('foo'), ow.error.syntaxError); - }, { message: 'Expected error `Error` to be of type `SyntaxError`' }); + }, {message: 'Expected error `Error` to be of type `SyntaxError`'}); }); test('error.uriError', t => { @@ -197,5 +197,5 @@ test('error.uriError', t => { t.throws(() => { ow(new Error('foo'), ow.error.uriError); - }, { message: 'Expected error `Error` to be of type `URIError`' }); + }, {message: 'Expected error `Error` to be of type `URIError`'}); }); diff --git a/test/fixtures/create-error.ts b/test/fixtures/create-error.ts index c4f3220..44942f9 100644 --- a/test/fixtures/create-error.ts +++ b/test/fixtures/create-error.ts @@ -1,24 +1,18 @@ /** @hidden */ -export const createAnyError = (...errors: readonly string[]): string => { - return [ - 'Any predicate failed with the following errors:', - ...errors.map(error => ` - ${error}`) - ].join('\n'); -}; +export const createAnyError = (...errors: readonly string[]): string => [ + 'Any predicate failed with the following errors:', + ...errors.map(error => ` - ${error}`), +].join('\n'); /** @hidden */ -export const createAnyPredicateError = (...allErrors: Array<[predicateName: string, errors: string[]]>): string => { - return [ - 'Any predicate failed with the following errors:', - ...allErrors.map(([predicateName, errors]) => { - return [ - `Errors from the "${predicateName}" predicate:`, - ...errors.map(entry => ` - ${entry}`) - ].join('\n'); - }) - ].join('\n'); -}; +export const createAnyPredicateError = (...allErrors: Array<[predicateName: string, errors: string[]]>): string => [ + 'Any predicate failed with the following errors:', + ...allErrors.map(([predicateName, errors]) => [ + `Errors from the "${predicateName}" predicate:`, + ...errors.map(entry => ` - ${entry}`), + ].join('\n')), +].join('\n'); diff --git a/test/function.ts b/test/function.ts index be2b6bc..d4e72c9 100644 --- a/test/function.ts +++ b/test/function.ts @@ -8,13 +8,13 @@ test('function', t => { t.throws(() => { ow('foo' as any, ow.function); - }, { message: 'Expected argument to be of type `Function` but received type `string`' }); + }, {message: 'Expected argument to be of type `Function` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.function); - }, { message: 'Expected `foo` to be of type `Function` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `Function` but received type `string`'}); t.throws(() => { ow(12 as any, ow.function); - }, { message: 'Expected argument to be of type `Function` but received type `number`' }); + }, {message: 'Expected argument to be of type `Function` but received type `number`'}); }); diff --git a/test/iterable.ts b/test/iterable.ts index 90bd31e..e9c498a 100644 --- a/test/iterable.ts +++ b/test/iterable.ts @@ -16,9 +16,9 @@ test('iterable', t => { t.throws(() => { ow(12 as any, ow.iterable); - }, { message: 'Expected argument to be of type `Iterable` but received type `number`' }); + }, {message: 'Expected argument to be of type `Iterable` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.iterable); - }, { message: 'Expected `foo` to be of type `Iterable` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `Iterable` but received type `number`'}); }); diff --git a/test/map.ts b/test/map.ts index 41ee860..e444a3d 100644 --- a/test/map.ts +++ b/test/map.ts @@ -12,11 +12,11 @@ test('map', t => { t.throws(() => { ow(12 as any, ow.map); - }, { message: 'Expected argument to be of type `Map` but received type `number`' }); + }, {message: 'Expected argument to be of type `Map` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.map); - }, { message: 'Expected `foo` to be of type `Map` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `Map` but received type `number`'}); }); test('map.size', t => { @@ -30,11 +30,11 @@ test('map.size', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.size(0)); - }, { message: 'Expected Map to have size `0`, got `1`' }); + }, {message: 'Expected Map to have size `0`, got `1`'}); t.throws(() => { ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.size(0)); - }, { message: 'Expected Map `foo` to have size `0`, got `1`' }); + }, {message: 'Expected Map `foo` to have size `0`, got `1`'}); }); test('map.minSize', t => { @@ -48,7 +48,7 @@ test('map.minSize', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.minSize(2)); - }, { message: 'Expected Map to have a minimum size of `2`, got `1`' }); + }, {message: 'Expected Map to have a minimum size of `2`, got `1`'}); }); test('map.maxSize', t => { @@ -62,7 +62,7 @@ test('map.maxSize', t => { t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.maxSize(1)); - }, { message: 'Expected Map to have a maximum size of `1`, got `2`' }); + }, {message: 'Expected Map to have a maximum size of `1`, got `2`'}); }); test('map.hasKeys', t => { @@ -80,15 +80,15 @@ test('map.hasKeys', t => { t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasKeys('foo')); - }, { message: 'Expected Map to have keys `["foo"]`' }); + }, {message: 'Expected Map to have keys `["foo"]`'}); t.throws(() => { ow(new Map([['unicorn', '🦄'], ['foo', '🌈']]), ow.map.hasKeys('foo', 'bar')); - }, { message: 'Expected Map to have keys `["bar"]`' }); + }, {message: 'Expected Map to have keys `["bar"]`'}); t.throws(() => { ow(new Map([[2, '🦄'], [4, '🌈']]), ow.map.hasKeys(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - }, { message: 'Expected Map to have keys `[1,3,5,6,7]`' }); + }, {message: 'Expected Map to have keys `[1,3,5,6,7]`'}); }); test('map.hasAnyKeys', t => { @@ -106,7 +106,7 @@ test('map.hasAnyKeys', t => { t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyKeys('foo')); - }, { message: 'Expected Map to have any key of `["foo"]`' }); + }, {message: 'Expected Map to have any key of `["foo"]`'}); }); test('map.hasValues', t => { @@ -120,11 +120,11 @@ test('map.hasValues', t => { t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasValues('🦄', '🌦️')); - }, { message: 'Expected Map to have values `["🌦️"]`' }); + }, {message: 'Expected Map to have values `["🌦️"]`'}); t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasValues('🌈', '⚡', '👓', '🐬', '🎃', '🎶', '❤', '️🐳', '🍀', '👽')); - }, { message: 'Expected Map to have values `["⚡","👓","🐬","🎃","🎶"]`' }); + }, {message: 'Expected Map to have values `["⚡","👓","🐬","🎃","🎶"]`'}); }); test('map.hasAnyValues', t => { @@ -138,7 +138,7 @@ test('map.hasAnyValues', t => { t.throws(() => { ow(new Map([['unicorn', '🦄'], ['rainbow', '🌈']]), ow.map.hasAnyValues('🌦️')); - }, { message: 'Expected Map to have any value of `["🌦️"]`' }); + }, {message: 'Expected Map to have any value of `["🌦️"]`'}); }); test('map.keysOfType', t => { @@ -156,11 +156,11 @@ test('map.keysOfType', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.keysOfType(ow.number)); - }, { message: '(Map) Expected keys to be of type `number` but received type `string`' }); + }, {message: '(Map) Expected keys to be of type `number` but received type `string`'}); t.throws(() => { ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.keysOfType(ow.number)); - }, { message: '(Map `foo`) Expected keys to be of type `number` but received type `string`' }); + }, {message: '(Map `foo`) Expected keys to be of type `number` but received type `string`'}); }); test('map.valuesOfType', t => { @@ -178,11 +178,11 @@ test('map.valuesOfType', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.valuesOfType(ow.number)); - }, { message: '(Map) Expected values to be of type `number` but received type `string`' }); + }, {message: '(Map) Expected values to be of type `number` but received type `string`'}); t.throws(() => { ow(new Map([['unicorn', '🦄']]), 'foo', ow.map.valuesOfType(ow.number)); - }, { message: '(Map `foo`) Expected values to be of type `number` but received type `string`' }); + }, {message: '(Map `foo`) Expected values to be of type `number` but received type `string`'}); }); test('map.empty', t => { @@ -196,7 +196,7 @@ test('map.empty', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.empty); - }, { message: 'Expected Map to be empty, got `[["unicorn","🦄"]]`' }); + }, {message: 'Expected Map to be empty, got `[["unicorn","🦄"]]`'}); }); test('map.notEmpty', t => { @@ -206,7 +206,7 @@ test('map.notEmpty', t => { t.throws(() => { ow(new Map(), ow.map.nonEmpty); - }, { message: 'Expected Map to not be empty' }); + }, {message: 'Expected Map to not be empty'}); }); test('map.deepEqual', t => { @@ -220,9 +220,9 @@ test('map.deepEqual', t => { t.throws(() => { ow(new Map([['unicorn', '🦄']]), ow.map.deepEqual(new Map([['rainbow', '🌈']]))); - }, { message: 'Expected Map to be deeply equal to `[["rainbow","🌈"]]`, got `[["unicorn","🦄"]]`' }); + }, {message: 'Expected Map to be deeply equal to `[["rainbow","🌈"]]`, got `[["unicorn","🦄"]]`'}); t.throws(() => { ow(new Map([['foo', {foo: 'bar'}]]), ow.map.deepEqual(new Map([['foo', {foo: 'baz'}]]))); - }, { message: 'Expected Map to be deeply equal to `[["foo",{"foo":"baz"}]]`, got `[["foo",{"foo":"bar"}]]`' }); + }, {message: 'Expected Map to be deeply equal to `[["foo",{"foo":"baz"}]]`, got `[["foo",{"foo":"bar"}]]`'}); }); diff --git a/test/nan.ts b/test/nan.ts index a3cca9d..f857394 100644 --- a/test/nan.ts +++ b/test/nan.ts @@ -16,13 +16,13 @@ test('nan', t => { t.throws(() => { ow(12, ow.nan); - }, { message: 'Expected argument to be of type `nan` but received type `number`' }); + }, {message: 'Expected argument to be of type `nan` but received type `number`'}); t.throws(() => { ow(12, 'foo', ow.nan); - }, { message: 'Expected `foo` to be of type `nan` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `nan` but received type `number`'}); t.throws(() => { ow('12' as any, ow.nan); - }, { message: 'Expected argument to be of type `nan` but received type `string`' }); + }, {message: 'Expected argument to be of type `nan` but received type `string`'}); }); diff --git a/test/null-or-undefined.ts b/test/null-or-undefined.ts index 0dd7a4a..83ed7ed 100644 --- a/test/null-or-undefined.ts +++ b/test/null-or-undefined.ts @@ -23,9 +23,9 @@ test('nullOrUndefined', t => { t.throws(() => { ow('foo' as any, ow.nullOrUndefined); - }, { message: 'Expected argument to be of type `nullOrUndefined` but received type `string`' }); + }, {message: 'Expected argument to be of type `nullOrUndefined` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.nullOrUndefined); - }, { message: 'Expected `foo` to be of type `nullOrUndefined` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `nullOrUndefined` but received type `string`'}); }); diff --git a/test/null.ts b/test/null.ts index 61894e0..7707f83 100644 --- a/test/null.ts +++ b/test/null.ts @@ -14,13 +14,13 @@ test('null', t => { t.throws(() => { ow(undefined as any, ow.null); - }, { message: 'Expected argument to be of type `null` but received type `undefined`' }); + }, {message: 'Expected argument to be of type `null` but received type `undefined`'}); t.throws(() => { ow(undefined as any, 'foo', ow.null); - }, { message: 'Expected `foo` to be of type `null` but received type `undefined`' }); + }, {message: 'Expected `foo` to be of type `null` but received type `undefined`'}); t.throws(() => { ow('foo' as any, ow.null); - }, { message: 'Expected argument to be of type `null` but received type `string`' }); + }, {message: 'Expected argument to be of type `null` but received type `string`'}); }); diff --git a/test/number.ts b/test/number.ts index bbe2d96..a33f117 100644 --- a/test/number.ts +++ b/test/number.ts @@ -8,11 +8,11 @@ test('number', t => { t.throws(() => { ow('12' as any, ow.number); - }, { message: 'Expected argument to be of type `number` but received type `string`' }); + }, {message: 'Expected argument to be of type `number` but received type `string`'}); t.throws(() => { ow('12' as any, 'foo', ow.number); - }, { message: 'Expected `foo` to be of type `number` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `number` but received type `string`'}); }); test('number.inRange', t => { @@ -29,15 +29,15 @@ test('number.inRange', t => { t.throws(() => { ow(10 as any, ow.number.inRange(0, 9)); - }, { message: 'Expected number to be in range [0..9], got 10' }); + }, {message: 'Expected number to be in range [0..9], got 10'}); t.throws(() => { ow(10 as any, 'foo', ow.number.inRange(0, 9)); - }, { message: 'Expected number `foo` to be in range [0..9], got 10' }); + }, {message: 'Expected number `foo` to be in range [0..9], got 10'}); t.throws(() => { ow(10 as any, ow.number.inRange(11, 20)); - }, { message: 'Expected number to be in range [11..20], got 10' }); + }, {message: 'Expected number to be in range [11..20], got 10'}); }); test('number.greaterThan', t => { @@ -51,15 +51,15 @@ test('number.greaterThan', t => { t.throws(() => { ow(10 as any, ow.number.greaterThan(10)); - }, { message: 'Expected number to be greater than 10, got 10' }); + }, {message: 'Expected number to be greater than 10, got 10'}); t.throws(() => { ow(10 as any, ow.number.greaterThan(11)); - }, { message: 'Expected number to be greater than 11, got 10' }); + }, {message: 'Expected number to be greater than 11, got 10'}); t.throws(() => { ow(10 as any, ow.number.greaterThan(20)); - }, { message: 'Expected number to be greater than 20, got 10' }); + }, {message: 'Expected number to be greater than 20, got 10'}); }); test('number.greaterThanOrEqual', t => { @@ -73,11 +73,11 @@ test('number.greaterThanOrEqual', t => { t.throws(() => { ow(10 as any, ow.number.greaterThanOrEqual(11)); - }, { message: 'Expected number to be greater than or equal to 11, got 10' }); + }, {message: 'Expected number to be greater than or equal to 11, got 10'}); t.throws(() => { ow(10 as any, ow.number.greaterThanOrEqual(20)); - }, { message: 'Expected number to be greater than or equal to 20, got 10' }); + }, {message: 'Expected number to be greater than or equal to 20, got 10'}); }); test('number.lessThan', t => { @@ -91,15 +91,15 @@ test('number.lessThan', t => { t.throws(() => { ow(10 as any, ow.number.lessThan(10)); - }, { message: 'Expected number to be less than 10, got 10' }); + }, {message: 'Expected number to be less than 10, got 10'}); t.throws(() => { ow(10 as any, ow.number.lessThan(9)); - }, { message: 'Expected number to be less than 9, got 10' }); + }, {message: 'Expected number to be less than 9, got 10'}); t.throws(() => { ow(10 as any, ow.number.lessThan(0)); - }, { message: 'Expected number to be less than 0, got 10' }); + }, {message: 'Expected number to be less than 0, got 10'}); }); test('number.lessThanOrEqual', t => { @@ -113,11 +113,11 @@ test('number.lessThanOrEqual', t => { t.throws(() => { ow(10 as any, ow.number.lessThanOrEqual(9)); - }, { message: 'Expected number to be less than or equal to 9, got 10' }); + }, {message: 'Expected number to be less than or equal to 9, got 10'}); t.throws(() => { ow(10 as any, ow.number.lessThanOrEqual(0)); - }, { message: 'Expected number to be less than or equal to 0, got 10' }); + }, {message: 'Expected number to be less than or equal to 0, got 10'}); }); test('number.equal', t => { @@ -127,7 +127,7 @@ test('number.equal', t => { t.throws(() => { ow(10 as any, ow.number.equal(5)); - }, { message: 'Expected number to be equal to 5, got 10' }); + }, {message: 'Expected number to be equal to 5, got 10'}); }); test('number.oneOf', t => { @@ -137,19 +137,19 @@ test('number.oneOf', t => { t.throws(() => { ow(10, ow.number.oneOf([5, 6])); - }, { message: 'Expected number to be one of `[5,6]`, got 10' }); + }, {message: 'Expected number to be one of `[5,6]`, got 10'}); t.throws(() => { ow(10, 'hello', ow.number.oneOf([5, 6])); - }, { message: 'Expected number `hello` to be one of `[5,6]`, got 10' }); + }, {message: 'Expected number `hello` to be one of `[5,6]`, got 10'}); t.throws(() => { ow(10, ow.number.oneOf([5, 6, 7, 8, 9])); - }, { message: 'Expected number to be one of `[5,6,7,8,9]`, got 10' }); + }, {message: 'Expected number to be one of `[5,6,7,8,9]`, got 10'}); t.throws(() => { ow(10, ow.number.oneOf([5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18])); - }, { message: 'Expected number to be one of `[5,6,7,8,9,11,12,13,14,15,…+3 more]`, got 10' }); + }, {message: 'Expected number to be one of `[5,6,7,8,9,11,12,13,14,15,…+3 more]`, got 10'}); }); test('number.integer', t => { @@ -159,7 +159,7 @@ test('number.integer', t => { t.throws(() => { ow(10.1 as any, ow.number.integer); - }, { message: 'Expected number to be an integer, got 10.1' }); + }, {message: 'Expected number to be an integer, got 10.1'}); }); test('number.finite', t => { @@ -169,7 +169,7 @@ test('number.finite', t => { t.throws(() => { ow(Number.POSITIVE_INFINITY as any, ow.number.finite); - }, { message: 'Expected number to be finite, got Infinity' }); + }, {message: 'Expected number to be finite, got Infinity'}); }); test('number.infinite', t => { @@ -179,7 +179,7 @@ test('number.infinite', t => { t.throws(() => { ow(10 as any, ow.number.infinite); - }, { message: 'Expected number to be infinite, got 10' }); + }, {message: 'Expected number to be infinite, got 10'}); }); test('number.positive', t => { @@ -189,7 +189,7 @@ test('number.positive', t => { t.throws(() => { ow(-1 as any, ow.number.positive); - }, { message: 'Expected number to be positive, got -1' }); + }, {message: 'Expected number to be positive, got -1'}); }); test('number.negative', t => { @@ -199,7 +199,7 @@ test('number.negative', t => { t.throws(() => { ow(1 as any, ow.number.negative); - }, { message: 'Expected number to be negative, got 1' }); + }, {message: 'Expected number to be negative, got 1'}); }); test('number.integerOrInfinite', t => { @@ -217,7 +217,7 @@ test('number.integerOrInfinite', t => { t.throws(() => { ow(3.14, ow.number.integerOrInfinite); - }, { message: 'Expected number to be an integer or infinite, got 3.14' }); + }, {message: 'Expected number to be an integer or infinite, got 3.14'}); }); test('number.uint8', t => { @@ -231,15 +231,15 @@ test('number.uint8', t => { t.throws(() => { ow(-1, ow.number.uint8); - }, { message: 'Expected number to be in range [0..255], got -1' }); + }, {message: 'Expected number to be in range [0..255], got -1'}); t.throws(() => { ow(1.5, ow.number.uint8); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { ow(256, ow.number.uint8); - }, { message: 'Expected number to be in range [0..255], got 256' }); + }, {message: 'Expected number to be in range [0..255], got 256'}); }); test('number.uint16', t => { @@ -248,20 +248,20 @@ test('number.uint16', t => { }); t.notThrows(() => { - ow(65535, ow.number.uint16); + ow(65_535, ow.number.uint16); }); t.throws(() => { ow(-1, ow.number.uint16); - }, { message: 'Expected number to be in range [0..65535], got -1' }); + }, {message: 'Expected number to be in range [0..65535], got -1'}); t.throws(() => { ow(1.5, ow.number.uint16); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { - ow(65536, ow.number.uint16); - }, { message: 'Expected number to be in range [0..65535], got 65536' }); + ow(65_536, ow.number.uint16); + }, {message: 'Expected number to be in range [0..65535], got 65536'}); }); test('number.uint32', t => { @@ -270,20 +270,20 @@ test('number.uint32', t => { }); t.notThrows(() => { - ow(4294967295, ow.number.uint32); + ow(4_294_967_295, ow.number.uint32); }); t.throws(() => { ow(-1, ow.number.uint32); - }, { message: 'Expected number to be in range [0..4294967295], got -1' }); + }, {message: 'Expected number to be in range [0..4294967295], got -1'}); t.throws(() => { ow(1.5, ow.number.uint32); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { - ow(4294967296, ow.number.uint32); - }, { message: 'Expected number to be in range [0..4294967295], got 4294967296' }); + ow(4_294_967_296, ow.number.uint32); + }, {message: 'Expected number to be in range [0..4294967295], got 4294967296'}); }); test('number.int8', t => { @@ -297,57 +297,57 @@ test('number.int8', t => { t.throws(() => { ow(-129, ow.number.int8); - }, { message: 'Expected number to be in range [-128..127], got -129' }); + }, {message: 'Expected number to be in range [-128..127], got -129'}); t.throws(() => { ow(1.5, ow.number.int8); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { ow(128, ow.number.int8); - }, { message: 'Expected number to be in range [-128..127], got 128' }); + }, {message: 'Expected number to be in range [-128..127], got 128'}); }); test('number.int16', t => { t.notThrows(() => { - ow(-32768, ow.number.int16); + ow(-32_768, ow.number.int16); }); t.notThrows(() => { - ow(32767, ow.number.int16); + ow(32_767, ow.number.int16); }); t.throws(() => { - ow(-32769, ow.number.int16); - }, { message: 'Expected number to be in range [-32768..32767], got -32769' }); + ow(-32_769, ow.number.int16); + }, {message: 'Expected number to be in range [-32768..32767], got -32769'}); t.throws(() => { ow(1.5, ow.number.int16); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { - ow(32768, ow.number.int16); - }, { message: 'Expected number to be in range [-32768..32767], got 32768' }); + ow(32_768, ow.number.int16); + }, {message: 'Expected number to be in range [-32768..32767], got 32768'}); }); test('number.int32', t => { t.notThrows(() => { - ow(-2147483648, ow.number.int32); + ow(-2_147_483_648, ow.number.int32); }); t.notThrows(() => { - ow(2147483647, ow.number.int32); + ow(2_147_483_647, ow.number.int32); }); t.throws(() => { - ow(-2147483649, ow.number.int32); - }, { message: 'Expected number to be in range [-2147483648..2147483647], got -2147483649' }); + ow(-2_147_483_649, ow.number.int32); + }, {message: 'Expected number to be in range [-2147483648..2147483647], got -2147483649'}); t.throws(() => { ow(1.5, ow.number.int32); - }, { message: 'Expected number to be an integer, got 1.5' }); + }, {message: 'Expected number to be an integer, got 1.5'}); t.throws(() => { - ow(2147483648, ow.number.int32); - }, { message: 'Expected number to be in range [-2147483648..2147483647], got 2147483648' }); + ow(2_147_483_648, ow.number.int32); + }, {message: 'Expected number to be in range [-2147483648..2147483647], got 2147483648'}); }); diff --git a/test/object.ts b/test/object.ts index 6570dbb..29eaacb 100644 --- a/test/object.ts +++ b/test/object.ts @@ -14,15 +14,15 @@ test('object', t => { t.throws(() => { ow('foo' as any, ow.object); - }, { message: 'Expected argument to be of type `object` but received type `string`'}); + }, {message: 'Expected argument to be of type `object` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.object); - }, { message: 'Expected `foo` to be of type `object` but received type `string`'}); + }, {message: 'Expected `foo` to be of type `object` but received type `string`'}); t.throws(() => { ow(1 as any, ow.object); - }, { message: 'Expected argument to be of type `object` but received type `number`'}); + }, {message: 'Expected argument to be of type `object` but received type `number`'}); }); test('object.plain', t => { @@ -32,11 +32,11 @@ test('object.plain', t => { t.throws(() => { ow(new Error('foo'), ow.object.plain); - }, { message: 'Expected object to be a plain object'}); + }, {message: 'Expected object to be a plain object'}); t.throws(() => { ow(new Error('foo'), 'foo', ow.object.plain); - }, { message: 'Expected object `foo` to be a plain object'}); + }, {message: 'Expected object `foo` to be a plain object'}); }); test('object.empty', t => { @@ -46,7 +46,7 @@ test('object.empty', t => { t.throws(() => { ow({unicorn: '🦄'}, ow.object.empty); - }, { message: 'Expected object to be empty, got `{"unicorn":"🦄"}`'}); + }, {message: 'Expected object to be empty, got `{"unicorn":"🦄"}`'}); }); test('object.nonEmpty', t => { @@ -55,7 +55,7 @@ test('object.nonEmpty', t => { }); t.throws(() => { ow({}, ow.object.nonEmpty); - }, { message: 'Expected object to not be empty'}); + }, {message: 'Expected object to not be empty'}); }); test('object.valuesOfType', t => { @@ -77,19 +77,19 @@ test('object.valuesOfType', t => { t.throws(() => { ow({unicorn: '🦄', rainbow: 2}, ow.object.valuesOfType(ow.string)); - }, { message: '(object) Expected values to be of type `string` but received type `number`' }); + }, {message: '(object) Expected values to be of type `string` but received type `number`'}); t.throws(() => { ow({unicorn: '🦄', rainbow: 2}, 'foo', ow.object.valuesOfType(ow.string)); - }, { message: '(object `foo`) Expected values to be of type `string` but received type `number`' }); + }, {message: '(object `foo`) Expected values to be of type `string` but received type `number`'}); t.throws(() => { ow({unicorn: 'a', rainbow: 'b'}, ow.object.valuesOfType(ow.string.minLength(2))); - }, { message: '(object) Expected string values to have a minimum length of `2`, got `a`' }); + }, {message: '(object) Expected string values to have a minimum length of `2`, got `a`'}); t.throws(() => { ow(['🦄', true, 1], ow.object.valuesOfType(ow.any(ow.string, ow.boolean))); - }, { message: '(object) Any predicate failed with the following errors:\n - Expected values to be of type `string` but received type `number`\n - Expected values to be of type `boolean` but received type `number`' }); + }, {message: '(object) Any predicate failed with the following errors:\n - Expected values to be of type `string` but received type `number`\n - Expected values to be of type `boolean` but received type `number`'}); }); test('object.valuesOfTypeDeep', t => { @@ -111,15 +111,15 @@ test('object.valuesOfTypeDeep', t => { t.throws(() => { ow({unicorn: {key: '🦄', value: 1}}, ow.object.deepValuesOfType(ow.string)); - }, { message: '(object) Expected deep values to be of type `string` but received type `number`' }); + }, {message: '(object) Expected deep values to be of type `string` but received type `number`'}); t.throws(() => { ow({unicorn: {key: '🦄', value: 1}}, 'foo', ow.object.deepValuesOfType(ow.string)); - }, { message: '(object `foo`) Expected deep values to be of type `string` but received type `number`' }); + }, {message: '(object `foo`) Expected deep values to be of type `string` but received type `number`'}); t.throws(() => { ow({a: {b: {c: {d: 1}, e: '2'}, f: 3}}, ow.object.deepValuesOfType(ow.number)); - }, { message: '(object) Expected deep values to be of type `number` but received type `string`' }); + }, {message: '(object) Expected deep values to be of type `number` but received type `string`'}); }); test('object.deepEqual', t => { @@ -133,7 +133,7 @@ test('object.deepEqual', t => { t.throws(() => { ow({unicorn: '🦄'}, ow.object.deepEqual({rainbow: '🌈'})); - }, { message: 'Expected object to be deeply equal to `{"rainbow":"🌈"}`, got `{"unicorn":"🦄"}`'}); + }, {message: 'Expected object to be deeply equal to `{"rainbow":"🌈"}`, got `{"unicorn":"🦄"}`'}); }); test('object.instanceOf', t => { @@ -147,27 +147,27 @@ test('object.instanceOf', t => { t.throws(() => { ow(new Unicorn(), ow.object.instanceOf(Error)); - }, { message: 'Expected object `Unicorn` to be of type `Error`'}); + }, {message: 'Expected object `Unicorn` to be of type `Error`'}); t.throws(() => { ow(new Unicorn(), 'foo', ow.object.instanceOf(Error)); - }, { message: 'Expected object `foo` `Unicorn` to be of type `Error`'}); + }, {message: 'Expected object `foo` `Unicorn` to be of type `Error`'}); t.throws(() => { ow(new Error('🦄'), ow.object.instanceOf(Unicorn)); - }, { message: 'Expected object `Error` to be of type `Unicorn`'}); + }, {message: 'Expected object `Error` to be of type `Unicorn`'}); t.throws(() => { ow({unicorn: '🦄'}, ow.object.instanceOf(Unicorn)); - }, { message: 'Expected object `{"unicorn":"🦄"}` to be of type `Unicorn`'}); + }, {message: 'Expected object `{"unicorn":"🦄"}` to be of type `Unicorn`'}); t.throws(() => { ow(null, ow.object.instanceOf(Unicorn)); - }, { message: /Expected object `null` to be of type `Unicorn`/ }); + }, {message: /Expected object `null` to be of type `Unicorn`/}); t.throws(() => { ow(undefined, ow.object.instanceOf(Unicorn)); - }, { message: /Expected object `undefined` to be of type `Unicorn`/ }); + }, {message: /Expected object `undefined` to be of type `Unicorn`/}); }); test('object.hasKeys', t => { @@ -189,11 +189,11 @@ test('object.hasKeys', t => { t.throws(() => { ow({unicorn: '🦄'}, ow.object.hasKeys('unicorn', 'rainbow')); - }, { message: 'Expected object to have keys `["rainbow"]`'}); + }, {message: 'Expected object to have keys `["rainbow"]`'}); t.throws(() => { ow({unicorn: {value: '🦄'}}, ow.object.hasKeys('unicorn.foo')); - }, { message: 'Expected object to have keys `["unicorn.foo"]`'}); + }, {message: 'Expected object to have keys `["unicorn.foo"]`'}); }); test('object.hasAnyKeys', t => { @@ -215,23 +215,23 @@ test('object.hasAnyKeys', t => { t.throws(() => { ow({unicorn: '🦄'}, ow.object.hasAnyKeys('foo')); - }, { message: 'Expected object to have any key of `["foo"]`'}); + }, {message: 'Expected object to have any key of `["foo"]`'}); t.throws(() => { ow({unicorn: '🦄'}, ow.object.hasAnyKeys('unicorn.value')); - }, { message: 'Expected object to have any key of `["unicorn.value"]`'}); + }, {message: 'Expected object to have any key of `["unicorn.value"]`'}); }); test('object.exactShape', t => { t.notThrows(() => { ow({unicorn: '🦄'}, ow.object.exactShape({ - unicorn: ow.string + unicorn: ow.string, })); }); t.notThrows(() => { ow({unicorn: '🦄'}, ow.object.exactShape({ - unicorn: ow.string + unicorn: ow.string, })); }); @@ -239,8 +239,8 @@ test('object.exactShape', t => { ow({unicorn: '🦄', rainbow: {value: '🌈'}}, ow.object.exactShape({ unicorn: ow.string, rainbow: { - value: ow.string - } + value: ow.string, + }, })); }); @@ -248,16 +248,16 @@ test('object.exactShape', t => { ow({unicorn: '🦄', rainbow: {value: '🌈'}}, ow.object.exactShape({ unicorn: ow.string, rainbow: { - foo: ow.string - } + foo: ow.string, + }, })); - }, { message: 'Expected property `rainbow.foo` to be of type `string` but received type `undefined` in object'}); + }, {message: 'Expected property `rainbow.foo` to be of type `string` but received type `undefined` in object'}); t.throws(() => { ow({unicorn: '🦄', rainbow: '🌈'}, ow.object.exactShape({ - unicorn: ow.string + unicorn: ow.string, })); - }, { message: 'Did not expect property `rainbow` to exist, got `🌈` in object' }); + }, {message: 'Did not expect property `rainbow` to exist, got `🌈` in object'}); const foo = {unicorn: '🦄', rainbow: {valid: true, value: '🌈'}}; @@ -265,59 +265,59 @@ test('object.exactShape', t => { ow(foo, ow.object.exactShape({ unicorn: ow.string, rainbow: { - valid: ow.boolean - } + valid: ow.boolean, + }, })); - }, { message: 'Did not expect property `rainbow.value` to exist, got `🌈` in object' }); + }, {message: 'Did not expect property `rainbow.value` to exist, got `🌈` in object'}); t.throws(() => { ow({unicorn: '🦄'}, ow.object.exactShape({ unicorn: ow.string, rainbow: { - valid: ow.boolean - } + valid: ow.boolean, + }, })); - }, { message: 'Expected property `rainbow` to exist in object'}); + }, {message: 'Expected property `rainbow` to exist in object'}); }); test('object.partialShape', t => { t.notThrows(() => { ow({unicorn: '🦄'}, ow.object.partialShape({ - unicorn: ow.string + unicorn: ow.string, })); }); t.throws(() => { ow({unicorn: '🦄'}, ow.object.partialShape({ - unicorn: ow.number + unicorn: ow.number, })); - }, { message: 'Expected property `unicorn` to be of type `number` but received type `string` in object'}); + }, {message: 'Expected property `unicorn` to be of type `number` but received type `string` in object'}); t.throws(() => { ow({unicorn: '🦄', rainbow: {value: '🌈'}}, ow.object.partialShape({ unicorn: ow.string, rainbow: { - value: ow.number - } + value: ow.number, + }, })); - }, { message: 'Expected property `rainbow.value` to be of type `number` but received type `string` in object'}); + }, {message: 'Expected property `rainbow.value` to be of type `number` but received type `string` in object'}); t.throws(() => { ow({unicorn: '🦄', rainbow: {rocket: {value: '🌈'}}}, ow.object.partialShape({ unicorn: ow.string, rainbow: { rocket: { - value: ow.number - } - } + value: ow.number, + }, + }, })); - }, { message: 'Expected property `rainbow.rocket.value` to be of type `number` but received type `string` in object'}); + }, {message: 'Expected property `rainbow.rocket.value` to be of type `number` but received type `string` in object'}); const foo = {unicorn: '🦄'}; t.throws(() => { ow(foo, ow.object.partialShape({ - unicorn: ow.number + unicorn: ow.number, })); - }, { message: 'Expected property `unicorn` to be of type `number` but received type `string` in object'}); + }, {message: 'Expected property `unicorn` to be of type `number` but received type `string` in object'}); }); diff --git a/test/optional.ts b/test/optional.ts index 43e71c2..0182757 100644 --- a/test/optional.ts +++ b/test/optional.ts @@ -28,13 +28,13 @@ test('optional', t => { t.throws(() => { ow(null, ow.optional.function); - }, { message: 'Expected argument to be of type `Function` but received type `null`' }); + }, {message: 'Expected argument to be of type `Function` but received type `null`'}); t.throws(() => { ow(null, ow.optional.number); - }, { message: 'Expected argument to be of type `number` but received type `null`' }); + }, {message: 'Expected argument to be of type `number` but received type `null`'}); t.throws(() => { ow('1' as any, ow.optional.number); - }, { message: 'Expected argument to be of type `number` but received type `string`' }); + }, {message: 'Expected argument to be of type `number` but received type `string`'}); }); diff --git a/test/promise.ts b/test/promise.ts index cb4a9fd..e6c34a2 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -15,13 +15,13 @@ test('promise', t => { t.throws(() => { ow('foo' as any, ow.promise); - }, { message: 'Expected argument to be of type `Promise` but received type `string`' }); + }, {message: 'Expected argument to be of type `Promise` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.promise); - }, { message: 'Expected `foo` to be of type `Promise` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `Promise` but received type `string`'}); t.throws(() => { ow(12 as any, ow.promise); - }, { message: 'Expected argument to be of type `Promise` but received type `number`' }); + }, {message: 'Expected argument to be of type `Promise` but received type `number`'}); }); diff --git a/test/regexp.ts b/test/regexp.ts index dc2dd06..6e20dc8 100644 --- a/test/regexp.ts +++ b/test/regexp.ts @@ -13,13 +13,13 @@ test('regExp', t => { t.throws(() => { ow('foo' as any, ow.regExp); - }, { message: 'Expected argument to be of type `RegExp` but received type `string`' }); + }, {message: 'Expected argument to be of type `RegExp` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.regExp); - }, { message: 'Expected `foo` to be of type `RegExp` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `RegExp` but received type `string`'}); t.throws(() => { ow(12 as any, ow.regExp); - }, { message: 'Expected argument to be of type `RegExp` but received type `number`' }); + }, {message: 'Expected argument to be of type `RegExp` but received type `number`'}); }); diff --git a/test/set.ts b/test/set.ts index b24501a..34a5874 100644 --- a/test/set.ts +++ b/test/set.ts @@ -12,11 +12,11 @@ test('set', t => { t.throws(() => { ow(12 as any, ow.set); - }, { message: 'Expected argument to be of type `Set` but received type `number`' }); + }, {message: 'Expected argument to be of type `Set` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.set); - }, { message: 'Expected `foo` to be of type `Set` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `Set` but received type `number`'}); }); test('set.size', t => { @@ -30,11 +30,11 @@ test('set.size', t => { t.throws(() => { ow(new Set(['🦄']), ow.set.size(0)); - }, { message: 'Expected Set to have size `0`, got `1`' }); + }, {message: 'Expected Set to have size `0`, got `1`'}); t.throws(() => { ow(new Set(['🦄']), 'foo', ow.set.size(0)); - }, { message: 'Expected Set `foo` to have size `0`, got `1`' }); + }, {message: 'Expected Set `foo` to have size `0`, got `1`'}); }); test('set.minSize', t => { @@ -48,7 +48,7 @@ test('set.minSize', t => { t.throws(() => { ow(new Set(['🦄']), ow.set.minSize(2)); - }, { message: 'Expected Set to have a minimum size of `2`, got `1`' }); + }, {message: 'Expected Set to have a minimum size of `2`, got `1`'}); }); test('set.maxSize', t => { @@ -62,7 +62,7 @@ test('set.maxSize', t => { t.throws(() => { ow(new Set(['🦄', '🌈']), ow.set.maxSize(1)); - }, { message: 'Expected Set to have a maximum size of `1`, got `2`' }); + }, {message: 'Expected Set to have a maximum size of `1`, got `2`'}); }); test('set.hasKeys', t => { @@ -80,15 +80,15 @@ test('set.hasKeys', t => { t.throws(() => { ow(new Set(['unicorn', 'rainbow']), ow.set.has('foo')); - }, { message: 'Expected Set to have items `["foo"]`' }); + }, {message: 'Expected Set to have items `["foo"]`'}); t.throws(() => { ow(new Set(['unicorn', 'foo']), ow.set.has('foo', 'bar')); - }, { message: 'Expected Set to have items `["bar"]`' }); + }, {message: 'Expected Set to have items `["bar"]`'}); t.throws(() => { ow(new Set([2, 4]), ow.set.has(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - }, { message: 'Expected Set to have items `[1,3,5,6,7]`' }); + }, {message: 'Expected Set to have items `[1,3,5,6,7]`'}); }); test('set.hasAny', t => { @@ -106,7 +106,7 @@ test('set.hasAny', t => { t.throws(() => { ow(new Set(['unicorn', 'rainbow']), ow.set.hasAny('foo')); - }, { message: 'Expected Set to have any item of `["foo"]`' }); + }, {message: 'Expected Set to have any item of `["foo"]`'}); }); test('set.ofType', t => { @@ -124,11 +124,11 @@ test('set.ofType', t => { t.throws(() => { ow(new Set(['unicorn']), ow.set.ofType(ow.number)); - }, { message: '(Set) Expected values to be of type `number` but received type `string`' }); + }, {message: '(Set) Expected values to be of type `number` but received type `string`'}); t.throws(() => { ow(new Set(['unicorn']), 'foo', ow.set.ofType(ow.number)); - }, { message: '(Set `foo`) Expected values to be of type `number` but received type `string`' }); + }, {message: '(Set `foo`) Expected values to be of type `number` but received type `string`'}); }); test('set.empty', t => { @@ -142,7 +142,7 @@ test('set.empty', t => { t.throws(() => { ow(new Set(['unicorn']), ow.set.empty); - }, { message: 'Expected Set to be empty, got `["unicorn"]`' }); + }, {message: 'Expected Set to be empty, got `["unicorn"]`'}); }); test('set.notEmpty', t => { @@ -152,7 +152,7 @@ test('set.notEmpty', t => { t.throws(() => { ow(new Set(), ow.set.nonEmpty); - }, { message: 'Expected Set to not be empty' }); + }, {message: 'Expected Set to not be empty'}); }); test('set.deepEqual', t => { @@ -166,9 +166,9 @@ test('set.deepEqual', t => { t.throws(() => { ow(new Set(['unicorn']), ow.set.deepEqual(new Set(['rainbow']))); - }, { message: 'Expected Set to be deeply equal to `["rainbow"]`, got `["unicorn"]`' }); + }, {message: 'Expected Set to be deeply equal to `["rainbow"]`, got `["unicorn"]`'}); t.throws(() => { ow(new Set([{foo: 'bar'}]), ow.set.deepEqual(new Set([{foo: 'baz'}]))); - }, { message: 'Expected Set to be deeply equal to `[{"foo":"baz"}]`, got `[{"foo":"bar"}]`' }); + }, {message: 'Expected Set to be deeply equal to `[{"foo":"baz"}]`, got `[{"foo":"bar"}]`'}); }); diff --git a/test/string.ts b/test/string.ts index 2b5e7a5..e02498e 100644 --- a/test/string.ts +++ b/test/string.ts @@ -10,15 +10,15 @@ test('string', t => { t.throws(() => { ow(12 as any, ow.string); - }, { message: 'Expected argument to be of type `string` but received type `number`' }); + }, {message: 'Expected argument to be of type `string` but received type `number`'}); t.throws(() => { ow(12 as any, 'bar', ow.string); - }, { message: 'Expected `bar` to be of type `string` but received type `number`' }); + }, {message: 'Expected `bar` to be of type `string` but received type `number`'}); t.throws(() => { ow(bar, ow.string); - }, { message: 'Expected argument to be of type `string` but received type `number`' }); + }, {message: 'Expected argument to be of type `string` but received type `number`'}); }); test('string.length', t => { @@ -32,11 +32,11 @@ test('string.length', t => { t.throws(() => { ow('foo' as any, ow.string.length(4)); - }, { message: 'Expected string to have length `4`, got `foo`' }); + }, {message: 'Expected string to have length `4`, got `foo`'}); t.throws(() => { ow('foo' as any, 'foo', ow.string.length(4)); - }, { message: 'Expected string `foo` to have length `4`, got `foo`' }); + }, {message: 'Expected string `foo` to have length `4`, got `foo`'}); }); test('string.minLength', t => { @@ -50,7 +50,7 @@ test('string.minLength', t => { t.throws(() => { ow('foo' as any, ow.string.minLength(4)); - }, { message: 'Expected string to have a minimum length of `4`, got `foo`' }); + }, {message: 'Expected string to have a minimum length of `4`, got `foo`'}); }); test('string.maxLength', t => { @@ -64,7 +64,7 @@ test('string.maxLength', t => { t.throws(() => { ow('foo' as any, ow.string.maxLength(2)); - }, { message: 'Expected string to have a maximum length of `2`, got `foo`' }); + }, {message: 'Expected string to have a maximum length of `2`, got `foo`'}); }); test('string.matches', t => { @@ -78,11 +78,11 @@ test('string.matches', t => { t.throws(() => { ow('Foo' as any, ow.string.matches(/^f.o$/)); - }, { message: 'Expected string to match `/^f.o$/`, got `Foo`' }); + }, {message: 'Expected string to match `/^f.o$/`, got `Foo`'}); t.throws(() => { ow('bar' as any, ow.string.matches(/^f.o$/i)); - }, { message: 'Expected string to match `/^f.o$/i`, got `bar`' }); + }, {message: 'Expected string to match `/^f.o$/i`, got `bar`'}); }); test('string.startsWith', t => { @@ -96,11 +96,11 @@ test('string.startsWith', t => { t.throws(() => { ow('foo' as any, ow.string.startsWith('oo')); - }, { message: 'Expected string to start with `oo`, got `foo`' }); + }, {message: 'Expected string to start with `oo`, got `foo`'}); t.throws(() => { ow('foo' as any, ow.string.startsWith('b')); - }, { message: 'Expected string to start with `b`, got `foo`' }); + }, {message: 'Expected string to start with `b`, got `foo`'}); }); test('string.endsWith', t => { @@ -114,11 +114,11 @@ test('string.endsWith', t => { t.throws(() => { ow('foo' as any, ow.string.endsWith('fo')); - }, { message: 'Expected string to end with `fo`, got `foo`' }); + }, {message: 'Expected string to end with `fo`, got `foo`'}); t.throws(() => { ow('foo' as any, ow.string.endsWith('ar')); - }, { message: 'Expected string to end with `ar`, got `foo`' }); + }, {message: 'Expected string to end with `ar`, got `foo`'}); }); test('string.includes', t => { @@ -128,7 +128,7 @@ test('string.includes', t => { t.throws(() => { ow('foo' as any, ow.string.includes('bar')); - }, { message: 'Expected string to include `bar`, got `foo`' }); + }, {message: 'Expected string to include `bar`, got `foo`'}); }); test('string.oneOf', t => { @@ -138,19 +138,19 @@ test('string.oneOf', t => { t.throws(() => { ow('foo', ow.string.oneOf(['unicorn', 'rainbow'])); - }, { message: 'Expected string to be one of `["unicorn","rainbow"]`, got `foo`' }); + }, {message: 'Expected string to be one of `["unicorn","rainbow"]`, got `foo`'}); t.throws(() => { ow('foo', 'hello', ow.string.oneOf(['unicorn', 'rainbow'])); - }, { message: 'Expected string `hello` to be one of `["unicorn","rainbow"]`, got `foo`' }); + }, {message: 'Expected string `hello` to be one of `["unicorn","rainbow"]`, got `foo`'}); t.throws(() => { ow('foo', ow.string.oneOf(['a', 'b', 'c', 'd', 'e'])); - }, { message: 'Expected string to be one of `["a","b","c","d","e"]`, got `foo`' }); + }, {message: 'Expected string to be one of `["a","b","c","d","e"]`, got `foo`'}); t.throws(() => { ow('foo', ow.string.oneOf(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'])); - }, { message: 'Expected string to be one of `["1","2","3","4","5","6","7","8","9","10",…+3 more]`, got `foo`' }); + }, {message: 'Expected string to be one of `["1","2","3","4","5","6","7","8","9","10",…+3 more]`, got `foo`'}); }); test('string.empty', t => { @@ -160,7 +160,7 @@ test('string.empty', t => { t.throws(() => { ow('foo' as any, ow.string.empty); - }, { message: 'Expected string to be empty, got `foo`' }); + }, {message: 'Expected string to be empty, got `foo`'}); }); test('string.nonEmpty', t => { @@ -170,7 +170,7 @@ test('string.nonEmpty', t => { t.throws(() => { ow('' as any, ow.string.nonEmpty); - }, { message: 'Expected string to not be empty' }); + }, {message: 'Expected string to not be empty'}); }); test('string.equals', t => { @@ -180,7 +180,7 @@ test('string.equals', t => { t.throws(() => { ow('bar' as any, ow.string.equals('foo')); - }, { message: 'Expected string to be equal to `foo`, got `bar`' }); + }, {message: 'Expected string to be equal to `foo`, got `bar`'}); }); test('string.alphabetical', t => { @@ -194,11 +194,11 @@ test('string.alphabetical', t => { t.throws(() => { ow('foo123', ow.string.alphabetical); - }, { message: 'Expected string to be alphabetical, got `foo123`' }); + }, {message: 'Expected string to be alphabetical, got `foo123`'}); t.throws(() => { ow('', ow.string.alphabetical); - }, { message: 'Expected string to be alphabetical, got ``' }); + }, {message: 'Expected string to be alphabetical, got ``'}); }); test('string.alphanumeric', t => { @@ -208,7 +208,7 @@ test('string.alphanumeric', t => { t.throws(() => { ow('Foo123!' as any, ow.string.alphanumeric); - }, { message: 'Expected string to be alphanumeric, got `Foo123!`' }); + }, {message: 'Expected string to be alphanumeric, got `Foo123!`'}); }); test('string.numeric', t => { @@ -226,27 +226,27 @@ test('string.numeric', t => { t.throws(() => { ow('Foo123', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `Foo123`' }); + }, {message: 'Expected string to be numeric, got `Foo123`'}); t.throws(() => { ow('++123', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `++123`' }); + }, {message: 'Expected string to be numeric, got `++123`'}); t.throws(() => { ow('1+1', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `1+1`' }); + }, {message: 'Expected string to be numeric, got `1+1`'}); t.throws(() => { ow('11-', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `11-`' }); + }, {message: 'Expected string to be numeric, got `11-`'}); t.throws(() => { ow('--123', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `--123`' }); + }, {message: 'Expected string to be numeric, got `--123`'}); t.throws(() => { ow('+-123', ow.string.numeric); - }, { message: 'Expected string to be numeric, got `+-123`' }); + }, {message: 'Expected string to be numeric, got `+-123`'}); }); test('string.date', t => { @@ -260,11 +260,11 @@ test('string.date', t => { t.throws(() => { ow('foo' as any, ow.string.date); - }, { message: 'Expected string to be a date, got `foo`' }); + }, {message: 'Expected string to be a date, got `foo`'}); t.throws(() => { ow('foo' as any, 'bar', ow.string.date); - }, { message: 'Expected string `bar` to be a date, got `foo`' }); + }, {message: 'Expected string `bar` to be a date, got `foo`'}); }); test('string.lowercase', t => { @@ -282,11 +282,11 @@ test('string.lowercase', t => { t.throws(() => { ow('FOO', ow.string.lowercase); - }, { message: 'Expected string to be lowercase, got `FOO`' }); + }, {message: 'Expected string to be lowercase, got `FOO`'}); t.throws(() => { ow('', ow.string.lowercase); - }, { message: 'Expected string to be lowercase, got ``' }); + }, {message: 'Expected string to be lowercase, got ``'}); }); test('string.uppercase', t => { @@ -304,11 +304,11 @@ test('string.uppercase', t => { t.throws(() => { ow('foo', ow.string.uppercase); - }, { message: 'Expected string to be uppercase, got `foo`' }); + }, {message: 'Expected string to be uppercase, got `foo`'}); t.throws(() => { ow('', ow.string.uppercase); - }, { message: 'Expected string to be uppercase, got ``' }); + }, {message: 'Expected string to be uppercase, got ``'}); }); test('string.url', t => { @@ -322,9 +322,9 @@ test('string.url', t => { t.throws(() => { ow('foo' as any, ow.string.url); - }, { message: 'Expected string to be a URL, got `foo`' }); + }, {message: 'Expected string to be a URL, got `foo`'}); t.throws(() => { ow('foo' as any, 'bar', ow.string.url); - }, { message: 'Expected string `bar` to be a URL, got `foo`' }); + }, {message: 'Expected string `bar` to be a URL, got `foo`'}); }); diff --git a/test/symbol.ts b/test/symbol.ts index 3152b70..9aa59f0 100644 --- a/test/symbol.ts +++ b/test/symbol.ts @@ -12,9 +12,9 @@ test('symbol', t => { t.throws(() => { ow(12 as any, ow.symbol); - }, { message: 'Expected argument to be of type `symbol` but received type `number`' }); + }, {message: 'Expected argument to be of type `symbol` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.symbol); - }, {message: 'Expected `foo` to be of type `symbol` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `symbol` but received type `number`'}); }); diff --git a/test/test.ts b/test/test.ts index fe28a53..8754e37 100644 --- a/test/test.ts +++ b/test/test.ts @@ -19,7 +19,7 @@ test('not', t => { t.throws(() => { ow(6, ow.number.not.infinite.not.greaterThan(5)); - }, { message: 'Expected number to not be greater than 5, got 6' }); + }, {message: 'Expected number to not be greater than 5, got 6'}); t.notThrows(() => { ow('foo!', ow.string.not.alphabetical); @@ -43,15 +43,15 @@ test('not', t => { t.throws(() => { ow('', ow.string.not.empty); - }, { message: 'Expected string to not be empty, got ``' }); + }, {message: 'Expected string to not be empty, got ``'}); t.throws(() => { ow('', 'foo', ow.string.not.empty); - }, { message: 'Expected string `foo` to not be empty, got ``' }); + }, {message: 'Expected string `foo` to not be empty, got ``'}); t.throws(() => { ow(foo, ow.string.not.empty); - }, { message: 'Expected string to not be empty, got ``' }); + }, {message: 'Expected string to not be empty, got ``'}); t.notThrows(() => { ow('a', ow.string.not.minLength(3)); @@ -61,7 +61,7 @@ test('not', t => { }); t.throws(() => { ow('abc', ow.string.not.minLength(3)); - }, { message: 'Expected string to have a maximum length of `2`, got `abc`' }); + }, {message: 'Expected string to have a maximum length of `2`, got `abc`'}); t.notThrows(() => { ow('abcd', ow.string.not.maxLength(2)); @@ -71,21 +71,21 @@ test('not', t => { }); t.throws(() => { ow('a', ow.string.not.maxLength(3)); - }, { message: 'Expected string to have a minimum length of `4`, got `a`' }); + }, {message: 'Expected string to have a minimum length of `4`, got `a`'}); t.notThrows(() => { ow({a: 1}, ow.object.not.empty); }); t.throws(() => { ow({}, ow.object.not.empty); - }, { message: 'Expected object to not be empty, got `{}`' }); + }, {message: 'Expected object to not be empty, got `{}`'}); t.notThrows(() => { ow(new Set([1]), ow.set.not.empty); }); t.throws(() => { ow(new Set([]), ow.set.not.empty); - }, { message: 'Expected Set to not be empty, got `[]`' }); + }, {message: 'Expected Set to not be empty, got `[]`'}); t.notThrows(() => { ow(new Set([1]), ow.set.not.minSize(3)); @@ -95,7 +95,7 @@ test('not', t => { }); t.throws(() => { ow(new Set([1, 2, 3]), ow.set.not.minSize(3)); - }, { message: 'Expected Set to have a maximum size of `2`, got `3`' }); + }, {message: 'Expected Set to have a maximum size of `2`, got `3`'}); t.notThrows(() => { ow(new Set([1, 2]), ow.set.not.maxSize(1)); @@ -105,14 +105,14 @@ test('not', t => { }); t.throws(() => { ow(new Set([1]), ow.set.not.maxSize(1)); - }, { message: 'Expected Set to have a minimum size of `2`, got `1`' }); + }, {message: 'Expected Set to have a minimum size of `2`, got `1`'}); t.notThrows(() => { ow(new Map([[1, 1]]), ow.map.not.empty); }); t.throws(() => { ow(new Map([]), ow.map.not.empty); - }, { message: 'Expected Map to not be empty, got `[]`' }); + }, {message: 'Expected Map to not be empty, got `[]`'}); t.notThrows(() => { ow(new Map([[1, 1]]), ow.map.not.minSize(3)); @@ -122,7 +122,7 @@ test('not', t => { }); t.throws(() => { ow(new Map([[1, 1], [2, 2], [3, 3]]), ow.map.not.minSize(3)); - }, { message: 'Expected Map to have a maximum size of `2`, got `3`' }); + }, {message: 'Expected Map to have a maximum size of `2`, got `3`'}); t.notThrows(() => { ow(new Map([[1, 1], [2, 2]]), ow.map.not.maxSize(1)); @@ -132,14 +132,14 @@ test('not', t => { }); t.throws(() => { ow(new Map([[1, 1]]), ow.map.not.maxSize(1)); - }, { message: 'Expected Map to have a minimum size of `2`, got `1`' }); + }, {message: 'Expected Map to have a minimum size of `2`, got `1`'}); t.notThrows(() => { ow(['foo'], ow.array.not.empty); }); t.throws(() => { ow([], ow.array.not.empty); - }, { message: 'Expected array to not be empty, got `[]`' }); + }, {message: 'Expected array to not be empty, got `[]`'}); t.notThrows(() => { ow([1], ow.array.not.minLength(3)); @@ -149,7 +149,7 @@ test('not', t => { }); t.throws(() => { ow([1, 2, 3], ow.array.not.minLength(3)); - }, { message: 'Expected array to have a maximum length of `2`, got `3`' }); + }, {message: 'Expected array to have a maximum length of `2`, got `3`'}); t.notThrows(() => { ow([1, 2, 3], ow.array.not.maxLength(2)); @@ -159,7 +159,7 @@ test('not', t => { }); t.throws(() => { ow([1], ow.array.not.maxLength(3)); - }, { message: 'Expected array to have a minimum length of `4`, got `1`' }); + }, {message: 'Expected array to have a minimum length of `4`, got `1`'}); t.notThrows(() => { ow(new Int8Array(1), ow.typedArray.not.minByteLength(3)); @@ -169,7 +169,7 @@ test('not', t => { }); t.throws(() => { ow(new Int8Array(3), ow.typedArray.not.minByteLength(3)); - }, { message: 'Expected TypedArray to have a maximum byte length of `2`, got `3`' }); + }, {message: 'Expected TypedArray to have a maximum byte length of `2`, got `3`'}); t.notThrows(() => { ow(new Uint8Array(4), ow.typedArray.not.maxByteLength(2)); @@ -179,7 +179,7 @@ test('not', t => { }); t.throws(() => { ow(new Uint8Array(2), ow.typedArray.not.maxByteLength(2)); - }, { message: 'Expected TypedArray to have a minimum byte length of `3`, got `2`' }); + }, {message: 'Expected TypedArray to have a minimum byte length of `3`, got `2`'}); t.notThrows(() => { ow(new Uint8ClampedArray(1), ow.typedArray.not.minLength(3)); @@ -189,7 +189,7 @@ test('not', t => { }); t.throws(() => { ow(new Float32Array(3), ow.typedArray.not.minLength(3)); - }, { message: 'Expected TypedArray to have a maximum length of `2`, got `3`' }); + }, {message: 'Expected TypedArray to have a maximum length of `2`, got `3`'}); t.notThrows(() => { ow(new Uint16Array(4), ow.typedArray.not.maxLength(2)); @@ -199,7 +199,7 @@ test('not', t => { }); t.throws(() => { ow(new Float64Array(2), ow.typedArray.not.maxLength(2)); - }, { message: 'Expected TypedArray to have a minimum length of `3`, got `2`' }); + }, {message: 'Expected TypedArray to have a minimum length of `3`, got `2`'}); t.notThrows(() => { ow(new ArrayBuffer(1), ow.arrayBuffer.not.minByteLength(3)); @@ -209,7 +209,7 @@ test('not', t => { }); t.throws(() => { ow(new ArrayBuffer(3), ow.arrayBuffer.not.minByteLength(3)); - }, { message: 'Expected ArrayBuffer to have a maximum byte length of `2`, got `3`' }); + }, {message: 'Expected ArrayBuffer to have a maximum byte length of `2`, got `3`'}); t.notThrows(() => { ow(new ArrayBuffer(4), ow.arrayBuffer.not.maxByteLength(2)); @@ -219,7 +219,7 @@ test('not', t => { }); t.throws(() => { ow(new ArrayBuffer(2), ow.arrayBuffer.not.maxByteLength(2)); - }, { message: 'Expected ArrayBuffer to have a minimum byte length of `3`, got `2`' }); + }, {message: 'Expected ArrayBuffer to have a minimum byte length of `3`, got `2`'}); t.notThrows(() => { ow(new SharedArrayBuffer(4), ow.sharedArrayBuffer.not.maxByteLength(2)); @@ -229,7 +229,7 @@ test('not', t => { }); t.throws(() => { ow(new SharedArrayBuffer(2), ow.sharedArrayBuffer.not.maxByteLength(2)); - }, { message: 'Expected SharedArrayBuffer to have a minimum byte length of `3`, got `2`' }); + }, {message: 'Expected SharedArrayBuffer to have a minimum byte length of `3`, got `2`'}); t.notThrows(() => { ow(new DataView(new ArrayBuffer(1)), ow.dataView.not.minByteLength(3)); @@ -239,7 +239,7 @@ test('not', t => { }); t.throws(() => { ow(new DataView(new ArrayBuffer(3)), ow.dataView.not.minByteLength(3)); - }, { message: 'Expected DataView to have a maximum byte length of `2`, got `3`' }); + }, {message: 'Expected DataView to have a maximum byte length of `2`, got `3`'}); t.notThrows(() => { ow(new DataView(new ArrayBuffer(4)), ow.dataView.not.maxByteLength(2)); @@ -249,13 +249,11 @@ test('not', t => { }); t.throws(() => { ow(new DataView(new ArrayBuffer(2)), ow.dataView.not.maxByteLength(2)); - }, { message: 'Expected DataView to have a minimum byte length of `3`, got `2`' }); + }, {message: 'Expected DataView to have a minimum byte length of `3`, got `2`'}); }); test('is', t => { - const greaterThan = (max: number, x: number): string | true => { - return x > max || `Expected \`${x}\` to be greater than \`${max}\``; - }; + const greaterThan = (max: number, x: number): string | true => x > max || `Expected \`${x}\` to be greater than \`${max}\``; t.notThrows(() => { ow(1, ow.number.is(x => x < 10)); @@ -263,19 +261,19 @@ test('is', t => { t.throws(() => { ow(1, ow.number.is(x => x > 10)); - }, { message: 'Expected number `1` to pass custom validation function' }); + }, {message: 'Expected number `1` to pass custom validation function'}); t.throws(() => { ow(1, 'foo', ow.number.is(x => x > 10)); - }, { message: 'Expected number `foo` `1` to pass custom validation function' }); + }, {message: 'Expected number `foo` `1` to pass custom validation function'}); t.throws(() => { ow(5, ow.number.is(x => greaterThan(10, x))); - }, { message:'(number) Expected `5` to be greater than `10`' }); + }, {message: '(number) Expected `5` to be greater than `10`'}); t.throws(() => { ow(5, 'foo', ow.number.is(x => greaterThan(10, x))); - }, { message:'(number `foo`) Expected `5` to be greater than `10`' }); + }, {message: '(number `foo`) Expected `5` to be greater than `10`'}); }); test('isValid', t => { @@ -291,8 +289,8 @@ test('isValid', t => { test('reusable validator', t => { const checkUsername = ow.create(ow.string.minLength(3)); - const checkUsername_: AssertingValidator = checkUsername; - const checkUsername__: AssertingValidator = checkUsername; + const checkUsername1: AssertingValidator = checkUsername; + const checkUsername2: AssertingValidator = checkUsername; const value = 'x'; const value_ = 'foo' as string | number; @@ -306,30 +304,30 @@ test('reusable validator', t => { }); t.notThrows(() => { - checkUsername_(value_); + checkUsername1(value_); ((_: string): void => {})(value_); // The _ function should narrow the type. If it didn't, this would not compile }); t.notThrows(() => { - checkUsername__(value_); + checkUsername2(value_); ((_: string): void => {})(value_); // The __ function should narrow the type. If it didn't, this would not compile }); t.throws(() => { checkUsername('fo'); - }, { message: 'Expected string to have a minimum length of `3`, got `fo`' }); + }, {message: 'Expected string to have a minimum length of `3`, got `fo`'}); t.throws(() => { checkUsername(value); - }, { message: 'Expected string to have a minimum length of `3`, got `x`' }); + }, {message: 'Expected string to have a minimum length of `3`, got `x`'}); const error = t.throws(() => { checkUsername(5); }, { message: [ 'Expected argument to be of type `string` but received type `number`', - 'Expected string to have a minimum length of `3`, got `5`' - ].join('\n') + 'Expected string to have a minimum length of `3`, got `5`', + ].join('\n'), }); t.is(error.validationErrors.size, 1, 'There is one item in the `validationErrors` map'); @@ -340,7 +338,7 @@ test('reusable validator', t => { t.is(result1_.size, 2, 'There are two reported errors for this input'); t.deepEqual(result1_, new Set([ 'Expected argument to be of type `string` but received type `number`', - 'Expected string to have a minimum length of `3`, got `5`' + 'Expected string to have a minimum length of `3`, got `5`', ]), 'There is an error for invalid input type, and one for minimum length not being satisfied'); }); @@ -360,19 +358,19 @@ test('reusable validator called with label', t => { t.throws(() => { checkUsername('fo', label); - }, { message: 'Expected string `bar` to have a minimum length of `3`, got `fo`' }); + }, {message: 'Expected string `bar` to have a minimum length of `3`, got `fo`'}); t.throws(() => { checkUsername(value, label); - }, { message: 'Expected string `bar` to have a minimum length of `3`, got `x`' }); + }, {message: 'Expected string `bar` to have a minimum length of `3`, got `x`'}); const error = t.throws(() => { checkUsername(5, label); }, { message: [ 'Expected `bar` to be of type `string` but received type `number`', - 'Expected string `bar` to have a minimum length of `3`, got `5`' - ].join('\n') + 'Expected string `bar` to have a minimum length of `3`, got `5`', + ].join('\n'), }); t.is(error.validationErrors.size, 1, 'There is one item in the `validationErrors` map'); @@ -383,7 +381,7 @@ test('reusable validator called with label', t => { t.is(result1_.size, 2, 'There are two reported errors for this input'); t.deepEqual(result1_, new Set([ 'Expected `bar` to be of type `string` but received type `number`', - 'Expected string `bar` to have a minimum length of `3`, got `5`' + 'Expected string `bar` to have a minimum length of `3`, got `5`', ]), 'There is an error for invalid input type, and one for minimum length not being satisfied'); }); @@ -400,15 +398,15 @@ test('reusable validator with label', t => { t.throws(() => { checkUsername('fo'); - }, { message: 'Expected string `foo` to have a minimum length of `3`, got `fo`' }); + }, {message: 'Expected string `foo` to have a minimum length of `3`, got `fo`'}); const error = t.throws(() => { checkUsername(5); }, { message: [ 'Expected `foo` to be of type `string` but received type `number`', - 'Expected string `foo` to have a minimum length of `3`, got `5`' - ].join('\n') + 'Expected string `foo` to have a minimum length of `3`, got `5`', + ].join('\n'), }); t.is(error.validationErrors.size, 1, 'There is one item in the `validationErrors` map'); @@ -419,7 +417,7 @@ test('reusable validator with label', t => { t.is(result1_.size, 2, 'There are two reported errors for this input'); t.deepEqual(result1_, new Set([ 'Expected `foo` to be of type `string` but received type `number`', - 'Expected string `foo` to have a minimum length of `3`, got `5`' + 'Expected string `foo` to have a minimum length of `3`, got `5`', ]), 'There is an error for invalid input type, and one for minimum length not being satisfied'); }); @@ -438,15 +436,15 @@ test('reusable validator with label called with label', t => { t.throws(() => { checkUsername('fo', label); - }, { message: 'Expected string `bar` to have a minimum length of `3`, got `fo`' }); + }, {message: 'Expected string `bar` to have a minimum length of `3`, got `fo`'}); const error = t.throws(() => { checkUsername(5, label); }, { message: [ 'Expected `bar` to be of type `string` but received type `number`', - 'Expected string `bar` to have a minimum length of `3`, got `5`' - ].join('\n') + 'Expected string `bar` to have a minimum length of `3`, got `5`', + ].join('\n'), }); t.is(error.validationErrors.size, 1, 'There is one item in the `validationErrors` map'); @@ -457,7 +455,7 @@ test('reusable validator with label called with label', t => { t.is(result1_.size, 2, 'There are two reported errors for this input'); t.deepEqual(result1_, new Set([ 'Expected `bar` to be of type `string` but received type `number`', - 'Expected string `bar` to have a minimum length of `3`, got `5`' + 'Expected string `bar` to have a minimum length of `3`, got `5`', ]), 'There is an error for invalid input type, and one for minimum length not being satisfied'); }); @@ -477,8 +475,8 @@ test('any-reusable validator', t => { }, { message: createAnyError( 'Expected string to include `.`, got `fo`', - 'Expected string to have a minimum length of `3`, got `fo`' - ) + 'Expected string to have a minimum length of `3`, got `fo`', + ), }); t.throws(() => { @@ -487,8 +485,8 @@ test('any-reusable validator', t => { message: createAnyError( 'Expected argument to be of type `string` but received type `number`', 'Expected string to include `.`, got `5`', - 'Expected string to have a minimum length of `3`, got `5`' - ) + 'Expected string to have a minimum length of `3`, got `5`', + ), }); }); @@ -496,21 +494,21 @@ test('custom validation function', t => { t.throws(() => { ow('🦄', 'unicorn', ow.string.validate(value => ({ message: (label): string => `Expected ${label} to be \`🌈\`, got \`${value}\``, - validator: value === '🌈' + validator: value === '🌈', }))); - }, { message: 'Expected string `unicorn` to be `🌈`, got `🦄`' }); + }, {message: 'Expected string `unicorn` to be `🌈`, got `🦄`'}); t.throws(() => { ow('🦄', 'unicorn', ow.string.validate(value => ({ message: 'Should be `🌈`', - validator: value === '🌈' + validator: value === '🌈', }))); - }, { message:'(string `unicorn`) Should be `🌈`' }); + }, {message: '(string `unicorn`) Should be `🌈`'}); t.notThrows(() => { ow('🦄', 'unicorn', ow.string.validate(value => ({ message: (label): string => `Expected ${label} to be '🦄', got \`${value}\``, - validator: value === '🦄' + validator: value === '🦄', }))); }); }); @@ -518,10 +516,10 @@ test('custom validation function', t => { test('ow without valid arguments', t => { t.throws(() => { ow(5, {} as any); - }, { message: 'Expected second argument to be a predicate or a string, got `object`' }); + }, {message: 'Expected second argument to be a predicate or a string, got `object`'}); }); -// skipped because require is not defined in esm +// Skipped because require is not defined in esm // This test is to cover all paths of source/utils/generate-stacks.ts // test('ow without Error.captureStackTrace', t => { // const originalErrorStackTrace = Error.captureStackTrace; @@ -556,9 +554,9 @@ test('ArgumentError with missing errors map', t => { throw new ArgumentError('Hi from tests!', throws); } - const error_1 = t.throws(() => { + const error1 = t.throws(() => { throws(); - }, { message: 'Hi from tests!' }); + }, {message: 'Hi from tests!'}); - t.deepEqual(error_1.validationErrors, new Map(), 'Error should default to an empty error map'); + t.deepEqual(error1.validationErrors, new Map(), 'Error should default to an empty error map'); }); diff --git a/test/typed-array.ts b/test/typed-array.ts index 536f4f7..fc92a44 100644 --- a/test/typed-array.ts +++ b/test/typed-array.ts @@ -20,15 +20,15 @@ test('typedArray', t => { t.throws(() => { ow('foo' as any, ow.typedArray); - }, { message: 'Expected argument to be of type `TypedArray` but received type `string`' }); + }, {message: 'Expected argument to be of type `TypedArray` but received type `string`'}); t.throws(() => { ow('foo' as any, 'foo', ow.typedArray); - }, { message: 'Expected `foo` to be of type `TypedArray` but received type `string`' }); + }, {message: 'Expected `foo` to be of type `TypedArray` but received type `string`'}); t.throws(() => { ow(12 as any, ow.typedArray); - }, { message: 'Expected argument to be of type `TypedArray` but received type `number`' }); + }, {message: 'Expected argument to be of type `TypedArray` but received type `number`'}); }); test('typedArray.byteLength', t => { @@ -70,11 +70,11 @@ test('typedArray.byteLength', t => { t.throws(() => { ow(new Int8Array(1), ow.typedArray.byteLength(2)); - }, { message: 'Expected TypedArray to have byte length of `2`, got `1`' }); + }, {message: 'Expected TypedArray to have byte length of `2`, got `1`'}); t.throws(() => { ow(new Int8Array(1), 'foo', ow.typedArray.byteLength(2)); - }, { message: 'Expected TypedArray `foo` to have byte length of `2`, got `1`' }); + }, {message: 'Expected TypedArray `foo` to have byte length of `2`, got `1`'}); }); test('typedArray.minByteLength', t => { @@ -88,7 +88,7 @@ test('typedArray.minByteLength', t => { t.throws(() => { ow(new Uint8Array(1), ow.typedArray.minByteLength(2)); - }, { message: 'Expected TypedArray to have a minimum byte length of `2`, got `1`' }); + }, {message: 'Expected TypedArray to have a minimum byte length of `2`, got `1`'}); }); test('typedArray.maxByteLength', t => { @@ -102,7 +102,7 @@ test('typedArray.maxByteLength', t => { t.throws(() => { ow(new Uint32Array(1), ow.typedArray.maxByteLength(1)); - }, { message: 'Expected TypedArray to have a maximum byte length of `1`, got `4`' }); + }, {message: 'Expected TypedArray to have a maximum byte length of `1`, got `4`'}); }); test('typedArray.length', t => { @@ -117,11 +117,11 @@ test('typedArray.length', t => { t.throws(() => { ow(new Float32Array(1), ow.typedArray.length(2)); - }, { message: 'Expected TypedArray to have length `2`, got `1`' }); + }, {message: 'Expected TypedArray to have length `2`, got `1`'}); t.throws(() => { ow(new Float32Array(1), 'foo', ow.typedArray.length(2)); - }, { message: 'Expected TypedArray `foo` to have length `2`, got `1`' }); + }, {message: 'Expected TypedArray `foo` to have length `2`, got `1`'}); }); }); @@ -136,7 +136,7 @@ test('typedArray.minLength', t => { t.throws(() => { ow(new Uint32Array(1), ow.typedArray.minLength(2)); - }, { message: 'Expected TypedArray to have a minimum length of `2`, got `1`' }); + }, {message: 'Expected TypedArray to have a minimum length of `2`, got `1`'}); }); test('typedArray.maxLength', t => { @@ -150,7 +150,7 @@ test('typedArray.maxLength', t => { t.throws(() => { ow(new Float64Array(2), ow.typedArray.maxLength(1)); - }, { message: 'Expected TypedArray to have a maximum length of `1`, got `2`' }); + }, {message: 'Expected TypedArray to have a maximum length of `1`, got `2`'}); }); test('int8Array', t => { @@ -160,11 +160,11 @@ test('int8Array', t => { t.throws(() => { ow('foo' as any, ow.int8Array); - }, { message: 'Expected argument to be of type `Int8Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Int8Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.int8Array); - }, { message: 'Expected argument to be of type `Int8Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Int8Array` but received type `number`'}); }); test('uint8Array', t => { @@ -174,11 +174,11 @@ test('uint8Array', t => { t.throws(() => { ow('foo' as any, ow.uint8Array); - }, { message: 'Expected argument to be of type `Uint8Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Uint8Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.uint8Array); - }, { message: 'Expected argument to be of type `Uint8Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Uint8Array` but received type `number`'}); }); test('uint8ClampedArray', t => { @@ -188,11 +188,11 @@ test('uint8ClampedArray', t => { t.throws(() => { ow('foo' as any, ow.uint8ClampedArray); - }, { message: 'Expected argument to be of type `Uint8ClampedArray` but received type `string`' }); + }, {message: 'Expected argument to be of type `Uint8ClampedArray` but received type `string`'}); t.throws(() => { ow(12 as any, ow.uint8ClampedArray); - }, { message: 'Expected argument to be of type `Uint8ClampedArray` but received type `number`' }); + }, {message: 'Expected argument to be of type `Uint8ClampedArray` but received type `number`'}); }); test('int16Array', t => { @@ -202,11 +202,11 @@ test('int16Array', t => { t.throws(() => { ow('foo' as any, ow.int16Array); - }, { message: 'Expected argument to be of type `Int16Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Int16Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.int16Array); - }, { message: 'Expected argument to be of type `Int16Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Int16Array` but received type `number`'}); }); test('uint16Array', t => { @@ -216,11 +216,11 @@ test('uint16Array', t => { t.throws(() => { ow('foo' as any, ow.uint16Array); - }, { message: 'Expected argument to be of type `Uint16Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Uint16Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.uint16Array); - }, { message: 'Expected argument to be of type `Uint16Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Uint16Array` but received type `number`'}); }); test('int32Array', t => { @@ -230,11 +230,11 @@ test('int32Array', t => { t.throws(() => { ow('foo' as any, ow.int32Array); - }, { message: 'Expected argument to be of type `Int32Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Int32Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.int32Array); - }, { message: 'Expected argument to be of type `Int32Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Int32Array` but received type `number`'}); }); test('uint32Array', t => { @@ -244,11 +244,11 @@ test('uint32Array', t => { t.throws(() => { ow('foo' as any, ow.uint32Array); - }, { message: 'Expected argument to be of type `Uint32Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Uint32Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.uint32Array); - }, { message: 'Expected argument to be of type `Uint32Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Uint32Array` but received type `number`'}); }); test('float32Array', t => { @@ -258,11 +258,11 @@ test('float32Array', t => { t.throws(() => { ow('foo' as any, ow.float32Array); - }, { message: 'Expected argument to be of type `Float32Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Float32Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.float32Array); - }, { message: 'Expected argument to be of type `Float32Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Float32Array` but received type `number`'}); }); test('float64Array', t => { @@ -272,9 +272,9 @@ test('float64Array', t => { t.throws(() => { ow('foo' as any, ow.float64Array); - }, { message: 'Expected argument to be of type `Float64Array` but received type `string`' }); + }, {message: 'Expected argument to be of type `Float64Array` but received type `string`'}); t.throws(() => { ow(12 as any, ow.float64Array); - }, { message: 'Expected argument to be of type `Float64Array` but received type `number`' }); + }, {message: 'Expected argument to be of type `Float64Array` but received type `number`'}); }); diff --git a/test/types.ts b/test/types.ts index 67fd2b1..3289b3f 100644 --- a/test/types.ts +++ b/test/types.ts @@ -1,3 +1,4 @@ +import type {Buffer} from 'node:buffer'; import test from 'ava'; import {ExpectTypeOf, expectTypeOf} from 'expect-type'; import {TypedArray} from 'type-fest'; @@ -78,7 +79,7 @@ function typeTests(value: unknown): Array<(() => void)> { expectTypeOf(value).toBeObject(); ow(value, ow.object.partialShape({ - foo: ow.string + foo: ow.string, })); expectTypeOf(value).toEqualTypeOf<{ @@ -88,8 +89,8 @@ function typeTests(value: unknown): Array<(() => void)> { ow(value, ow.object.exactShape({ foo: ow.string, bar: ow.object.exactShape({ - baz: ow.number - }) + baz: ow.number, + }), })); expectTypeOf(value).toEqualTypeOf<{ @@ -106,7 +107,7 @@ function typeTests(value: unknown): Array<(() => void)> { const tests: Tests = { array: expect => expect.toBeArray(), arrayBuffer: expect => expect.toEqualTypeOf(), - // @ts-expect-error + // @ts-expect-error not why this doesn't work bigint: expect => expect.toEqualTypeOf(), boolean: expect => expect.toBeBoolean(), buffer: expect => expect.toEqualTypeOf(), @@ -139,7 +140,7 @@ function typeTests(value: unknown): Array<(() => void)> { uint8ClampedArray: expect => expect.toEqualTypeOf(), undefined: expect => expect.toEqualTypeOf(), weakMap: expect => expect.toEqualTypeOf>(), - weakSet: expect => expect.toEqualTypeOf>() + weakSet: expect => expect.toEqualTypeOf>(), }; return tests; @@ -184,10 +185,10 @@ function typeTests(value: unknown): Array<(() => void)> { nested: ow.object.exactShape({ nested: ow.array.ofType( ow.object.exactShape({ - nested: ow.number - }) - ) - }) + nested: ow.number, + }), + ), + }), }); expectTypeOf>().toEqualTypeOf<{ @@ -229,6 +230,6 @@ function typeTests(value: unknown): Array<(() => void)> { nested: Array<{nested: number}>; }; }>(); - } + }, ]; } diff --git a/test/undefined.ts b/test/undefined.ts index fc59bc0..1dfe1d9 100644 --- a/test/undefined.ts +++ b/test/undefined.ts @@ -19,17 +19,17 @@ test('undefined', t => { t.throws(() => { ow(y as any, ow.undefined); - }, { message: 'Expected argument to be of type `undefined` but received type `number`' }); + }, {message: 'Expected argument to be of type `undefined` but received type `number`'}); t.throws(() => { ow(y as any, 'foo', ow.undefined); - }, {message: 'Expected `foo` to be of type `undefined` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `undefined` but received type `number`'}); t.throws(() => { ow(null as any, ow.undefined); - }, {message: 'Expected argument to be of type `undefined` but received type `null`' }); + }, {message: 'Expected argument to be of type `undefined` but received type `null`'}); t.throws(() => { ow('foo' as any, ow.undefined); - }, {message: 'Expected argument to be of type `undefined` but received type `string`' }); + }, {message: 'Expected argument to be of type `undefined` but received type `string`'}); }); diff --git a/test/weak-map.ts b/test/weak-map.ts index 6e7aa79..df6d51f 100644 --- a/test/weak-map.ts +++ b/test/weak-map.ts @@ -12,7 +12,7 @@ test('weakMap', t => { t.throws(() => { ow(12 as any, ow.weakMap); - }, { message: 'Expected argument to be of type `WeakMap` but received type `number`' }); + }, {message: 'Expected argument to be of type `WeakMap` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.weakMap); @@ -30,19 +30,19 @@ test('weakMap.hasKeys', t => { t.throws(() => { ow(new WeakMap([[{rainbow: true}, '🌈']]), ow.weakMap.hasKeys({rainbow: true})); - }, {message: 'Expected WeakMap to have keys `[{"rainbow":true}]`' }); + }, {message: 'Expected WeakMap to have keys `[{"rainbow":true}]`'}); t.throws(() => { ow(new WeakMap([[{rainbow: true}, '🌈']]), 'foo', ow.weakMap.hasKeys({rainbow: true})); - }, { message: 'Expected WeakMap `foo` to have keys `[{"rainbow":true}]`' }); + }, {message: 'Expected WeakMap `foo` to have keys `[{"rainbow":true}]`'}); t.throws(() => { ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasKeys(unicorn, {rainbow: true})); - }, { message: 'Expected WeakMap to have keys `[{"rainbow":true}]`'}); + }, {message: 'Expected WeakMap to have keys `[{"rainbow":true}]`'}); t.throws(() => { ow(new WeakMap([[keys[0]!, 1], [keys[2]!, 3]]), ow.weakMap.hasKeys(...keys)); - }, { message: 'Expected WeakMap to have keys `[{"x":2},{"x":4},{"x":5},{"x":6},{"x":7}]`' }); + }, {message: 'Expected WeakMap to have keys `[{"x":2},{"x":4},{"x":5},{"x":6},{"x":7}]`'}); }); test('weakMap.hasAnyKeys', t => { @@ -64,5 +64,5 @@ test('weakMap.hasAnyKeys', t => { t.throws(() => { ow(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), ow.weakMap.hasAnyKeys(rocket)); - }, { message: 'Expected WeakMap to have any key of `[{"rocket":true}]`' }); + }, {message: 'Expected WeakMap to have any key of `[{"rocket":true}]`'}); }); diff --git a/test/weak-set.ts b/test/weak-set.ts index 3fc9224..7e4c0f7 100644 --- a/test/weak-set.ts +++ b/test/weak-set.ts @@ -20,11 +20,11 @@ test('weakSet', t => { t.throws(() => { ow(12 as any, ow.weakSet); - }, { message: 'Expected argument to be of type `WeakSet` but received type `number`' }); + }, {message: 'Expected argument to be of type `WeakSet` but received type `number`'}); t.throws(() => { ow(12 as any, 'foo', ow.weakSet); - }, { message: 'Expected `foo` to be of type `WeakSet` but received type `number`' }); + }, {message: 'Expected `foo` to be of type `WeakSet` but received type `number`'}); }); test('weakSet.has', t => { @@ -40,19 +40,19 @@ test('weakSet.has', t => { t.throws(() => { ow(new WeakSet([unicorn, rainbow]), ow.weakSet.has(rocket)); - }, { message: 'Expected WeakSet to have items `[{"rocket":"🚀"}]`' }); + }, {message: 'Expected WeakSet to have items `[{"rocket":"🚀"}]`'}); t.throws(() => { ow(new WeakSet([unicorn, rainbow]), 'foo', ow.weakSet.has(rocket)); - }, { message: 'Expected WeakSet `foo` to have items `[{"rocket":"🚀"}]`' }); + }, {message: 'Expected WeakSet `foo` to have items `[{"rocket":"🚀"}]`'}); t.throws(() => { ow(new WeakSet([unicorn, rocket]), ow.weakSet.has(rainbow, rocket)); - }, { message: 'Expected WeakSet to have items `[{"rainbow":"🌈"}]`' }); + }, {message: 'Expected WeakSet to have items `[{"rainbow":"🌈"}]`'}); t.throws(() => { ow(new WeakSet([keys[1]!, keys[3]!]), ow.weakSet.has(...keys)); - }, { message: 'Expected WeakSet to have items `[{"x":1},{"x":3},{"x":5},{"x":6},{"x":7}]`' }); + }, {message: 'Expected WeakSet to have items `[{"x":1},{"x":3},{"x":5},{"x":6},{"x":7}]`'}); }); test('weakSet.hasAny', t => { @@ -66,5 +66,5 @@ test('weakSet.hasAny', t => { t.throws(() => { ow(new WeakSet([unicorn, rainbow]), ow.weakSet.hasAny(rocket)); - }, { message: 'Expected WeakSet to have any item of `[{"rocket":"🚀"}]`' }); + }, {message: 'Expected WeakSet to have any item of `[{"rocket":"🚀"}]`'}); }); From 9cfceb18ebf7282236e849b21168fa76562ea373 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Oct 2021 14:53:34 +0700 Subject: [PATCH 07/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d7ab63..539d059 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "^0.45.0" + "xo": "github:xojs/xo#ada5d0432bdb724687881a405851c9af822d7261" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 4fe3d0460e8502af9976f0131602506020c89cb2 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Oct 2021 14:58:04 +0700 Subject: [PATCH 08/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 539d059..fb12b27 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:xojs/xo#ada5d0432bdb724687881a405851c9af822d7261" + "xo": "github:xojs/xo#4f051953b45fb2e5ea446834c4d271963985e084" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From c9fda78aed67fb5dbc99173d4ea4c93f56ae89ab Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Oct 2021 15:19:02 +0700 Subject: [PATCH 09/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb12b27..1a7874c 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:xojs/xo#4f051953b45fb2e5ea446834c4d271963985e084" + "xo": "github:xojs/xo#278635176d3dc69a0065953aa6e8b624ccd4ac95" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 6a98d138bb78f3b99f7988d14d1f8a76dd03ef2b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Oct 2021 22:49:19 +0700 Subject: [PATCH 10/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a7874c..4e44bde 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:xojs/xo#278635176d3dc69a0065953aa6e8b624ccd4ac95" + "xo": "github:fisker/xo#208a48de76e5eb3225ca456516fd155600e4ddac" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 2653e2c1ff3f4d15246c4935965b667ab60d60a4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 20 Oct 2021 11:12:19 +0700 Subject: [PATCH 11/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e44bde..664010d 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:fisker/xo#208a48de76e5eb3225ca456516fd155600e4ddac" + "xo": "github:Spence-S/xo#ffc482368cc2df5cbcf37bbbc07c37c707308d13" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 2f4b254109538c010d3235bc28a80d24221a8002 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 21 Oct 2021 01:14:18 +0700 Subject: [PATCH 12/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 664010d..4e179a9 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:Spence-S/xo#ffc482368cc2df5cbcf37bbbc07c37c707308d13" + "xo": "github:Spence-S/xo#221131c9156953aad63f6f2a57cb14258211dec3" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From e0f209f692999025258d0ef96f6f12fcfacefae3 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 21 Oct 2021 23:11:18 +0700 Subject: [PATCH 13/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e179a9..57abb96 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.3.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:Spence-S/xo#221131c9156953aad63f6f2a57cb14258211dec3" + "xo": "github:Spence-S/xo#9d4286767a4e580eb90b85dac8cd796c0c3e905b" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From c3b31331f961446a60562419a09cfc4cac44776e Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Thu, 21 Oct 2021 22:45:15 +0200 Subject: [PATCH 14/22] fix: coverage --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 57abb96..6b77c3c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "node": ">=12" }, "scripts": { - "test": "xo && nyc ava", + "test": "xo && c8 --reporter=html --reporter=text ava", "docs": "typedoc source/index.ts", "build": "del-cli dist && tsc", "prepare": "npm run build", @@ -63,11 +63,11 @@ "@types/node": "^16.10.2", "@types/vali-date": "^1.0.0", "ava": "^3.15.0", + "c8": "^7.10.0", "del-cli": "^4.0.0", "expect-type": "^0.12.0", "gh-pages": "^3.2.3", - "nyc": "^15.1.0", - "ts-node": "^10.3.0", + "ts-node": "^10.3.1", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", "xo": "github:Spence-S/xo#9d4286767a4e580eb90b85dac8cd796c0c3e905b" From e3ea9daf65f6fc658e64de7792a312205d14db3a Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Fri, 22 Oct 2021 22:20:09 +0200 Subject: [PATCH 15/22] update ts-node to fix ci --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b77c3c..c086cbb 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "del-cli": "^4.0.0", "expect-type": "^0.12.0", "gh-pages": "^3.2.3", - "ts-node": "^10.3.1", + "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", "xo": "github:Spence-S/xo#9d4286767a4e580eb90b85dac8cd796c0c3e905b" From 123cf1d6f5f0ed85301cdccd9872979911865ae6 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Fri, 22 Oct 2021 22:36:52 +0200 Subject: [PATCH 16/22] run code coverage on node 16 because code coverage on node 14 fails for some reason --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0dc80c9..743d241 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,6 @@ jobs: - run: npm install --force - run: npm test - uses: codecov/codecov-action@v1 - if: matrix.node-version == 14 + if: matrix.node-version == 16 with: fail_ci_if_error: true From 0b2f9970dbff94442428c63bded7f739c9efbd64 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Sun, 24 Oct 2021 09:22:04 +0200 Subject: [PATCH 17/22] use package json config instead of cli flags for c8 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c086cbb..4a1a540 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "node": ">=12" }, "scripts": { - "test": "xo && c8 --reporter=html --reporter=text ava", + "test": "xo && c8 ava", "docs": "typedoc source/index.ts", "build": "del-cli dist && tsc", "prepare": "npm run build", @@ -113,7 +113,7 @@ "ts": "module" } }, - "nyc": { + "c8": { "reporter": [ "text", "lcov" From 32548c5a102e14fd5f5912a295de7fcbc8faca18 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 27 Oct 2021 23:05:53 +0700 Subject: [PATCH 18/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a1a540..955db6f 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "github:Spence-S/xo#9d4286767a4e580eb90b85dac8cd796c0c3e905b" + "xo": "^0.46.0" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 85098225e33c2162492b8f07daebaf791abf4583 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 28 Oct 2021 13:39:53 +0700 Subject: [PATCH 19/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 955db6f..bd5d717 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "^0.46.0" + "xo": "^0.46.1" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From a11393393c2b7ec6b35a0146aad32050431a041d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 28 Oct 2021 15:42:41 +0700 Subject: [PATCH 20/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd5d717..778b412 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "^0.46.1" + "xo": "^0.46.3" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From db0eef899a8f2a26aef84e5381a3af568947df88 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 3 Nov 2021 17:55:53 +0700 Subject: [PATCH 21/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 778b412..e802869 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "^0.46.3" + "xo": "Spence-S/xo#090fc029a425bd90866f48d11ed593f4e265189f" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" From 44ebfe0407ddcf16e62de190856c16b7650b292d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 3 Nov 2021 22:21:20 +0700 Subject: [PATCH 22/22] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e802869..cc3c9e8 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ts-node": "^10.4.0", "typedoc": "^0.22.5", "typescript": "^4.5.0-beta", - "xo": "Spence-S/xo#090fc029a425bd90866f48d11ed593f4e265189f" + "xo": "^0.46.4" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js"