Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 30, 2020
1 parent b3c5fbd commit 48cb4c1
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 64 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
"object"
],
"dependencies": {
"type-fest": "^0.11.0"
"type-fest": "^0.17.0"
},
"devDependencies": {
"@sindresorhus/is": "^2.1.0",
"@sindresorhus/is": "^3.1.2",
"@sindresorhus/tsconfig": "^0.7.0",
"@types/lodash.isequal": "^4.5.2",
"@types/node": "^13.7.4",
"@types/node": "^14.11.2",
"@types/vali-date": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"add-asset-webpack-plugin": "^1.0.0",
"add-module-exports-webpack-plugin": "^1.0.0",
"ava": "^2.0.0",
Expand All @@ -66,16 +66,16 @@
"codecov": "^3.1.0",
"del-cli": "^3.0.0",
"dot-prop": "^5.2.0",
"eslint-config-xo-typescript": "^0.26.0",
"eslint-config-xo-typescript": "^0.33.0",
"license-webpack-plugin": "^2.0.2",
"lodash.isequal": "^4.5.0",
"nyc": "^15.0.0",
"typedoc": "^0.16.10",
"typescript": "~3.8.2",
"typedoc": "^0.19.2",
"typescript": "~4.0.3",
"vali-date": "^1.0.0",
"webpack": "^4.33.0",
"webpack-cli": "^3.3.10",
"xo": "^0.26.1"
"xo": "^0.33.1"
},
"browser": {
"./dist/source/utils/infer-label.js": "./dist/source/utils/infer-label.browser.js"
Expand All @@ -94,14 +94,14 @@
],
"rules": {
"no-useless-return": "off",
"@typescript-eslint/generic-type-naming": "off",
"@typescript-eslint/member-naming": "off",
"ava/no-ignored-test-files": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/restrict-template-expressions": "off"
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/no-anonymous-default-export": "off"
}
},
"ava": {
Expand Down
30 changes: 11 additions & 19 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,36 @@ export type Main = <T>(value: T, label: string | Function, predicate: BasePredic
// Extends is only necessary for the generated documentation to be cleaner. The loaders below infer the correct type.
export interface Ow extends Modifiers, Predicates {
/**
Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
Returns `true` if the value matches the predicate, otherwise returns `false`.
@param value - Value to test.
@param predicate - Predicate to test against.
*/
<T>(value: T, predicate: BasePredicate<T>): void;
isValid: <T>(value: T, predicate: BasePredicate<T>) => value is T;

/**
Test if `value` matches the provided `predicate`. Throws an `ArgumentError` with the specified `label` if the test fails.
Create a reusable validator.
@param value - Value to test.
@param label - Label which should be used in error messages.
@param predicate - Predicate to test against.
@param predicate - Predicate used in the validator function.
*/
<T>(value: T, label: string, predicate: BasePredicate<T>): void;
create: (<T>(predicate: BasePredicate<T>) => ReusableValidator<T>) & (<T>(label: string, predicate: BasePredicate<T>) => ReusableValidator<T>);

/**
Returns `true` if the value matches the predicate, otherwise returns `false`.
Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
@param value - Value to test.
@param predicate - Predicate to test against.
*/
isValid<T>(value: T, predicate: BasePredicate<T>): value is T;

/**
Create a reusable validator.
@param predicate - Predicate used in the validator function.
*/
create<T>(predicate: BasePredicate<T>): ReusableValidator<T>;
<T>(value: T, predicate: BasePredicate<T>): void;

/**
Create a reusable validator.
Test if `value` matches the provided `predicate`. Throws an `ArgumentError` with the specified `label` if the test fails.
@param value - Value to test.
@param label - Label which should be used in error messages.
@param predicate - Predicate used in the validator function.
@param predicate - Predicate to test against.
*/
create<T>(label: string, predicate: BasePredicate<T>): ReusableValidator<T>;
<T>(value: T, label: string, predicate: BasePredicate<T>): void;
}

/**
Expand Down
22 changes: 11 additions & 11 deletions source/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ export interface Predicates {
/**
Test that the value matches at least one of the given predicates.
*/
any<T1>(p1: BasePredicate<T1>): AnyPredicate<T1>;
any<T1, T2>(p1: BasePredicate<T1>, p2: BasePredicate<T2>): AnyPredicate<T1 | T2>;
any<T1, T2, T3>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>): AnyPredicate<T1 | T2 | T3>;
any<T1, T2, T3, T4>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>): AnyPredicate<T1 | T2 | T3 | T4>;
any<T1, T2, T3, T4, T5>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>): AnyPredicate<T1 | T2 | T3 | T4 | T5>;
any<T1, T2, T3, T4, T5, T6>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>;
any<T1, T2, T3, T4, T5, T6, T7>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
any<T1, T2, T3, T4, T5, T6, T7, T8>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
any<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
any<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>, p10: BasePredicate<T10>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
any(...predicate: BasePredicate[]): AnyPredicate;
any: (<T1>(p1: BasePredicate<T1>) => AnyPredicate<T1>)
& (<T1, T2>(p1: BasePredicate<T1>, p2: BasePredicate<T2>) => AnyPredicate<T1 | T2>)
& (<T1, T2, T3>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>) => AnyPredicate<T1 | T2 | T3>)
& (<T1, T2, T3, T4>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>) => AnyPredicate<T1 | T2 | T3 | T4>)
& (<T1, T2, T3, T4, T5>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>) => AnyPredicate<T1 | T2 | T3 | T4 | T5>)
& (<T1, T2, T3, T4, T5, T6>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>)
& (<T1, T2, T3, T4, T5, T6, T7>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>)
& (<T1, T2, T3, T4, T5, T6, T7, T8>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>)
& (<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>)
& (<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>, p10: BasePredicate<T10>) => AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>)
& ((...predicate: BasePredicate[]) => AnyPredicate);
}

