UNPKG

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