-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
36 lines (35 loc) · 1.06 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { getProto, isArray } from '../../internal/builtin'
/**
* Checks if a value passes `Array.isArray` and has prototype `Array.prototype`.
*
* @param value The value to check.
* @returns `true` if the check passes, `false` otherwise.
*
* @remarks
* This is useful for checking that the prototype of an array has not been
* modified. However, this will return `false` for arrays created in other
* realms since they will have a different prototype.
*
* @example
* #### Basic usage
* ```ts
* isPlainArray([]) // true
* isPlainArray(new Array()) // true
*
* isPlainArray(new Uint16Array()) // false
* isPlainArray(Object.create(Array.prototype)) // false
* isPlainArray(Object.create(null)) // false
* isPlainArray(null) // false
* ```
*
* Comparison with `Array.isArray`:
* ```ts
* class MyArray extends Array {}
* Array.isArray(new MyArray()) // true
* isPlainArray(new MyArray()) // false
* ```
* @category Is
*/
export const isPlainArray = (value: unknown): value is unknown[] => {
return isArray(value) && getProto(value) === Array.prototype
}