0
# Collection Validation
1
2
Functions for validating arrays, objects, and their properties.
3
4
## Capabilities
5
6
### Array Operations
7
8
#### In Array Check
9
10
Checks if a given value is present in an array.
11
12
```javascript { .api }
13
/**
14
* Checks if the given item is in array
15
* @param value - Value to search for
16
* @param array - Array to search in
17
* @returns True if value is found in array
18
* Interfaces: not
19
*/
20
function inArray(value: any, array: any[]): boolean;
21
```
22
23
**Usage Example:**
24
25
```javascript
26
is.inArray(2, [1, 2, 3]); // true
27
is.inArray(4, [1, 2, 3]); // false
28
is.not.inArray(4, [1, 2, 3]); // true
29
```
30
31
#### Sorted Check
32
33
Checks if the given array is sorted, with optional comparison operator.
34
35
```javascript { .api }
36
/**
37
* Checks if the given array is sorted
38
* @param array - Array to check
39
* @param sign - Optional comparison operator ('>=', '>', '<=', '<')
40
* @returns True if array is sorted according to the specified order
41
* Interfaces: not, all, any
42
*/
43
function sorted(array: any[], sign?: string): boolean;
44
```
45
46
**Usage Example:**
47
48
```javascript
49
is.sorted([1, 2, 3]); // true (default: ascending)
50
is.sorted([1, 2, 4, 3]); // false
51
is.sorted([1, 1, 2, 2], '>='); // true
52
is.sorted([1, 2, 3, 4], '>'); // true
53
is.sorted([4, 3, 3, 1], '<='); // true
54
is.sorted([4, 3, 2, 1], '<'); // true
55
is.sorted([1, 2, 3, 3], '>'); // false
56
is.not.sorted([5, 4, 3]); // true
57
is.all.sorted([1, 2], [3, 4]); // true
58
is.any.sorted([1, 2], [5, 4]); // true
59
```
60
61
### Object Operations
62
63
#### Property Count Check
64
65
Checks if an object has exactly the specified number of properties.
66
67
```javascript { .api }
68
/**
69
* Checks if objects' property count is equal to given count
70
* @param object - Object to check
71
* @param count - Expected number of properties
72
* @returns True if object has exactly count properties
73
* Interfaces: not
74
*/
75
function propertyCount(object: any, count: number): boolean;
76
```
77
78
**Usage Example:**
79
80
```javascript
81
is.propertyCount({this: 'is', 'sample': 'object'}, 2); // true
82
is.propertyCount({this: 'is', 'sample': 'object'}, 3); // false
83
is.not.propertyCount({}, 2); // true
84
```
85
86
#### Property Defined Check
87
88
Checks if a specific property is defined on an object.
89
90
```javascript { .api }
91
/**
92
* Checks if the given property is defined on object
93
* @param object - Object to check
94
* @param property - Property name to check for
95
* @returns True if property exists on object
96
* Interfaces: not
97
*/
98
function propertyDefined(object: any, property: string): boolean;
99
```
100
101
**Usage Example:**
102
103
```javascript
104
is.propertyDefined({yeap: 'yeap'}, 'yeap'); // true
105
is.propertyDefined({yeap: 'yeap'}, 'nope'); // false
106
is.not.propertyDefined({}, 'nope'); // true
107
```