@jsuites/utils 6.0.1 → 6.0.2

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 +47 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1534,7 +1534,7 @@
1534
1534
  }
1535
1535
  }
1536
1536
  },
1537
- 'HH24': function(v, two) {
1537
+ 'HH24': function(v, two = true) {
1538
1538
  let test = false;
1539
1539
 
1540
1540
  let number = parseInt(v)
@@ -1542,7 +1542,7 @@
1542
1542
  if (number >= 0 && number < 10) {
1543
1543
  if (isBlank(this.values[this.index])) {
1544
1544
  if (number > 2 && number < 10) {
1545
- if (two) {
1545
+ if (two !== false) {
1546
1546
  v = 0 + v;
1547
1547
  }
1548
1548
  this.date[3] = this.values[this.index] = v;
@@ -1552,13 +1552,13 @@
1552
1552
  }
1553
1553
  } else {
1554
1554
  if (this.values[this.index] == 2 && number < 4) {
1555
- if (! two && this.values[this.index] === '0') {
1555
+ if (two === false && this.values[this.index] === '0') {
1556
1556
  this.values[this.index] = '';
1557
1557
  }
1558
1558
  this.date[3] = this.values[this.index] += v;
1559
1559
  this.index++;
1560
1560
  } else if (this.values[this.index] < 2 && number < 10) {
1561
- if (! two && this.values[this.index] === '0') {
1561
+ if (two === false && this.values[this.index] === '0') {
1562
1562
  this.values[this.index] = '';
1563
1563
  }
1564
1564
  this.date[3] = this.values[this.index] += v;
@@ -1575,6 +1575,10 @@
1575
1575
  if (test === true) {
1576
1576
  var t = parseInt(this.values[this.index]);
1577
1577
  if (t >= 0 && t < 24) {
1578
+ // Pad single digit with leading zero for HH24 format
1579
+ if (two !== false && this.values[this.index] && this.values[this.index].length === 1) {
1580
+ this.values[this.index] = '0' + this.values[this.index];
1581
+ }
1578
1582
  this.date[3] = this.values[this.index];
1579
1583
  this.index++;
1580
1584
  return false;
@@ -1582,10 +1586,10 @@
1582
1586
  }
1583
1587
  },
1584
1588
  'HH': function(v) {
1585
- parseMethods['HH24'].call(this, v, 1);
1589
+ parseMethods['HH24'].call(this, v, true);
1586
1590
  },
1587
1591
  'H': function(v) {
1588
- parseMethods['HH24'].call(this, v, 0);
1592
+ parseMethods['HH24'].call(this, v, false);
1589
1593
  },
1590
1594
  '\\[H\\]': function(v) {
1591
1595
  if (this.values[this.index] == undefined) {
@@ -2579,7 +2583,33 @@
2579
2583
  }
2580
2584
 
2581
2585
  const format = function(str, config) {
2582
- let ret = new Intl.NumberFormat(config.locale, config.options || {}).format(str);
2586
+ // Extract numeric value from formatted or unformatted string (e.g., "₹3.00" -> 3)
2587
+ // Using same logic as ParseValue to handle already-formatted strings
2588
+ let numericValue;
2589
+ const decimal = config.decimal || '.';
2590
+ let v = String(str).split(decimal);
2591
+
2592
+ // Detect negative sign
2593
+ let signal = v[0].includes('-');
2594
+
2595
+ // Extract digits only
2596
+ v[0] = v[0].match(/[0-9]+/g);
2597
+ if (v[0]) {
2598
+ if (signal) v[0].unshift('-');
2599
+ v[0] = v[0].join('');
2600
+ } else {
2601
+ v[0] = signal ? '-0' : '0';
2602
+ }
2603
+
2604
+ if (v[1] !== undefined) {
2605
+ v[1] = v[1].match(/[0-9]+/g);
2606
+ v[1] = v[1] ? v[1].join('') : '';
2607
+ }
2608
+
2609
+ // Convert to number
2610
+ numericValue = v[0] || v[1] ? parseFloat(v.join('.')) : 0;
2611
+
2612
+ let ret = new Intl.NumberFormat(config.locale, config.options || {}).format(numericValue);
2583
2613
 
2584
2614
  config.values.push(ret);
2585
2615
  }
@@ -3965,7 +3995,7 @@
3965
3995
  let value = element[property];
3966
3996
  // Get the mask
3967
3997
  if (! mask) {
3968
- mask = element.getAttribute('data-mask');
3998
+ mask = element.getAttribute('data-mask') || element.mask;
3969
3999
  }
3970
4000
  // Keep the current caret position
3971
4001
  let caret = getCaret(element);
@@ -3973,8 +4003,16 @@
3973
4003
  value = value.substring(0, caret) + hiddenCaret + value.substring(caret);
3974
4004
  }
3975
4005
 
4006
+ if (typeof mask === 'string') {
4007
+ mask = { mask: mask };
4008
+ }
4009
+
4010
+ if (mask.locale) {
4011
+ return;
4012
+ }
4013
+
3976
4014
  // Run mask
3977
- let result = Component(value, { mask: mask }, true);
4015
+ let result = Component(value, mask, true);
3978
4016
 
3979
4017
  // New value
3980
4018
  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.2",
23
23
  "bugs": "https://github.com/jsuites/jsuites/issues",
24
24
  "homepage": "https://github.com/jsuites/jsuites",
25
25
  "docs": "https://jsuites.net/",