UNPKG

3.23 kBTypeScriptView Raw
1import { Shape, TypeOfShape } from '../utils/match-shape';
2import { Predicate, PredicateOptions } from './predicate';
3import { BasePredicate } from './base-predicate';
4export { Shape };
5export declare class ObjectPredicate<T extends object = object> extends Predicate<T> {
6 /**
7 @hidden
8 */
9 constructor(options?: PredicateOptions);
10 /**
11 Test if an Object is a plain object.
12 */
13 get plain(): this;
14 /**
15 Test an object to be empty.
16 */
17 get empty(): this;
18 /**
19 Test an object to be not empty.
20 */
21 get nonEmpty(): this;
22 /**
23 Test all the values in the object to match the provided predicate.
24
25 @param predicate - The predicate that should be applied against every value in the object.
26 */
27 valuesOfType<T>(predicate: BasePredicate<T>): this;
28 /**
29 Test all the values in the object deeply to match the provided predicate.
30
31 @param predicate - The predicate that should be applied against every value in the object.
32 */
33 deepValuesOfType<T>(predicate: Predicate<T>): this;
34 /**
35 Test an object to be deeply equal to the provided object.
36
37 @param expected - Expected object to match.
38 */
39 deepEqual(expected: object): this;
40 /**
41 Test an object to be of a specific instance type.
42
43 @param instance - The expected instance type of the object.
44 */
45 instanceOf(instance: Function): this;
46 /**
47 Test an object to include all the provided keys. You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.
48
49 @param keys - The keys that should be present in the object.
50 */
51 hasKeys(...keys: readonly string[]): this;
52 /**
53 Test an object to include any of the provided keys. You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.
54
55 @param keys - The keys that could be a key in the object.
56 */
57 hasAnyKeys(...keys: readonly string[]): this;
58 /**
59 Test an object to match the `shape` partially. This means that it ignores unexpected properties. The shape comparison is deep.
60
61 The shape is an object which describes how the tested object should look like. The keys are the same as the source object and the values are predicates.
62
63 @param shape - Shape to test the object against.
64
65 @example
66 ```
67 import ow from 'ow';
68
69 const object = {
70 unicorn: '🦄',
71 rainbow: '🌈'
72 };
73
74 ow(object, ow.object.partialShape({
75 unicorn: ow.string
76 }));
77 ```
78 */
79 partialShape<S extends Shape = Shape>(shape: S): ObjectPredicate<TypeOfShape<S>>;
80 /**
81 Test an object to match the `shape` exactly. This means that will fail if it comes across unexpected properties. The shape comparison is deep.
82
83 The shape is an object which describes how the tested object should look like. The keys are the same as the source object and the values are predicates.
84
85 @param shape - Shape to test the object against.
86
87 @example
88 ```
89 import ow from 'ow';
90
91 ow({unicorn: '🦄'}, ow.object.exactShape({
92 unicorn: ow.string
93 }));
94 ```
95 */
96 exactShape<S extends Shape = Shape>(shape: S): ObjectPredicate<TypeOfShape<S>>;
97}
98
\No newline at end of file