@lowentry/utils 1.16.2 → 1.18.1
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/index.js +202 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/LeUtils.js +41 -0
- package/src/classes/LinkedList.js +145 -0
- package/src/classes/SerializableMap.js +17 -0
- package/src/index.js +2 -0
- package/tests/sort.test.js +33 -0
package/index.js
CHANGED
|
@@ -8,6 +8,12 @@ import _wrapAsyncGenerator from '@babel/runtime/helpers/wrapAsyncGenerator';
|
|
|
8
8
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
9
9
|
import FastDeepEqual from 'fast-deep-equal';
|
|
10
10
|
import CloneDeep from 'clone-deep';
|
|
11
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
12
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
13
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
14
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
15
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
16
|
+
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
11
17
|
|
|
12
18
|
var REGEX_ALL_NON_FLOAT_CHARACTERS = /[^0-9.\-]/g;
|
|
13
19
|
|
|
@@ -1406,6 +1412,40 @@ var LeUtils = {
|
|
|
1406
1412
|
}
|
|
1407
1413
|
return 0;
|
|
1408
1414
|
},
|
|
1415
|
+
/**
|
|
1416
|
+
* Compares two strings in a natural way, meaning that it will compare numbers in the strings as actual numbers.
|
|
1417
|
+
*
|
|
1418
|
+
* This will correctly sort numeric parts so that "file5.txt" comes before "file10.txt", as well as that "file/5/test.txt" comes before "file/10/test.txt".
|
|
1419
|
+
*
|
|
1420
|
+
* @param {string} a
|
|
1421
|
+
* @param {string} b
|
|
1422
|
+
* @returns {number}
|
|
1423
|
+
*/
|
|
1424
|
+
compareNaturalStrings: function compareNaturalStrings(a, b) {
|
|
1425
|
+
var _a$match, _b$match;
|
|
1426
|
+
var re = /(\d+|\D+)/g; // split into runs of digits or non-digits
|
|
1427
|
+
var aTokens = (_a$match = a.match(re)) !== null && _a$match !== void 0 ? _a$match : [];
|
|
1428
|
+
var bTokens = (_b$match = b.match(re)) !== null && _b$match !== void 0 ? _b$match : [];
|
|
1429
|
+
var len = Math.min(aTokens.length, bTokens.length);
|
|
1430
|
+
for (var i = 0; i < len; i++) {
|
|
1431
|
+
var x = aTokens[i];
|
|
1432
|
+
var y = bTokens[i];
|
|
1433
|
+
if (x === y) {
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// if both are numbers, compare as numbers
|
|
1438
|
+
var nx = parseInt(x, 10);
|
|
1439
|
+
var ny = parseInt(y, 10);
|
|
1440
|
+
if (!isNaN(nx) && !isNaN(ny)) {
|
|
1441
|
+
return nx - ny;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// otherwise compare lexically
|
|
1445
|
+
return x < y ? -1 : 1;
|
|
1446
|
+
}
|
|
1447
|
+
return aTokens.length - bTokens.length;
|
|
1448
|
+
},
|
|
1409
1449
|
/**
|
|
1410
1450
|
* Compares two strings generated by LeUtils.timestamp(). Primarily used for sorting.
|
|
1411
1451
|
*
|
|
@@ -3484,5 +3524,166 @@ var LeUtils = {
|
|
|
3484
3524
|
}()
|
|
3485
3525
|
};
|
|
3486
3526
|
|
|
3487
|
-
|
|
3527
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
3528
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3529
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
3530
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
3531
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
3532
|
+
var LinkedListNode = /*#__PURE__*/_createClass(
|
|
3533
|
+
/**
|
|
3534
|
+
* @param {*} value
|
|
3535
|
+
*/
|
|
3536
|
+
function LinkedListNode(value) {
|
|
3537
|
+
_classCallCheck(this, LinkedListNode);
|
|
3538
|
+
/** @type {*} */
|
|
3539
|
+
_defineProperty(this, "value", void 0);
|
|
3540
|
+
/** @type {LinkedListNode|null} */
|
|
3541
|
+
_defineProperty(this, "next", null);
|
|
3542
|
+
/** @type {LinkedListNode|null} */
|
|
3543
|
+
_defineProperty(this, "previous", null);
|
|
3544
|
+
this.value = value;
|
|
3545
|
+
});
|
|
3546
|
+
var _head = /*#__PURE__*/new WeakMap();
|
|
3547
|
+
var _tail = /*#__PURE__*/new WeakMap();
|
|
3548
|
+
var _size = /*#__PURE__*/new WeakMap();
|
|
3549
|
+
var LinkedList = /*#__PURE__*/function () {
|
|
3550
|
+
function LinkedList() {
|
|
3551
|
+
_classCallCheck(this, LinkedList);
|
|
3552
|
+
/** @type {LinkedListNode|null} */
|
|
3553
|
+
_classPrivateFieldInitSpec(this, _head, null);
|
|
3554
|
+
/** @type {LinkedListNode|null} */
|
|
3555
|
+
_classPrivateFieldInitSpec(this, _tail, null);
|
|
3556
|
+
/** @type {number} */
|
|
3557
|
+
_classPrivateFieldInitSpec(this, _size, 0);
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
/**
|
|
3561
|
+
* Returns the number of elements in the list.
|
|
3562
|
+
*
|
|
3563
|
+
* @returns {number}
|
|
3564
|
+
*/
|
|
3565
|
+
return _createClass(LinkedList, [{
|
|
3566
|
+
key: "size",
|
|
3567
|
+
get: function get() {
|
|
3568
|
+
return _classPrivateFieldGet(_size, this);
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
/**
|
|
3572
|
+
* Adds a new value to the beginning of the list.
|
|
3573
|
+
*
|
|
3574
|
+
* @param {*} value
|
|
3575
|
+
*/
|
|
3576
|
+
}, {
|
|
3577
|
+
key: "unshift",
|
|
3578
|
+
value: function unshift(value) {
|
|
3579
|
+
var _this$size;
|
|
3580
|
+
var newNode = new LinkedListNode(value);
|
|
3581
|
+
if (_classPrivateFieldGet(_head, this) === null) {
|
|
3582
|
+
_classPrivateFieldSet(_head, this, newNode);
|
|
3583
|
+
_classPrivateFieldSet(_tail, this, newNode);
|
|
3584
|
+
} else {
|
|
3585
|
+
newNode.next = _classPrivateFieldGet(_head, this);
|
|
3586
|
+
_classPrivateFieldGet(_head, this).previous = newNode;
|
|
3587
|
+
_classPrivateFieldSet(_head, this, newNode);
|
|
3588
|
+
}
|
|
3589
|
+
_classPrivateFieldSet(_size, this, (_this$size = _classPrivateFieldGet(_size, this), _this$size++, _this$size));
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
/**
|
|
3593
|
+
* Adds a new value to the end of the list.
|
|
3594
|
+
*
|
|
3595
|
+
* @param {*} value
|
|
3596
|
+
*/
|
|
3597
|
+
}, {
|
|
3598
|
+
key: "push",
|
|
3599
|
+
value: function push(value) {
|
|
3600
|
+
var _this$size3;
|
|
3601
|
+
var newNode = new LinkedListNode(value);
|
|
3602
|
+
if (_classPrivateFieldGet(_tail, this) === null) {
|
|
3603
|
+
_classPrivateFieldSet(_head, this, newNode);
|
|
3604
|
+
_classPrivateFieldSet(_tail, this, newNode);
|
|
3605
|
+
} else {
|
|
3606
|
+
newNode.previous = _classPrivateFieldGet(_tail, this);
|
|
3607
|
+
_classPrivateFieldGet(_tail, this).next = newNode;
|
|
3608
|
+
_classPrivateFieldSet(_tail, this, newNode);
|
|
3609
|
+
}
|
|
3610
|
+
_classPrivateFieldSet(_size, this, (_this$size3 = _classPrivateFieldGet(_size, this), _this$size3++, _this$size3));
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
/**
|
|
3614
|
+
* Removes the first value from the list and returns it.
|
|
3615
|
+
*
|
|
3616
|
+
* @returns {*|undefined}
|
|
3617
|
+
*/
|
|
3618
|
+
}, {
|
|
3619
|
+
key: "shift",
|
|
3620
|
+
value: function shift() {
|
|
3621
|
+
var _this$size5;
|
|
3622
|
+
if (_classPrivateFieldGet(_head, this) === null) {
|
|
3623
|
+
return undefined;
|
|
3624
|
+
}
|
|
3625
|
+
var value = _classPrivateFieldGet(_head, this).value;
|
|
3626
|
+
_classPrivateFieldSet(_head, this, _classPrivateFieldGet(_head, this).next);
|
|
3627
|
+
if (_classPrivateFieldGet(_head, this) !== null) {
|
|
3628
|
+
_classPrivateFieldGet(_head, this).previous = null;
|
|
3629
|
+
} else {
|
|
3630
|
+
_classPrivateFieldSet(_tail, this, null);
|
|
3631
|
+
}
|
|
3632
|
+
_classPrivateFieldSet(_size, this, (_this$size5 = _classPrivateFieldGet(_size, this), _this$size5--, _this$size5));
|
|
3633
|
+
return value;
|
|
3634
|
+
}
|
|
3635
|
+
|
|
3636
|
+
/**
|
|
3637
|
+
* Removes the last value from the list and returns it.
|
|
3638
|
+
*
|
|
3639
|
+
* @returns {*|undefined}
|
|
3640
|
+
*/
|
|
3641
|
+
}, {
|
|
3642
|
+
key: "pop",
|
|
3643
|
+
value: function pop() {
|
|
3644
|
+
var _this$size7;
|
|
3645
|
+
if (_classPrivateFieldGet(_tail, this) === null) {
|
|
3646
|
+
return undefined;
|
|
3647
|
+
}
|
|
3648
|
+
var value = _classPrivateFieldGet(_tail, this).value;
|
|
3649
|
+
_classPrivateFieldSet(_tail, this, _classPrivateFieldGet(_tail, this).previous);
|
|
3650
|
+
if (_classPrivateFieldGet(_tail, this) !== null) {
|
|
3651
|
+
_classPrivateFieldGet(_tail, this).next = null;
|
|
3652
|
+
} else {
|
|
3653
|
+
_classPrivateFieldSet(_head, this, null);
|
|
3654
|
+
}
|
|
3655
|
+
_classPrivateFieldSet(_size, this, (_this$size7 = _classPrivateFieldGet(_size, this), _this$size7--, _this$size7));
|
|
3656
|
+
return value;
|
|
3657
|
+
}
|
|
3658
|
+
}]);
|
|
3659
|
+
}();
|
|
3660
|
+
|
|
3661
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
3662
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
3663
|
+
/**
|
|
3664
|
+
* SerializableMap class extends the native Map to provide a JSON representation.
|
|
3665
|
+
*
|
|
3666
|
+
* This class can only have string keys, as JSON does not support non-string keys.
|
|
3667
|
+
*/
|
|
3668
|
+
var SerializableMap = /*#__PURE__*/function (_Map) {
|
|
3669
|
+
function SerializableMap() {
|
|
3670
|
+
_classCallCheck(this, SerializableMap);
|
|
3671
|
+
return _callSuper(this, SerializableMap, arguments);
|
|
3672
|
+
}
|
|
3673
|
+
_inherits(SerializableMap, _Map);
|
|
3674
|
+
return _createClass(SerializableMap, [{
|
|
3675
|
+
key: "toJSON",
|
|
3676
|
+
value:
|
|
3677
|
+
/**
|
|
3678
|
+
* Returns a JSON representation of the map.
|
|
3679
|
+
*
|
|
3680
|
+
* @returns {object}
|
|
3681
|
+
*/
|
|
3682
|
+
function toJSON() {
|
|
3683
|
+
return Object.fromEntries(this);
|
|
3684
|
+
}
|
|
3685
|
+
}]);
|
|
3686
|
+
}(/*#__PURE__*/_wrapNativeSuper(Map));
|
|
3687
|
+
|
|
3688
|
+
export { ARRAY, FLOAT, FLOAT_ANY, FLOAT_LAX, FLOAT_LAX_ANY, INT, INT_ANY, INT_LAX, INT_LAX_ANY, ISSET, IS_ARRAY, IS_OBJECT, LeUtils, LinkedList, OBJECT, STRING, STRING_ANY, SerializableMap };
|
|
3488
3689
|
//# sourceMappingURL=index.js.map
|