@jsuites/utils 6.0.1 → 6.0.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.
Files changed (2) hide show
  1. package/dist/index.js +54 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -994,14 +994,8 @@
994
994
  const hiddenCaret = "\u200B";
995
995
  // Locale for date parsing
996
996
  const userLocale = (typeof navigator !== 'undefined' && navigator.language) || 'en-US';
997
- // Labels
998
- const weekDaysFull = Helpers.weekdays;
999
- const weekDays = Helpers.weekdaysShort;
1000
- const monthsFull = Helpers.months;
1001
- const months = Helpers.monthsShort;
1002
997
 
1003
998
  // Helpers
1004
-
1005
999
  const focus = function(el) {
1006
1000
  if (el.textContent.length) {
1007
1001
  // Handle contenteditable elements
@@ -1373,9 +1367,9 @@
1373
1367
  this.values[this.index] = '';
1374
1368
  }
1375
1369
  let value = (this.values[this.index] + v).toLowerCase();
1376
- for (var i = 0; i < monthsFull.length; i++) {
1377
- if (monthsFull[i][0].toLowerCase().indexOf(value) === 0) {
1378
- this.values[this.index] = monthsFull[i][0];
1370
+ for (var i = 0; i < Helpers.months.length; i++) {
1371
+ if (Helpers.months[i][0].toLowerCase().indexOf(value) === 0) {
1372
+ this.values[this.index] = Helpers.months[i][0];
1379
1373
  this.date[1] = i + 1;
1380
1374
  this.index++;
1381
1375
  break;
@@ -1383,13 +1377,13 @@
1383
1377
  }
1384
1378
  },
1385
1379
  'MMMM': function(v) {
1386
- let ret = parseMethods.FIND.call(this, v, monthsFull);
1380
+ let ret = parseMethods.FIND.call(this, v, Helpers.months);
1387
1381
  if (typeof(ret) !== 'undefined') {
1388
1382
  this.date[1] = ret + 1;
1389
1383
  }
1390
1384
  },
1391
1385
  'MMM': function(v) {
1392
- let ret = parseMethods.FIND.call(this, v, months);
1386
+ let ret = parseMethods.FIND.call(this, v, Helpers.monthsShort);
1393
1387
  if (typeof(ret) !== 'undefined') {
1394
1388
  this.date[1] = ret + 1;
1395
1389
  }
@@ -1442,10 +1436,10 @@
1442
1436
  return parseMethods['MMM'].call(this, v);
1443
1437
  },
1444
1438
  'DDDD': function(v) {
1445
- return parseMethods.FIND.call(this, v, weekDaysFull);
1439
+ return parseMethods.FIND.call(this, v, Helpers.weekdays);
1446
1440
  },
1447
1441
  'DDD': function(v) {
1448
- return parseMethods.FIND.call(this, v, weekDays);
1442
+ return parseMethods.FIND.call(this, v, Helpers.weekdaysShort);
1449
1443
  },
1450
1444
  'DD': function(v, single) {
1451
1445
  const commit = () => {
@@ -1534,7 +1528,7 @@
1534
1528
  }
1535
1529
  }
1536
1530
  },
1537
- 'HH24': function(v, two) {
1531
+ 'HH24': function(v, two = true) {
1538
1532
  let test = false;
1539
1533
 
1540
1534
  let number = parseInt(v)
@@ -1542,7 +1536,7 @@
1542
1536
  if (number >= 0 && number < 10) {
1543
1537
  if (isBlank(this.values[this.index])) {
1544
1538
  if (number > 2 && number < 10) {
1545
- if (two) {
1539
+ if (two !== false) {
1546
1540
  v = 0 + v;
1547
1541
  }
1548
1542
  this.date[3] = this.values[this.index] = v;
@@ -1552,13 +1546,13 @@
1552
1546
  }
1553
1547
  } else {
1554
1548
  if (this.values[this.index] == 2 && number < 4) {
1555
- if (! two && this.values[this.index] === '0') {
1549
+ if (two === false && this.values[this.index] === '0') {
1556
1550
  this.values[this.index] = '';
1557
1551
  }
1558
1552
  this.date[3] = this.values[this.index] += v;
1559
1553
  this.index++;
1560
1554
  } else if (this.values[this.index] < 2 && number < 10) {
1561
- if (! two && this.values[this.index] === '0') {
1555
+ if (two === false && this.values[this.index] === '0') {
1562
1556
  this.values[this.index] = '';
1563
1557
  }
1564
1558
  this.date[3] = this.values[this.index] += v;
@@ -1575,6 +1569,10 @@
1575
1569
  if (test === true) {
1576
1570
  var t = parseInt(this.values[this.index]);
1577
1571
  if (t >= 0 && t < 24) {
1572
+ // Pad single digit with leading zero for HH24 format
1573
+ if (two !== false && this.values[this.index] && this.values[this.index].length === 1) {
1574
+ this.values[this.index] = '0' + this.values[this.index];
1575
+ }
1578
1576
  this.date[3] = this.values[this.index];
1579
1577
  this.index++;
1580
1578
  return false;
@@ -1582,10 +1580,10 @@
1582
1580
  }
1583
1581
  },
1584
1582
  'HH': function(v) {
1585
- parseMethods['HH24'].call(this, v, 1);
1583
+ parseMethods['HH24'].call(this, v, true);
1586
1584
  },
1587
1585
  'H': function(v) {
1588
- parseMethods['HH24'].call(this, v, 0);
1586
+ parseMethods['HH24'].call(this, v, false);
1589
1587
  },
1590
1588
  '\\[H\\]': function(v) {
1591
1589
  if (this.values[this.index] == undefined) {
@@ -2579,7 +2577,33 @@
2579
2577
  }
2580
2578
 
2581
2579
  const format = function(str, config) {
2582
- let ret = new Intl.NumberFormat(config.locale, config.options || {}).format(str);
2580
+ // Extract numeric value from formatted or unformatted string (e.g., "₹3.00" -> 3)
2581
+ // Using same logic as ParseValue to handle already-formatted strings
2582
+ let numericValue;
2583
+ const decimal = config.decimal || '.';
2584
+ let v = String(str).split(decimal);
2585
+
2586
+ // Detect negative sign
2587
+ let signal = v[0].includes('-');
2588
+
2589
+ // Extract digits only
2590
+ v[0] = v[0].match(/[0-9]+/g);
2591
+ if (v[0]) {
2592
+ if (signal) v[0].unshift('-');
2593
+ v[0] = v[0].join('');
2594
+ } else {
2595
+ v[0] = signal ? '-0' : '0';
2596
+ }
2597
+
2598
+ if (v[1] !== undefined) {
2599
+ v[1] = v[1].match(/[0-9]+/g);
2600
+ v[1] = v[1] ? v[1].join('') : '';
2601
+ }
2602
+
2603
+ // Convert to number
2604
+ numericValue = v[0] || v[1] ? parseFloat(v.join('.')) : 0;
2605
+
2606
+ let ret = new Intl.NumberFormat(config.locale, config.options || {}).format(numericValue);
2583
2607
 
2584
2608
  config.values.push(ret);
2585
2609
  }
@@ -3965,7 +3989,7 @@
3965
3989
  let value = element[property];
3966
3990
  // Get the mask
3967
3991
  if (! mask) {
3968
- mask = element.getAttribute('data-mask');
3992
+ mask = element.getAttribute('data-mask') || element.mask;
3969
3993
  }
3970
3994
  // Keep the current caret position
3971
3995
  let caret = getCaret(element);
@@ -3973,8 +3997,16 @@
3973
3997
  value = value.substring(0, caret) + hiddenCaret + value.substring(caret);
3974
3998
  }
3975
3999
 
4000
+ if (typeof mask === 'string') {
4001
+ mask = { mask: mask };
4002
+ }
4003
+
4004
+ if (mask.locale) {
4005
+ return;
4006
+ }
4007
+
3976
4008
  // Run mask
3977
- let result = Component(value, { mask: mask }, true);
4009
+ let result = Component(value, mask, true);
3978
4010
 
3979
4011
  // New value
3980
4012
  let newValue = result.values.join('');
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "javascript utilities"
20
20
  ],
21
21
  "main": "dist/index.js",
22
- "version": "6.0.1",
22
+ "version": "6.0.3",
23
23
  "bugs": "https://github.com/jsuites/jsuites/issues",
24
24
  "homepage": "https://github.com/jsuites/jsuites",
25
25
  "docs": "https://jsuites.net/",