export default <T>(object: T, options?: PredicateOptions): T & Predicates => {
Expand Down
4 changes: 2 additions & 2 deletions source/predicates/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export class AnyPredicate<T = unknown> implements BasePredicate<T> {
try {
main(value, label, predicate);
return;
} catch (error) {
} catch (error: unknown) {
if (value === undefined && this.options.optional === true) {
return;
}

errors.push(`- ${error.message}`);
errors.push(`- ${(error as Error).message}`);
}
}

Expand Down
8 changes: 4 additions & 4 deletions source/predicates/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class ArrayPredicate<T = unknown> extends Predicate<T[]> {
includes(...searchElements: readonly T[]) {
return this.addValidator({
message: (value, label) => `Expected ${label} to include all elements of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``,
validator: value => searchElements.every(el => value.includes(el))
validator: value => searchElements.every(element => value.includes(element))
});
}

Expand All @@ -93,7 +93,7 @@ export class ArrayPredicate<T = unknown> extends Predicate<T[]> {
includesAny(...searchElements: readonly T[]) {
return this.addValidator({
message: (value, label) => `Expected ${label} to include any element of \`${JSON.stringify(searchElements)}\`, got \`${JSON.stringify(value)}\``,
validator: value => searchElements.some(el => value.includes(el))
validator: value => searchElements.some(element => value.includes(element))
});
}

Expand Down Expand Up @@ -151,8 +151,8 @@ export class ArrayPredicate<T = unknown> extends Predicate<T[]> {
}

return true;
} catch (error_) {
error = error_.message;
} catch (error_: unknown) {
error = (error_ as Error).message;
return false;
}
}
Expand Down
1 change: 1 addition & 0 deletions source/predicates/base-predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export const isPredicate = (value: unknown): value is BasePredicate => Boolean((
@hidden
*/
export interface BasePredicate<T = unknown> {
// eslint-disable-next-line @typescript-eslint/method-signature-style
[testSymbol](value: T, main: Main, label: string | Function): void;
}
4 changes: 3 additions & 1 deletion source/predicates/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ export type ValidatorMessageBuilder<T> = (value: T, label?: string) => string;
@hidden
*/
export interface Validator<T> {
// eslint-disable-next-line @typescript-eslint/method-signature-style
message(value: T, label?: string, result?: any): string;

// eslint-disable-next-line @typescript-eslint/method-signature-style
validator(value: T): unknown;

/**
Provide custom message used by `not` operator.
When absent, the return value of `message()` is used and 'not' is inserted after the first 'to', e.g. `Expected 'smth' to be empty` -> `Expected 'smth' to not be empty`.
*/
negatedMessage?(value: T, label: string): string;
negatedMessage?(value: T, label: string): string; // eslint-disable-line @typescript-eslint/method-signature-style
}

/**
Expand Down
4 changes: 2 additions & 2 deletions source/predicates/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class StringPredicate extends Predicate<string> {
get alphabetical() {
return this.addValidator({
message: (value, label) => `Expected ${label} to be alphabetical, got \`${value}\``,
validator: value => /^[a-z]+$/ig.test(value)
validator: value => /^[a-z]+$/gi.test(value)
});
}

Expand All @@ -175,7 +175,7 @@ export class StringPredicate extends Predicate<string> {
get numeric() {
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)
});
}

Expand Down
2 changes: 1 addition & 1 deletion source/utils/has-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@hidden
*/
export interface CollectionLike<T> {
has(item: T): boolean;
has: (item: T) => boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion source/utils/is-valid-identifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const identifierRegex = /^[a-z$_][a-z$_\d]*$/i;
const identifierRegex = /^[a-z$_][$\w]*$/i;

const reservedSet = new Set([
'undefined',
Expand Down
8 changes: 4 additions & 4 deletions source/utils/match-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function partial(object: {[key: string]: any}, shape: Shape, parent?: str
}

return true;
} catch (error) {
return error.message;
} catch (error: unknown) {
return (error as Error).message;
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ export function exact(object: {[key: string]: any}, shape: Shape, parent?: strin
}

return true;
} catch (error) {
return error.message;
} catch (error: unknown) {
return (error as Error).message;
}
}
4 changes: 2 additions & 2 deletions source/utils/of-type-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Test all the values in the object against a provided predicate.
export default (object: unknown, predicate: Predicate): boolean | string => {
try {
return ofTypeDeep(object, predicate);
} catch (error) {
return error.message;
} catch (error: unknown) {
return (error as Error).message;
}
};
4 changes: 2 additions & 2 deletions source/utils/of-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default <T>(source: IterableIterator<T> | Set<T> | T[], predicate: BasePr
}

return true;
} catch (error) {
return error.message;
} catch (error: unknown) {
return (error as Error).message;
}
};
2 changes: 1 addition & 1 deletion test/custom-message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import {default as ow, Predicate} from '../source';
import ow, {Predicate} from '../source';

class CustomPredicate extends Predicate<any> {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion test/custom-predicate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import {default as ow, Predicate} from '../source';
import ow, {Predicate} from '../source';

class CustomPredicate extends Predicate<string> {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion test/nan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ow from '../source';

test('nan', t => {
t.notThrows(() => {
ow(NaN, ow.nan);
ow(Number.NaN, ow.nan);
});

t.notThrows(() => {
Expand Down

0 comments on commit 48cb4c1

Please sign in to comment.