ut2 1.5.3 → 1.5.4

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/lib/isEqual.js CHANGED
@@ -1,181 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var allKeys = require('./allKeys.js');
4
- var eq = require('./eq.js');
5
- var getTagWithBugfix = require('./internals/getTagWithBugfix.js');
6
- var native = require('./internals/native.js');
7
- var isBuffer = require('./isBuffer.js');
8
- var isFunction = require('./isFunction.js');
9
- var isNil = require('./isNil.js');
10
- var isObjectLike = require('./isObjectLike.js');
11
- var isTypedArray = require('./isTypedArray.js');
12
- var orderBy = require('./orderBy.js');
3
+ var isEqualDeep = require('./internals/isEqualDeep.js');
13
4
 
14
- var symbolValueOf = native.symbolProto ? native.symbolProto.valueOf : undefined;
15
- function mapToArray(map) {
16
- var result = [];
17
- map.forEach(function (value, key) {
18
- result.push([key, value]);
19
- });
20
- return orderBy(result, [0, 1]);
21
- }
22
- function setToArray(set) {
23
- var result = [];
24
- set.forEach(function (value) {
25
- result.push(value);
26
- });
27
- return orderBy(result);
28
- }
29
- function argToArray(arg) {
30
- return native.arrayProtoSlice.call(arg);
31
- }
32
- function toBufferView(bufferSource) {
33
- return new Uint8Array(bufferSource.buffer || bufferSource, bufferSource.byteOffset || 0, bufferSource.byteLength);
34
- }
35
- function isDomNode(obj) {
36
- return isObjectLike(obj) && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string' && typeof obj.isEqualNode === 'function';
37
- }
38
- function isEqualDeep(value, other, customizer, strictCheck, valueStack, otherStack) {
39
- if (eq(value, other, strictCheck)) {
40
- return true;
41
- }
42
- var valType = typeof value;
43
- var othType = typeof other;
44
- if (strictCheck && valType !== othType) {
45
- return false;
46
- }
47
- if (isNil(value) || isNil(other) || (valType !== 'object' && othType !== 'object')) {
48
- return false;
49
- }
50
- var tag = getTagWithBugfix(value);
51
- if (tag !== getTagWithBugfix(other)) {
52
- return false;
53
- }
54
- var convert;
55
- switch (tag) {
56
- case native.numberTag:
57
- return eq(+value, +other, strictCheck);
58
- case native.booleanTag:
59
- case native.dateTag:
60
- return strictCheck ? +value === +other : eq(+value, +other);
61
- case native.stringTag:
62
- case native.regExpTag:
63
- return '' + value === '' + other;
64
- case native.symbolTag:
65
- return symbolValueOf ? symbolValueOf.call(value) === symbolValueOf.call(other) : false;
66
- case native.errorTag:
67
- return value.name === other.name && value.message === other.message;
68
- case native.dataViewTag:
69
- case native.arrayBufferTag:
70
- if (value.byteLength !== other.byteLength || (value.byteOffset && value.byteOffset !== other.byteOffset)) {
71
- return false;
72
- }
73
- convert = toBufferView;
74
- break;
75
- case native.mapTag:
76
- convert = mapToArray;
77
- break;
78
- case native.setTag:
79
- convert = setToArray;
80
- break;
81
- case native.argumentsTag:
82
- convert = argToArray;
83
- break;
84
- }
85
- if (convert) {
86
- return isEqualDeep(convert(value), convert(other), customizer, strictCheck, valueStack, otherStack);
87
- }
88
- if (isDomNode(value) && isDomNode(other)) {
89
- return value.isEqualNode(other);
90
- }
91
- var areArrays = tag === native.arrayTag;
92
- if (!areArrays && isTypedArray(value)) {
93
- if (value.byteLength !== other.byteLength) {
94
- return false;
95
- }
96
- if (value.buffer === other.buffer && value.byteOffset === other.byteOffset) {
97
- return true;
98
- }
99
- areArrays = true;
100
- }
101
- if (isBuffer(value)) {
102
- if (!isBuffer(other)) {
103
- return false;
104
- }
105
- areArrays = true;
106
- }
107
- valueStack = valueStack || [];
108
- otherStack = otherStack || [];
109
- var length = valueStack.length;
110
- while (length--) {
111
- if (valueStack[length] === value) {
112
- return otherStack[length] === other;
113
- }
114
- }
115
- valueStack.push(value);
116
- otherStack.push(other);
117
- var result = true;
118
- var hasCustomizer = typeof customizer === 'function';
119
- if (areArrays) {
120
- length = value.length;
121
- if (length !== other.length) {
122
- return false;
123
- }
124
- while (length--) {
125
- if (hasCustomizer) {
126
- var compared = customizer(value[length], other[length], length, value, other, valueStack, otherStack);
127
- if (compared !== undefined) {
128
- if (!compared) {
129
- return false;
130
- }
131
- continue;
132
- }
133
- }
134
- if (!isEqualDeep(value[length], other[length], customizer, strictCheck, valueStack, otherStack)) {
135
- return false;
136
- }
137
- }
138
- }
139
- else if (tag === native.objectTag) {
140
- var keys = allKeys(value);
141
- length = keys.length;
142
- if (allKeys(other).length !== length) {
143
- return false;
144
- }
145
- var skipCtor = false;
146
- while (length--) {
147
- var key = keys[length];
148
- if (hasCustomizer) {
149
- var compared = customizer(value[key], other[key], key, value, other, valueStack, otherStack);
150
- if (compared !== undefined) {
151
- if (!compared) {
152
- return false;
153
- }
154
- continue;
155
- }
156
- }
157
- if (!(native.objectProtoHasOwnProperty.call(other, key) && isEqualDeep(value[key], other[key], customizer, strictCheck, valueStack, otherStack))) {
158
- return false;
159
- }
160
- if (!skipCtor && key === 'constructor') {
161
- skipCtor = true;
162
- }
163
- }
164
- if (!skipCtor) {
165
- var valCtor = value.constructor;
166
- var othCtor = other.constructor;
167
- if (valCtor !== othCtor && !(isFunction(valCtor) && valCtor instanceof valCtor && isFunction(othCtor) && othCtor instanceof othCtor) && 'constructor' in value && 'constructor' in other) {
168
- return false;
169
- }
170
- }
171
- }
172
- else {
173
- result = false;
174
- }
175
- valueStack.pop();
176
- otherStack.pop();
177
- return result;
178
- }
179
5
  function isEqual(value, other, customizer, strictCheck) {
180
6
  if (strictCheck === void 0) { strictCheck = false; }
181
7
  if (typeof customizer === 'function') {
package/lib/isMatch.js CHANGED
@@ -3,13 +3,12 @@
3
3
  var allKeys = require('./allKeys.js');
4
4
  var getTag = require('./internals/getTag.js');
5
5
  var native = require('./internals/native.js');
6
- var isEqual = require('./isEqual.js');
6
+ var isEqualDeep = require('./internals/isEqualDeep.js');
7
7
 
8
8
  function isDeepComparable(object, source) {
9
9
  return getTag(object) === native.objectTag && getTag(source) === native.objectTag;
10
10
  }
11
- function baseIsMatch(object, source, customizer, strictCheck, objStack, srcStack, executedCustomizer) {
12
- if (executedCustomizer === void 0) { executedCustomizer = false; }
11
+ function baseIsMatch(object, source, customizer, strictCheck, objStack, srcStack) {
13
12
  var hasCustomizer = typeof customizer === 'function';
14
13
  if (isDeepComparable(object, source)) {
15
14
  objStack = objStack || [];
@@ -38,7 +37,7 @@ function baseIsMatch(object, source, customizer, strictCheck, objStack, srcStack
38
37
  continue;
39
38
  }
40
39
  }
41
- if (!baseIsMatch(object[key], source[key], customizer, strictCheck, objStack, srcStack, true)) {
40
+ if (!baseIsMatch(object[key], source[key], customizer, strictCheck, objStack, srcStack)) {
42
41
  return false;
43
42
  }
44
43
  }
@@ -46,18 +45,17 @@ function baseIsMatch(object, source, customizer, strictCheck, objStack, srcStack
46
45
  srcStack.pop();
47
46
  return true;
48
47
  }
49
- var result = isEqual(object, source, function (objValue, srcValue, k, obj, src) {
50
- if (!executedCustomizer && hasCustomizer) {
48
+ var result = isEqualDeep(object, source, function (objValue, srcValue, k, obj, src) {
49
+ if (hasCustomizer) {
51
50
  var compared = customizer(objValue, srcValue, k, obj, src, objStack, srcStack);
52
51
  if (compared !== undefined) {
53
52
  return compared;
54
53
  }
55
54
  }
56
- executedCustomizer = false;
57
55
  if (isDeepComparable(objValue, srcValue)) {
58
56
  return baseIsMatch(objValue, srcValue, customizer, strictCheck, objStack, srcStack);
59
57
  }
60
- }, strictCheck);
58
+ }, strictCheck, objStack, srcStack);
61
59
  return result;
62
60
  }
63
61
  function isMatch(object, source, customizer, strictCheck) {
@@ -68,7 +66,7 @@ function isMatch(object, source, customizer, strictCheck) {
68
66
  return !!compared;
69
67
  }
70
68
  }
71
- return baseIsMatch(object, source, customizer, strictCheck, undefined, undefined, true);
69
+ return baseIsMatch(object, source, customizer, strictCheck, undefined, undefined);
72
70
  }
73
71
 
74
72
  module.exports = isMatch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ut2",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "author": "caijf",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,26 @@
1
+ type Customizer = (objValue: any, othValue: any, key?: number | string | symbol, object?: any, other?: any, valueStack?: any[], otherStack?: any[]) => void | boolean;
2
+ /**
3
+ *
4
+ * 深度比较两个值是否相等。
5
+ *
6
+ * 支持比较 `boolean` `number` `string` `symbol` `array` `array buffer` `date` `error` `map` `object` `regexp` `set` `typed array` 类型。对象只比较自身的属性,不包括继承和不可枚举的属性。
7
+ *
8
+ * 如果 `strictCheck=true` , 以下值不相等:
9
+ *
10
+ * 1. `0` `-0`
11
+ * 2. `typeof` 不同类型,如 `1` `Object(1)`
12
+ * 3. 无效日期对象,如 `new Date('')` `new Date('abc')`
13
+ *
14
+ * @static
15
+ * @alias module:Language.isEqual
16
+ * @since 1.3.0
17
+ * @param {*} value 要比较的值。
18
+ * @param {*} other 另一个要比较的值。
19
+ * @param {Function} [customizer] 自定义比较。
20
+ * @param {boolean} [strictCheck=false] 严格比较,默认 `false` 。
21
+ * @param {*[]} [valueStack] 值的堆栈。
22
+ * @param {*[]} [otherStack] 另一个值的堆栈。
23
+ * @returns {boolean} 如果两个值相等,返回 `true` ,否则返回 `false` 。
24
+ */
25
+ declare function isEqualDeep(value: any, other: any, customizer?: Customizer, strictCheck?: boolean, valueStack?: any[], otherStack?: any[]): boolean;
26
+ export default isEqualDeep;
@@ -1,4 +1,4 @@
1
- type Customizer = (objValue: any, othValue: any, key?: number | string | symbol, object?: any, other?: any, valueStack?: any[], otherStack?: any[]) => void | boolean;
1
+ import isEqualDeep from './internals/isEqualDeep';
2
2
  /**
3
3
  * 深度比较两个值是否相等。
4
4
  *
@@ -40,5 +40,5 @@ type Customizer = (objValue: any, othValue: any, key?: number | string | symbol,
40
40
  * isEqual({foo: 'a'}, {foo: 'b'}, customizer); // true
41
41
  *
42
42
  */
43
- declare function isEqual(value: any, other: any, customizer?: Customizer, strictCheck?: boolean): boolean;
43
+ declare function isEqual(value: any, other: any, customizer?: Parameters<typeof isEqualDeep>[2], strictCheck?: boolean): boolean;
44
44
  export default isEqual;