isPlainObject

说明

判断是否普通的键值对对象

源码

用法

isPlainObject.test.ts
1
import { isPlainObject } from "../../utility/object/isPlainObject";
2
3
describe('isPlainObject', () => {
4
test('isPlainObject should return `true` if received a plain object', () => {
5
const received = [
6
{ name: 'duan', age: 20 },
7
{},
8
];
9
10
for (const v of received) {
11
expect(isPlainObject(v)).toBeTruthy();
12
}
13
});
14
15
test('isPlainObject should return `false` if received a non plain object', () => {
16
document.body.innerHTML += `
17
<p></p>
18
<p></p>
19
`;
20
21
const received = [
22
document.querySelectorAll('p'),
23
[1, 2, 3],
24
null,
25
undefined,
26
0,
27
'',
28
false,
29
true
30
];
31
32
for (const v of received) {
33
expect(isPlainObject(v)).toBeFalsy();
34
}
35
});
36
})
37
Copied!
最近更新 1yr ago
复制链接