@libs-ui/utils 0.2.305 → 0.2.306-3

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.
@@ -637,85 +637,6 @@ const uuid = () => {
637
637
  return md5(shuffledString);
638
638
  };
639
639
 
640
- /* eslint-disable @typescript-eslint/no-explicit-any */
641
- const UtilsHttpParamsRequestInstance = (options, instance) => {
642
- return new UtilsHttpParamsRequest(options, instance);
643
- };
644
- class UtilsHttpParamsRequest extends HttpParams {
645
- params = new HttpParams();
646
- constructor(options, instance) {
647
- super(options);
648
- if (!instance) {
649
- this.params = new HttpParams(options);
650
- return;
651
- }
652
- if (instance instanceof UtilsHttpParamsRequest) {
653
- this.params = instance.getInstance();
654
- return;
655
- }
656
- if (instance instanceof HttpParams) {
657
- this.params = instance;
658
- return;
659
- }
660
- }
661
- getInstance() {
662
- return this.params;
663
- }
664
- setInstance(instance) {
665
- if (instance instanceof UtilsHttpParamsRequest) {
666
- this.params = instance.getInstance();
667
- return;
668
- }
669
- if (instance instanceof HttpParams) {
670
- this.params = instance;
671
- return;
672
- }
673
- }
674
- set(param, value) {
675
- this.params = this.params.set(param, value);
676
- return this;
677
- }
678
- has(param) {
679
- return this.params.has(param);
680
- }
681
- get(param) {
682
- return this.params.get(param);
683
- }
684
- getAll(param) {
685
- return this.params.getAll(param);
686
- }
687
- keys() {
688
- return this.params.keys();
689
- }
690
- append(param, value) {
691
- this.params = this.params.append(param, value);
692
- return this;
693
- }
694
- appendAll(params) {
695
- this.params = this.params.appendAll(params);
696
- return this;
697
- }
698
- delete(param, value) {
699
- this.params = this.params.delete(param, value);
700
- return this;
701
- }
702
- toString() {
703
- return this.params.toString();
704
- }
705
- }
706
- // Demo su dung GET_PATH_VARIABLE
707
- // interface Person {
708
- // name: string;
709
- // age: number;
710
- // location: string;
711
- // }
712
- // type c = GET_PATH_VARIABLE<Person, unknown>;
713
- // const a: c = {
714
- // "pathVariable-age": 1,
715
- // "pathVariable-location": '12',
716
- // "pathVariable-name": '124',
717
- // };
718
-
719
640
  let key = '12~@#loqwsxacva(3rdhaq12';
720
641
  /**
721
642
  * @description Thiết lập key mã hóa
@@ -1349,8 +1270,9 @@ class UtilsCache {
1349
1270
  resolve({ deleteSuccess: true });
1350
1271
  };
1351
1272
  request.onerror = (event) => {
1352
- console.trace('Error deleting database:', event.target.error);
1353
- resolve({ messageError: get(event.target.error, 'message'), deleteSuccess: false });
1273
+ const error = event.target.error;
1274
+ console.trace('Error deleting database:', error);
1275
+ resolve({ messageError: get(error || {}, 'message'), deleteSuccess: false });
1354
1276
  };
1355
1277
  request.onblocked = () => {
1356
1278
  console.trace('Delete request is blocked');
@@ -1539,6 +1461,85 @@ const getFormatData = (type, lang) => {
1539
1461
  }
1540
1462
  };
1541
1463
 
1464
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1465
+ const UtilsHttpParamsRequestInstance = (options, instance) => {
1466
+ return new UtilsHttpParamsRequest(options, instance);
1467
+ };
1468
+ class UtilsHttpParamsRequest extends HttpParams {
1469
+ params = new HttpParams();
1470
+ constructor(options, instance) {
1471
+ super(options);
1472
+ if (!instance) {
1473
+ this.params = new HttpParams(options);
1474
+ return;
1475
+ }
1476
+ if (instance instanceof UtilsHttpParamsRequest) {
1477
+ this.params = instance.getInstance();
1478
+ return;
1479
+ }
1480
+ if (instance instanceof HttpParams) {
1481
+ this.params = instance;
1482
+ return;
1483
+ }
1484
+ }
1485
+ getInstance() {
1486
+ return this.params;
1487
+ }
1488
+ setInstance(instance) {
1489
+ if (instance instanceof UtilsHttpParamsRequest) {
1490
+ this.params = instance.getInstance();
1491
+ return;
1492
+ }
1493
+ if (instance instanceof HttpParams) {
1494
+ this.params = instance;
1495
+ return;
1496
+ }
1497
+ }
1498
+ set(param, value) {
1499
+ this.params = this.params.set(param, value);
1500
+ return this;
1501
+ }
1502
+ has(param) {
1503
+ return this.params.has(param);
1504
+ }
1505
+ get(param) {
1506
+ return this.params.get(param);
1507
+ }
1508
+ getAll(param) {
1509
+ return this.params.getAll(param);
1510
+ }
1511
+ keys() {
1512
+ return this.params.keys();
1513
+ }
1514
+ append(param, value) {
1515
+ this.params = this.params.append(param, value);
1516
+ return this;
1517
+ }
1518
+ appendAll(params) {
1519
+ this.params = this.params.appendAll(params);
1520
+ return this;
1521
+ }
1522
+ delete(param, value) {
1523
+ this.params = this.params.delete(param, value);
1524
+ return this;
1525
+ }
1526
+ toString() {
1527
+ return this.params.toString();
1528
+ }
1529
+ }
1530
+ // Demo su dung GET_PATH_VARIABLE
1531
+ // interface Person {
1532
+ // name: string;
1533
+ // age: number;
1534
+ // location: string;
1535
+ // }
1536
+ // type c = GET_PATH_VARIABLE<Person, unknown>;
1537
+ // const a: c = {
1538
+ // "pathVariable-age": 1,
1539
+ // "pathVariable-location": '12',
1540
+ // "pathVariable-name": '124',
1541
+ // };
1542
+
1542
1543
  /* eslint-disable @typescript-eslint/no-explicit-any */
