size

说明

返回任意值的长度

源码

用法

size.test.ts
1
import { size } from "../../utility/others/sizse";
2
3
describe('size tests...', () => {
4
5
test('size() should return zero when receive a special character', () => {
6
const received = [0, 100, undefined, null, Symbol('ddzy'), function () { }];
7
const expected = [0, 0, 0, 0, 0, 0];
8
9
received.forEach((v, i) => {
10
const result = size(v);
11
12
expect(result).toBe(expected[i]);
13
});
14
});
15
16
test('size() should return the correct length of string', () => {
17
const received = ['', 'ddzy'];
18
const expected = [0, 4];
19
20
received.forEach((v, i) => {
21
const result = size(v);
22
23
expect(result).toBe(expected[i]);
24
});
25
});
26
27
test('size() should return the correct length of array', () => {
28
const received = [[], [0, 1, 2, 3, 4, 5]];
29
const expected = [0, 6];
30
31
received.forEach((v, i) => {
32
const result = size(v);
33
34
expect(result).toBe(expected[i]);
35
});
36
});
37
38
test('size() should return the correct length of array', () => {
39
const received = [{}, { name: 'duanzhaoyang', age: 21 }];
40
const expected = [0, 2];
41
42
received.forEach((v, i) => {
43
const result = size(v);
44
45
expect(result).toBe(expected[i]);
46
});
47
});
48
49
});
Copied!
最近更新 1yr ago
复制链接