ut2 1.5.5 → 1.6.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  一个现代 JavaScript 实用工具库。[点击查看在线文档]。
4
4
 
5
- [![npm][npm]][npm-url] [![Build and Deploy Docs](https://github.com/caijf/ut2/actions/workflows/ci.yml/badge.svg)](https://github.com/caijf/ut2/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/caijf/ut2/branch/main/graph/badge.svg?token=XKTS0H7085)](https://codecov.io/gh/caijf/ut2) [![Static Badge](https://img.shields.io/badge/benchmark-online-green)](https://codesandbox.io/s/github/caijf/ut2/tree/main/benchmark) ![npm](https://img.shields.io/npm/dt/ut2) ![GitHub](https://img.shields.io/github/license/caijf/ut2.svg)
5
+ [![npm][npm]][npm-url] [![Build and Deploy Docs](https://github.com/caijf/ut2/actions/workflows/ci.yml/badge.svg)](https://github.com/caijf/ut2/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/caijf/ut2/branch/main/graph/badge.svg?token=XKTS0H7085)](https://codecov.io/gh/caijf/ut2) [![Static Badge](https://img.shields.io/badge/benchmark-online-green)](https://s57jpy.csb.app/) ![npm](https://img.shields.io/npm/dt/ut2) ![GitHub](https://img.shields.io/github/license/caijf/ut2.svg)
6
6
 
7
7
  ## 比较
8
8
 
@@ -173,6 +173,7 @@ const debounced = debounce(() => {
173
173
  - lte - 小于等于。
174
174
  - noop - 空函数。
175
175
  - nthArg - 返回指定位置参数的函数。
176
+ - range - 创建升序或降序的数字数组。
176
177
  - sleep - 返回 `promise` 延迟。
177
178
  - times - 迭代执行次数。
178
179
  - toFinite - 转为有限数字。
package/dist/ut2.js CHANGED
@@ -413,7 +413,7 @@
413
413
  return value;
414
414
  }
415
415
  if (isArray(value)) {
416
- return "".concat(value.map(baseToString));
416
+ return '' + value.map(baseToString);
417
417
  }
418
418
  if (isSymbol(value)) {
419
419
  return symbolToString ? symbolToString.call(value) : '';
@@ -499,7 +499,7 @@
499
499
  return value == null || value !== value ? defaultValue : value;
500
500
  }
501
501
 
502
- var VERSION = "1.5.5";
502
+ var VERSION = "1.6.0";
503
503
  var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
504
504
  var FUNC_ERROR_TEXT = 'Expected a function';
505
505
  function toSource(func) {
@@ -1338,35 +1338,44 @@
1338
1338
  return getKeysIn(object);
1339
1339
  }
1340
1340
 
1341
- function baseMerge(object, source, customizer, storage) {
1342
- if (storage === void 0) { storage = new WeakMap(); }
1341
+ function baseMerge(object, source, customizer, stack) {
1342
+ if (stack === void 0) { stack = new WeakMap(); }
1343
1343
  var obj = Object(object);
1344
1344
  if (!isObject(source) || obj === source) {
1345
1345
  return obj;
1346
1346
  }
1347
1347
  var keys = allKeysIn(source);
1348
+ var hasCustomizer = typeof customizer === 'function';
1348
1349
  keys.forEach(function (key) {
1349
1350
  var srcValue = source[key];
1350
- var newValue = typeof customizer === 'function' ? customizer(obj[key], srcValue, key, obj, source) : undefined;
1351
- if (newValue === undefined) {
1352
- newValue = srcValue;
1353
- }
1354
- if (isObjectLike(newValue) && key in obj && !storage.has(newValue)) {
1355
- storage.set(newValue, true);
1356
- var objValue = obj[key];
1357
- var newObjValue = void 0;
1358
- if (isArray(newValue)) {
1359
- newObjValue = isArray(objValue) ? objValue : [];
1360
- }
1361
- else {
1362
- newObjValue = isObjectLike(objValue) ? objValue : {};
1363
- }
1364
- obj[key] = baseMerge(newObjValue, newValue, customizer, storage);
1351
+ var srcIsObj = isObject(srcValue);
1352
+ if (srcIsObj && stack.has(srcValue)) {
1353
+ obj[key] = srcValue;
1365
1354
  }
1366
1355
  else {
1367
- if (newValue !== undefined || (newValue === undefined && !(key in obj))) {
1356
+ var newValue = hasCustomizer ? customizer(obj[key], srcValue, key, obj, source) : undefined;
1357
+ if (newValue !== undefined) {
1368
1358
  obj[key] = newValue;
1369
1359
  }
1360
+ else {
1361
+ var objValue = obj[key];
1362
+ var newObjValue = void 0;
1363
+ if (srcIsObj) {
1364
+ stack.set(srcValue, true);
1365
+ if (isArray(srcValue)) {
1366
+ newObjValue = isArray(objValue) ? objValue : [];
1367
+ }
1368
+ else if (isPlainObject(srcValue)) {
1369
+ newObjValue = isObjectLike(objValue) ? objValue : {};
1370
+ }
1371
+ }
1372
+ if (newObjValue) {
1373
+ obj[key] = baseMerge(newObjValue, srcValue, customizer, stack);
1374
+ }
1375
+ else if (srcValue !== undefined || !(key in obj)) {
1376
+ obj[key] = srcValue;
1377
+ }
1378
+ }
1370
1379
  }
1371
1380
  });
1372
1381
  return obj;
@@ -1575,6 +1584,29 @@
1575
1584
  };
1576
1585
  }
1577
1586
 
1587
+ function range(start, end, step) {
1588
+ start = toFinite(start);
1589
+ if (isNil(end)) {
1590
+ end = start;
1591
+ start = 0;
1592
+ }
1593
+ else {
1594
+ end = toFinite(end);
1595
+ }
1596
+ step = toFinite(step);
1597
+ if (!step) {
1598
+ step = start < end ? 1 : -1;
1599
+ }
1600
+ var index = -1;
1601
+ var length = mathMax(mathCeil((end - start) / step), 0);
1602
+ var result = Array(length);
1603
+ while (length--) {
1604
+ result[++index] = start;
1605
+ start += step;
1606
+ }
1607
+ return result;
1608
+ }
1609
+
1578
1610
  function sleep(ms) {
1579
1611
  if (ms === void 0) { ms = 1000; }
1580
1612
  return new Promise(function (resolve) {
@@ -1714,6 +1746,7 @@
1714
1746
  exports.pickBy = pickBy;
1715
1747
  exports.random = random;
1716
1748
  exports.randomInt = randomInt;
1749
+ exports.range = range;
1717
1750
  exports.round = round;
1718
1751
  exports.shuffle = shuffle;
1719
1752
  exports.sleep = sleep;