@lambo-design/shared 1.0.0-beta.237 → 1.0.0-beta.239
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/config.js +51 -51
- package/config/env.js +4 -4
- package/config/index.js +7 -7
- package/config/themes/atrovirens/atrovirens.css +575 -575
- package/config/themes/atrovirens/atrovirens.less +667 -667
- package/config/themes/atrovirens/var.less +674 -674
- package/config/themes/blue/blue.css +575 -575
- package/config/themes/blue/blue.less +669 -669
- package/config/themes/blue/var.less +677 -677
- package/config/themes/blue-white/blue-white.css +575 -575
- package/config/themes/blue-white/blue-white.less +669 -669
- package/config/themes/blue-white/var.less +676 -676
- package/config/themes/blue-white-tight/blue-white-tight.css +576 -576
- package/config/themes/blue-white-tight/blue-white-tight.less +672 -672
- package/config/themes/blue-white-tight/var.less +677 -677
- package/config/themes/danqing/danqing.css +576 -575
- package/config/themes/danqing/danqing.css.map +1 -1
- package/config/themes/danqing/danqing.less +668 -668
- package/config/themes/danqing/danqing.wxss +572 -572
- package/config/themes/danqing/var.less +679 -679
- package/config/themes/deep/deep.css +575 -575
- package/config/themes/deep/deep.less +669 -669
- package/config/themes/deep/var.less +677 -677
- package/config/themes/default/default.css +575 -575
- package/config/themes/default/default.less +671 -671
- package/config/themes/default/var.less +677 -677
- package/config/themes/eap/eap.css +575 -575
- package/config/themes/eap/eap.less +671 -671
- package/config/themes/eap/var.less +677 -677
- package/config/themes/gold/gold.css +575 -575
- package/config/themes/gold/gold.less +671 -671
- package/config/themes/gold/var.less +677 -677
- package/config/themes/index.js +28 -28
- package/config/themes/lime/lime.css +575 -575
- package/config/themes/lime/lime.less +671 -671
- package/config/themes/lime/var.less +678 -678
- package/config/themes/orange/orange.css +575 -575
- package/config/themes/orange/orange.less +671 -671
- package/config/themes/orange/var.less +678 -678
- package/config/themes/red/red.css +575 -575
- package/config/themes/red/red.less +671 -671
- package/config/themes/red/var.less +677 -677
- package/config/themes/theme-atrovirens.js +558 -558
- package/config/themes/theme-blue.js +558 -558
- package/config/themes/theme-bw.js +558 -558
- package/config/themes/theme-bwt.js +559 -559
- package/config/themes/theme-danqing.js +558 -558
- package/config/themes/theme-deep.js +558 -558
- package/config/themes/theme-default.js +558 -558
- package/config/themes/theme-eap.js +558 -558
- package/config/themes/theme-gold.js +558 -558
- package/config/themes/theme-lime.js +558 -558
- package/config/themes/theme-orange.js +559 -559
- package/config/themes/theme-red.js +558 -558
- package/config/themes/theme-white.js +557 -557
- package/config/themes/white/var.less +675 -675
- package/config/themes/white/white.css +575 -575
- package/config/themes/white/white.less +668 -668
- package/directives/index.js +23 -23
- package/directives/module/draggable.js +56 -56
- package/directives/module/permission.js +49 -49
- package/directives/module/print.js +1 -1
- package/directives/module/vue-print-nb/README.md +63 -63
- package/directives/module/vue-print-nb/print.js +94 -94
- package/directives/module/vue-print-nb/printarea.js +532 -532
- package/index.js +10 -10
- package/nstyles/common.less +197 -197
- package/nstyles/components/404.less +46 -46
- package/nstyles/components/button.less +34 -34
- package/nstyles/components/date-picker.less +37 -37
- package/nstyles/components/drawer.less +20 -20
- package/nstyles/components/dropdown.less +18 -18
- package/nstyles/components/excel-flow.less +72 -72
- package/nstyles/components/form.less +313 -303
- package/nstyles/components/index.less +23 -23
- package/nstyles/components/layout/collect.less +10 -10
- package/nstyles/components/layout/detail-view.less +107 -107
- package/nstyles/components/layout/full-screen.less +7 -7
- package/nstyles/components/layout/index.less +7 -7
- package/nstyles/components/layout/other-menu.less +142 -142
- package/nstyles/components/layout/page-view.less +101 -101
- package/nstyles/components/layout/sider-trigger.less +41 -41
- package/nstyles/components/layout/tags-nav.less +113 -113
- package/nstyles/components/modal.less +85 -85
- package/nstyles/components/n-button.less +131 -131
- package/nstyles/components/n-image-preview.less +131 -131
- package/nstyles/components/n-model/index.less +19 -19
- package/nstyles/components/n-model/report-index.less +43 -43
- package/nstyles/components/n-panel.less +40 -40
- package/nstyles/components/n-picker.less +37 -37
- package/nstyles/components/n-sign.less +17 -17
- package/nstyles/components/n-tooltip.less +10 -10
- package/nstyles/components/panel.less +31 -31
- package/nstyles/components/select.less +3 -3
- package/nstyles/components/sign.less +27 -27
- package/nstyles/components/table.less +315 -315
- package/nstyles/components/tree.less +158 -158
- package/nstyles/components/upload.less +164 -164
- package/nstyles/index.less +5 -5
- package/nstyles/reset.less +65 -65
- package/nstyles/third/ag.less +174 -174
- package/nstyles/third/index.less +11 -11
- package/nstyles/third/view-design.less +366 -366
- package/nstyles/variables/base.less +143 -143
- package/nstyles/variables/index.less +4 -4
- package/nstyles/variables/theme/default/button.less +7 -7
- package/nstyles/variables/theme/default/common.less +57 -57
- package/nstyles/variables/theme/default/index.less +7 -7
- package/nstyles/variables/theme/default/layout.less +40 -40
- package/nstyles/variables/theme/default/table.less +37 -37
- package/nstyles/variables/theme/default/tag.less +3 -3
- package/nstyles/variables/theme/default/upload.less +3 -3
- package/nstyles/variables/theme/index.less +13 -13
- package/nstyles/variables/theme/small/button.less +7 -7
- package/nstyles/variables/theme/small/common.less +39 -39
- package/nstyles/variables/theme/small/index.less +5 -5
- package/nstyles/variables/theme/small/layout.less +21 -21
- package/nstyles/variables/theme/small/table.less +17 -17
- package/nstyles/variables/theme/small/tag.less +3 -3
- package/package.json +1 -1
- package/plugin/index.js +12 -12
- package/plugin/module/date-format.js +30 -30
- package/plugin/module/loading.js +26 -26
- package/plugin/module/warn-handler.js +11 -11
- package/styles/variables.less +21 -21
- package/utils/ajax/cacheconf.js +19 -19
- package/utils/ajax/content-type.js +30 -30
- package/utils/ajax/index.js +12 -12
- package/utils/ajax/interceptors.js +97 -97
- package/utils/assist.js +147 -147
- package/utils/base64.js +126 -126
- package/utils/blob.js +47 -47
- package/utils/bus.js +3 -3
- package/utils/crypto/index.js +48 -48
- package/utils/crypto/md5.js +152 -152
- package/utils/crypto/sm3.js +235 -235
- package/utils/date.js +381 -381
- package/utils/dict/built-in-dict.js +20 -20
- package/utils/dict/index.js +167 -167
- package/utils/dom.js +38 -38
- package/utils/event.js +72 -72
- package/utils/excel.js +655 -655
- package/utils/file.js +19 -19
- package/utils/form/validate.js +29 -29
- package/utils/half-year.js +68 -68
- package/utils/index.js +41 -41
- package/utils/json.js +29 -29
- package/utils/lodop.js +165 -165
- package/utils/menu/before-close.js +17 -17
- package/utils/menu/index.js +395 -395
- package/utils/mime_type.js +67 -67
- package/utils/modelerUtil.js +227 -227
- package/utils/n/api.js +22 -22
- package/utils/n/date.js +57 -57
- package/utils/n/index.js +9 -9
- package/utils/n/is-type.js +176 -176
- package/utils/n/number.js +144 -144
- package/utils/n/permission-cache.js +11 -11
- package/utils/n/reuqest/axiosN.js +17 -17
- package/utils/n/reuqest/content-type.js +19 -19
- package/utils/n/reuqest/interceptors.js +95 -95
- package/utils/n/reuqest/url-params.js +12 -12
- package/utils/n/storage.js +51 -51
- package/utils/n/token.js +51 -51
- package/utils/n/user-cache.js +11 -11
- package/utils/n/user.js +34 -34
- package/utils/n/uuid.js +16 -16
- package/utils/n-generator-routers.js +208 -208
- package/utils/n-router.js +205 -205
- package/utils/n-theme.js +30 -30
- package/utils/number.js +180 -180
- package/utils/oss.js +57 -57
- package/utils/platform.js +1334 -1334
- package/utils/quarter.js +58 -58
- package/utils/storage.js +198 -198
- package/utils/theme.js +138 -138
- package/utils/transform.js +179 -0
- package/utils/type.js +102 -102
- package/utils/util.js +795 -795
- package/utils/validator.js +181 -181
- package/utils/vxetable/index.js +25 -25
- package/utils/zoomScroll.js +9 -9
package/utils/n/date.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import dayjs from 'dayjs'
|
|
2
|
-
|
|
3
|
-
export function str2Date(value) {
|
|
4
|
-
if (value) {
|
|
5
|
-
return dayjs(value, ['YYYYMMDDHHmmss', 'YYYYMMDDHHmm', 'YYYYMMDD', 'YYYYMM', 'YYYY']).toDate()
|
|
6
|
-
} else {
|
|
7
|
-
return null
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function formatDate(value) {
|
|
12
|
-
if (value && /^[0-9]+$/.test(value)) {
|
|
13
|
-
switch (value.length) {
|
|
14
|
-
case 14: {
|
|
15
|
-
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm:ss')
|
|
16
|
-
}
|
|
17
|
-
case 12: {
|
|
18
|
-
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm')
|
|
19
|
-
}
|
|
20
|
-
case 8: {
|
|
21
|
-
return dayjs(value, ['YYYYMMDD']).format('YYYY-MM-DD')
|
|
22
|
-
}
|
|
23
|
-
case 6: {
|
|
24
|
-
return dayjs(value, ['YYYYMM']).format('YYYY-MM')
|
|
25
|
-
}
|
|
26
|
-
case 4: {
|
|
27
|
-
return value.substring(0, 2) + '-' + value.substring(2, 2)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
return value || '-'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function formatDateChinese(value) {
|
|
36
|
-
if (value && /^[0-9]+$/.test(value)) {
|
|
37
|
-
switch (value.length) {
|
|
38
|
-
case 14: {
|
|
39
|
-
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm:ss')
|
|
40
|
-
}
|
|
41
|
-
case 12: {
|
|
42
|
-
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm')
|
|
43
|
-
}
|
|
44
|
-
case 8: {
|
|
45
|
-
return dayjs(value, ['YYYYMMDD']).format('YYYY年MM月DD日')
|
|
46
|
-
}
|
|
47
|
-
case 6: {
|
|
48
|
-
return dayjs(value, ['YYYYMM']).format('YYYY年MM月')
|
|
49
|
-
}
|
|
50
|
-
case 4: {
|
|
51
|
-
return value.substring(0, 2) + '年' + value.substring(2, 2) + '月'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
return value || '-'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import dayjs from 'dayjs'
|
|
2
|
+
|
|
3
|
+
export function str2Date(value) {
|
|
4
|
+
if (value) {
|
|
5
|
+
return dayjs(value, ['YYYYMMDDHHmmss', 'YYYYMMDDHHmm', 'YYYYMMDD', 'YYYYMM', 'YYYY']).toDate()
|
|
6
|
+
} else {
|
|
7
|
+
return null
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function formatDate(value) {
|
|
12
|
+
if (value && /^[0-9]+$/.test(value)) {
|
|
13
|
+
switch (value.length) {
|
|
14
|
+
case 14: {
|
|
15
|
+
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm:ss')
|
|
16
|
+
}
|
|
17
|
+
case 12: {
|
|
18
|
+
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm')
|
|
19
|
+
}
|
|
20
|
+
case 8: {
|
|
21
|
+
return dayjs(value, ['YYYYMMDD']).format('YYYY-MM-DD')
|
|
22
|
+
}
|
|
23
|
+
case 6: {
|
|
24
|
+
return dayjs(value, ['YYYYMM']).format('YYYY-MM')
|
|
25
|
+
}
|
|
26
|
+
case 4: {
|
|
27
|
+
return value.substring(0, 2) + '-' + value.substring(2, 2)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
return value || '-'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function formatDateChinese(value) {
|
|
36
|
+
if (value && /^[0-9]+$/.test(value)) {
|
|
37
|
+
switch (value.length) {
|
|
38
|
+
case 14: {
|
|
39
|
+
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm:ss')
|
|
40
|
+
}
|
|
41
|
+
case 12: {
|
|
42
|
+
return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm')
|
|
43
|
+
}
|
|
44
|
+
case 8: {
|
|
45
|
+
return dayjs(value, ['YYYYMMDD']).format('YYYY年MM月DD日')
|
|
46
|
+
}
|
|
47
|
+
case 6: {
|
|
48
|
+
return dayjs(value, ['YYYYMM']).format('YYYY年MM月')
|
|
49
|
+
}
|
|
50
|
+
case 4: {
|
|
51
|
+
return value.substring(0, 2) + '年' + value.substring(2, 2) + '月'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
return value || '-'
|
|
56
|
+
}
|
|
57
|
+
}
|
package/utils/n/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './date'
|
|
2
|
-
export * from './is-type'
|
|
3
|
-
export * from './number'
|
|
4
|
-
export * from './permission-cache'
|
|
5
|
-
export * from './storage'
|
|
6
|
-
export * from './token'
|
|
7
|
-
export * from './user-cache'
|
|
8
|
-
export * from './user'
|
|
9
|
-
export * from './uuid'
|
|
1
|
+
export * from './date'
|
|
2
|
+
export * from './is-type'
|
|
3
|
+
export * from './number'
|
|
4
|
+
export * from './permission-cache'
|
|
5
|
+
export * from './storage'
|
|
6
|
+
export * from './token'
|
|
7
|
+
export * from './user-cache'
|
|
8
|
+
export * from './user'
|
|
9
|
+
export * from './uuid'
|
|
10
10
|
export * from './reuqest/axiosN'
|
package/utils/n/is-type.js
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
const toString = {}.toString;
|
|
2
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3
|
-
const PRECISION = 0.00001; // numbers less than this is considered as 0
|
|
4
|
-
const objectProto = Object.prototype;
|
|
5
|
-
|
|
6
|
-
export function isNull(value) {
|
|
7
|
-
return value === null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isUndefined(value) {
|
|
11
|
-
return value === undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function isNil(value) {
|
|
15
|
-
return isNull(value) || isUndefined(value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getType(value) {
|
|
19
|
-
return toString
|
|
20
|
-
.call(value)
|
|
21
|
-
.replace(/^\[object /, '')
|
|
22
|
-
.replace(/]$/, '');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function isType(value, type) {
|
|
26
|
-
return toString.call(value) === `[object ${type}]`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function isPrototype(value) {
|
|
30
|
-
const Ctor = value && value.constructor;
|
|
31
|
-
const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
|
|
32
|
-
return value === proto;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isBoolean(value) {
|
|
36
|
-
return isType(value, 'Boolean');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function isNumber(value) {
|
|
40
|
-
return isType(value, 'Number');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function isString(str) {
|
|
44
|
-
return isType(str, 'String');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function isArray(value) {
|
|
48
|
-
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function isArrayLike(value) {
|
|
52
|
-
return value !== null && typeof value !== 'function' && Number.isFinite(value.length);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function isObject(value) {
|
|
56
|
-
const type = typeof value;
|
|
57
|
-
return (value !== null && type === 'object') || type === 'function';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function isObjectLike(value) {
|
|
61
|
-
return typeof value === 'object' && value !== null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function isPlainObject(value) {
|
|
65
|
-
if (!isObjectLike(value) || !isType(value, 'Object')) return false;
|
|
66
|
-
if (Object.getPrototypeOf(value) === null) return true;
|
|
67
|
-
let proto = value;
|
|
68
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
69
|
-
proto = Object.getPrototypeOf(proto);
|
|
70
|
-
}
|
|
71
|
-
return Object.getPrototypeOf(value) === proto;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function isFunction(value) {
|
|
75
|
-
return isType(value, 'Function');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function isPromise(value) {
|
|
79
|
-
return value && typeof value.then === 'function';
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function isDate(value) {
|
|
83
|
-
return isType(value, 'Date');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function isArguments(value) {
|
|
87
|
-
return isType(value, 'Arguments');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function isRegExp(str) {
|
|
91
|
-
return isType(str, 'RegExp');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function isError(value) {
|
|
95
|
-
return isType(value, 'Error');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function isElement(o) {
|
|
99
|
-
return o instanceof Element || o instanceof HTMLDocument;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function isEmpty(value) {
|
|
103
|
-
if (isNil(value)) return true;
|
|
104
|
-
if (isArrayLike(value)) return !value.length;
|
|
105
|
-
const type = getType(value);
|
|
106
|
-
if (['Map', 'Set'].includes(type)) return !value.size;
|
|
107
|
-
if (isPrototype(value)) return !Object.keys(value).length;
|
|
108
|
-
for (const key in value) {
|
|
109
|
-
if (hasOwnProperty.call(value, key)) return false;
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function isEqual(value, other) {
|
|
115
|
-
if (value === other) return true;
|
|
116
|
-
if (!value || !other) return false;
|
|
117
|
-
if (isString(value) || isString(other)) return false;
|
|
118
|
-
if (isArrayLike(value) || isArrayLike(other)) {
|
|
119
|
-
if (value.length !== other.length) return false;
|
|
120
|
-
let rst = true;
|
|
121
|
-
for (let i = 0; i < value.length; i++) {
|
|
122
|
-
rst = isEqual(value[i], other[i]);
|
|
123
|
-
if (!rst) break;
|
|
124
|
-
}
|
|
125
|
-
return rst;
|
|
126
|
-
}
|
|
127
|
-
if (isObjectLike(value) || isObjectLike(other)) {
|
|
128
|
-
const valueKeys = Object.keys(value);
|
|
129
|
-
const otherKeys = Object.keys(other);
|
|
130
|
-
if (valueKeys.length !== otherKeys.length) return false;
|
|
131
|
-
let rst = true;
|
|
132
|
-
for (let i = 0; i < valueKeys.length; i++) {
|
|
133
|
-
rst = isEqual(value[valueKeys[i]], other[valueKeys[i]]);
|
|
134
|
-
if (!rst) break;
|
|
135
|
-
}
|
|
136
|
-
return rst;
|
|
137
|
-
}
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function isEven(num) {
|
|
142
|
-
return isNumber(num) && num % 2 === 0;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function isOdd(num) {
|
|
146
|
-
return isNumber(num) && num % 2 !== 0;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function isFinite(value) {
|
|
150
|
-
return isNumber(value) && Number.isFinite(value);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function isInteger(num) {
|
|
154
|
-
return Number.isInteger ? Number.isInteger(num) : isNumber(num) && num % 1 === 0;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function isDecimal(num) {
|
|
158
|
-
return isNumber(num) && num % 1 !== 0;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function isNegative(num) {
|
|
162
|
-
return isNumber(num) && num < 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function isPositive(num) {
|
|
166
|
-
return isNumber(num) && num > 0;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function isNumberEqual(a, b, precision = PRECISION) {
|
|
170
|
-
return Math.abs(a - b) < precision;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function isEqualWith(value, other, fn) {
|
|
174
|
-
if (!isFunction(fn)) return isEqual(value, other);
|
|
175
|
-
return fn(value, other);
|
|
176
|
-
}
|
|
1
|
+
const toString = {}.toString;
|
|
2
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3
|
+
const PRECISION = 0.00001; // numbers less than this is considered as 0
|
|
4
|
+
const objectProto = Object.prototype;
|
|
5
|
+
|
|
6
|
+
export function isNull(value) {
|
|
7
|
+
return value === null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isUndefined(value) {
|
|
11
|
+
return value === undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isNil(value) {
|
|
15
|
+
return isNull(value) || isUndefined(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getType(value) {
|
|
19
|
+
return toString
|
|
20
|
+
.call(value)
|
|
21
|
+
.replace(/^\[object /, '')
|
|
22
|
+
.replace(/]$/, '');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isType(value, type) {
|
|
26
|
+
return toString.call(value) === `[object ${type}]`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isPrototype(value) {
|
|
30
|
+
const Ctor = value && value.constructor;
|
|
31
|
+
const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
|
|
32
|
+
return value === proto;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isBoolean(value) {
|
|
36
|
+
return isType(value, 'Boolean');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isNumber(value) {
|
|
40
|
+
return isType(value, 'Number');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isString(str) {
|
|
44
|
+
return isType(str, 'String');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isArray(value) {
|
|
48
|
+
return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isArrayLike(value) {
|
|
52
|
+
return value !== null && typeof value !== 'function' && Number.isFinite(value.length);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isObject(value) {
|
|
56
|
+
const type = typeof value;
|
|
57
|
+
return (value !== null && type === 'object') || type === 'function';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function isObjectLike(value) {
|
|
61
|
+
return typeof value === 'object' && value !== null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function isPlainObject(value) {
|
|
65
|
+
if (!isObjectLike(value) || !isType(value, 'Object')) return false;
|
|
66
|
+
if (Object.getPrototypeOf(value) === null) return true;
|
|
67
|
+
let proto = value;
|
|
68
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
69
|
+
proto = Object.getPrototypeOf(proto);
|
|
70
|
+
}
|
|
71
|
+
return Object.getPrototypeOf(value) === proto;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isFunction(value) {
|
|
75
|
+
return isType(value, 'Function');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isPromise(value) {
|
|
79
|
+
return value && typeof value.then === 'function';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isDate(value) {
|
|
83
|
+
return isType(value, 'Date');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function isArguments(value) {
|
|
87
|
+
return isType(value, 'Arguments');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function isRegExp(str) {
|
|
91
|
+
return isType(str, 'RegExp');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isError(value) {
|
|
95
|
+
return isType(value, 'Error');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function isElement(o) {
|
|
99
|
+
return o instanceof Element || o instanceof HTMLDocument;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isEmpty(value) {
|
|
103
|
+
if (isNil(value)) return true;
|
|
104
|
+
if (isArrayLike(value)) return !value.length;
|
|
105
|
+
const type = getType(value);
|
|
106
|
+
if (['Map', 'Set'].includes(type)) return !value.size;
|
|
107
|
+
if (isPrototype(value)) return !Object.keys(value).length;
|
|
108
|
+
for (const key in value) {
|
|
109
|
+
if (hasOwnProperty.call(value, key)) return false;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function isEqual(value, other) {
|
|
115
|
+
if (value === other) return true;
|
|
116
|
+
if (!value || !other) return false;
|
|
117
|
+
if (isString(value) || isString(other)) return false;
|
|
118
|
+
if (isArrayLike(value) || isArrayLike(other)) {
|
|
119
|
+
if (value.length !== other.length) return false;
|
|
120
|
+
let rst = true;
|
|
121
|
+
for (let i = 0; i < value.length; i++) {
|
|
122
|
+
rst = isEqual(value[i], other[i]);
|
|
123
|
+
if (!rst) break;
|
|
124
|
+
}
|
|
125
|
+
return rst;
|
|
126
|
+
}
|
|
127
|
+
if (isObjectLike(value) || isObjectLike(other)) {
|
|
128
|
+
const valueKeys = Object.keys(value);
|
|
129
|
+
const otherKeys = Object.keys(other);
|
|
130
|
+
if (valueKeys.length !== otherKeys.length) return false;
|
|
131
|
+
let rst = true;
|
|
132
|
+
for (let i = 0; i < valueKeys.length; i++) {
|
|
133
|
+
rst = isEqual(value[valueKeys[i]], other[valueKeys[i]]);
|
|
134
|
+
if (!rst) break;
|
|
135
|
+
}
|
|
136
|
+
return rst;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function isEven(num) {
|
|
142
|
+
return isNumber(num) && num % 2 === 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function isOdd(num) {
|
|
146
|
+
return isNumber(num) && num % 2 !== 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function isFinite(value) {
|
|
150
|
+
return isNumber(value) && Number.isFinite(value);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function isInteger(num) {
|
|
154
|
+
return Number.isInteger ? Number.isInteger(num) : isNumber(num) && num % 1 === 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function isDecimal(num) {
|
|
158
|
+
return isNumber(num) && num % 1 !== 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function isNegative(num) {
|
|
162
|
+
return isNumber(num) && num < 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function isPositive(num) {
|
|
166
|
+
return isNumber(num) && num > 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function isNumberEqual(a, b, precision = PRECISION) {
|
|
170
|
+
return Math.abs(a - b) < precision;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function isEqualWith(value, other, fn) {
|
|
174
|
+
if (!isFunction(fn)) return isEqual(value, other);
|
|
175
|
+
return fn(value, other);
|
|
176
|
+
}
|