1543
1544
  /**Các hàm tương tự thư viện lodash */
1544
1545
  /**
@@ -1587,7 +1588,7 @@ const omitBy = (objData, predicate) => {
1587
1588
  return objData;
1588
1589
  }
1589
1590
  const newObj = {};
1590
- Object.keys(objData).forEach(key => {
1591
+ Object.keys(objData).forEach((key) => {
1591
1592
  const valueOfKey = get(objData, key);
1592
1593
  if (!predicate(valueOfKey)) {
1593
1594
  set(newObj, key, valueOfKey);
@@ -1658,7 +1659,7 @@ const omitBy = (objData, predicate) => {
1658
1659
  * get(null, 'any.path'); // undefined
1659
1660
  * get(undefined, 'any.path', 'fallback'); // 'fallback'
1660
1661
  */
1661
- const get = (obj, path, defaultValue = undefined, keepLastValueIfSignal) => {
1662
+ const get = (obj, path, defaultValue, keepLastValueIfSignal) => {
1662
1663
  if (isNil(obj)) {
1663
1664
  return defaultValue;
1664
1665
  }
@@ -1674,7 +1675,12 @@ const get = (obj, path, defaultValue = undefined, keepLastValueIfSignal) => {
1674
1675
  if (obj instanceof DOMRect) {
1675
1676
  return obj[path];
1676
1677
  }
1677
- const paths = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.$1').split('.').filter(key => key);
1678
+ const paths = Array.isArray(path)
1679
+ ? path
1680
+ : path
1681
+ .replace(/\[(\d+)]/g, '.$1')
1682
+ .split('.')
1683
+ .filter((key) => key);
1678
1684
  for (const index in paths) {
1679
1685
  const key = paths[index];
1680
1686
  if (obj instanceof CSSStyleDeclaration) {
@@ -1705,18 +1711,23 @@ const get = (obj, path, defaultValue = undefined, keepLastValueIfSignal) => {
1705
1711
  * set(obj, 'a.b', 2); // { a: { b: 2 } }
1706
1712
  */
1707
1713
  const set = (obj, path, value) => {
1708
- if (!obj || (typeof obj !== "object" && !isSignal(obj)) || (isSignal(obj) && typeof obj() !== "object")) {
1709
- throw new Error("The first argument must be an object");
1714
+ if (!obj || (typeof obj !== 'object' && !isSignal(obj)) || (isSignal(obj) && typeof obj() !== 'object')) {
1715
+ throw new Error('The first argument must be an object');
1710
1716
  }
1711
1717
  if (obj instanceof HttpParams) {
1712
1718
  return obj.set(`${path}`, value);
1713
1719
  }
1714
- const pathArray = Array.isArray(path) ? path : path.replace(/\[(\d+)]/g, '.[$1]').split('.').filter(key => key);
1720
+ const pathArray = Array.isArray(path)
1721
+ ? path
1722
+ : path
1723
+ .replace(/\[(\d+)]/g, '.[$1]')
1724
+ .split('.')
1725
+ .filter((key) => key);
1715
1726
  let currentObjectByKey = isSignal(obj) ? obj() : obj;
1716
1727
  let preObjectByKey = obj;
1717
1728
  pathArray.forEach((key, index) => {
1718
1729
  if (index < pathArray.length - 1) {
1719
- if (!(key in currentObjectByKey) || (typeof currentObjectByKey[key] !== "object" && !isSignal(currentObjectByKey[key]))) {
1730
+ if (!(key in currentObjectByKey) || (typeof currentObjectByKey[key] !== 'object' && !isSignal(currentObjectByKey[key]))) {
1720
1731
  const nextKey = pathArray[index + 1];
1721
1732
  key = key.replace(/\[(\d+)]/g, '$1');
1722
1733
  currentObjectByKey[key] = /\[(\d+)]/g.test(nextKey) ? [] : {};
@@ -1726,7 +1737,7 @@ const set = (obj, path, value) => {
1726
1737
  currentObjectByKey = isSignal(currentObjectByKey) ? currentObjectByKey() : currentObjectByKey;
1727
1738
  return;
1728
1739
  }
1729
- if (typeof currentObjectByKey !== "object") {
1740
+ if (typeof currentObjectByKey !== 'object') {
1730
1741
  return;
1731
1742
  }
1732
1743
  // Gán giá trị ở cuối đường dẫn
@@ -1807,13 +1818,13 @@ const cloneDeep = (data, options = { ignoreSignal: false }, seen = new WeakMap()
1807
1818
  if (data instanceof Set) {
1808
1819
  const setCopy = new Set();
1809
1820
  seen.set(data, setCopy);
1810
- data.forEach(val => {
1821
+ data.forEach((val) => {
1811
1822
  setCopy.add(cloneDeep(val, options, seen));
1812
1823
  });
1813
1824
  return setCopy;
1814
1825
  }
1815
1826
  if (Array.isArray(data)) {
1816
- seen.set(data, data.map(item => cloneDeep(item, options, seen)));
1827
+ seen.set(data, data.map((item) => cloneDeep(item, options, seen)));
1817
1828
  return seen.get(data);
1818
1829
  }
1819
1830
  if (data instanceof File || data instanceof Blob || Object.prototype.toString.call(data) === '[object File]') {
@@ -1995,7 +2006,7 @@ const isEqual = (value1, value2, options) => {
1995
2006
  return false;
1996
2007
  }
1997
2008
  if (!exactlyPosition) {
1998
- return !value1.some(item => !value2.includes(item));
2009
+ return !value1.some((item) => !value2.includes(item));
1999
2010
  }
2000
2011
  return !value1.some((item, index) => !isEqual(item, value2[index], options));
2001
2012
  }
@@ -2028,7 +2039,7 @@ const uniqBy = (data, key) => {
2028
2039
  // Xử lý mảng chứa signal values
2029
2040
  if (data[0] && isSignal(data[0])) {
2030
2041
  const seen = new Set();
2031
- return data.filter(item => {
2042
+ return data.filter((item) => {
2032
2043
  const value = `${get(item, '')}`;
2033
2044
  if (seen.has(value)) {
2034
2045
  return false;
@@ -2041,7 +2052,7 @@ const uniqBy = (data, key) => {
2041
2052
  return Array.from(new Set(data));
2042
2053
  }
2043
2054
  const dataUnique = keyBy(data, key);
2044
- return Object.keys(dataUnique).map(key => dataUnique[key]);
2055
+ return Object.keys(dataUnique).map((key) => dataUnique[key]);
2045
2056
  };
2046
2057
  const generateInterface = (obj, interfaceName) => {
2047
2058
  const generateType = (value) => {
@@ -2666,6 +2677,7 @@ const convertUrlToFile = (url, fileName) => {
2666
2677
  const file = convertBase64ToBlob(reader.result);
2667
2678
  resolve(convertBlobToFile(file, fileName || Date.now().toLocaleString()));
2668
2679
  };
2680
+ reader.onerror = () => resolve(undefined);
2669
2681
  reader.readAsDataURL(xhr.response);
2670
2682
  };
2671
2683
  xhr.onerror = (err) => {