@synerise/ds-input-number 0.8.13 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.8.15](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.14...@synerise/ds-input-number@0.8.15) (2023-07-17)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-input-number
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.8.14](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.13...@synerise/ds-input-number@0.8.14) (2023-07-12)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **input-number:** input number edge cases fix ([6615b12](https://github.com/Synerise/synerise-design/commit/6615b1220fb740d6a5efe53621736e8cf4a1a5b8))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.8.13](https://github.com/Synerise/synerise-design/compare/@synerise/ds-input-number@0.8.12...@synerise/ds-input-number@0.8.13) (2023-07-12)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-input-number
@@ -1,3 +1,4 @@
1
1
  import { Delimiter } from '@synerise/ds-data-format';
2
2
  export declare const MAXIMUM_FRACTION_DIGITS = 20;
3
3
  export declare const NUMBER_DELIMITER: Delimiter;
4
+ export declare const MAXIMUM_NUMBER_DIGITS = 15;
@@ -1,2 +1,3 @@
1
1
  export var MAXIMUM_FRACTION_DIGITS = 20;
2
- export var NUMBER_DELIMITER = '.';
2
+ export var NUMBER_DELIMITER = '.';
3
+ export var MAXIMUM_NUMBER_DIGITS = 15;
@@ -1,4 +1,4 @@
1
1
  import { ReactText } from 'react';
2
2
  import { NumberToFormatOptions, Delimiter } from '@synerise/ds-data-format';
3
- export declare const formatNumber: (value: string | number | undefined, formatValue: (value: number, options: NumberToFormatOptions) => string, thousandDelimiter: Delimiter, decimalDelimiter: Delimiter, valueFormatOptions?: NumberToFormatOptions | undefined) => string;
4
- export declare const parseFormattedNumber: (value: string | undefined, formatValue: (value: number, options: NumberToFormatOptions) => string, thousandDelimiter: Delimiter, decimalDelimiter: Delimiter) => ReactText;
3
+ export declare const formatNumber: (value: string | number | undefined, formatValue: (value: number, options: NumberToFormatOptions) => string, notationThousandDelimiter: Delimiter, notationDecimalDelimiter: Delimiter, valueFormatOptions?: NumberToFormatOptions | undefined) => string;
4
+ export declare const parseFormattedNumber: (value: string | undefined, formatValue: (value: number, options: NumberToFormatOptions) => string, notationThousandDelimiter: Delimiter, notationDecimalDelimiter: Delimiter) => ReactText;
@@ -4,52 +4,62 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { MAXIMUM_FRACTION_DIGITS, NUMBER_DELIMITER } from '../constants/inputNumber.constants'; // input 1: not formatted number string (on input change)
8
- // input 2: not formatted number (on blur)
7
+ import { MAXIMUM_FRACTION_DIGITS, MAXIMUM_NUMBER_DIGITS, NUMBER_DELIMITER } from '../constants/inputNumber.constants'; // input case 1: not formatted number string (on input change)
8
+ // input case 2: not formatted number (on blur)
9
9
  // output: formatted number string with decimal char
10
10
 
11
- export var formatNumber = function formatNumber(value, formatValue, thousandDelimiter, decimalDelimiter, valueFormatOptions) {
11
+ export var formatNumber = function formatNumber(value, formatValue, notationThousandDelimiter, notationDecimalDelimiter, valueFormatOptions) {
12
+ var _value$match, _value$match2;
13
+
12
14
  if (value === undefined || value === '') return '';
13
15
 
14
16
  var formatOptions = _objectSpread({
15
17
  maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
16
18
  }, valueFormatOptions);
17
19
 
18
- var notationDecimalChar = '';
19
- var result = '';
20
-
21
20
  if (typeof value === 'number') {
22
- result = formatValue(value, formatOptions);
23
- } else {
24
- var lastChar = value == null ? void 0 : value.slice(-1);
25
-
26
- if (lastChar === NUMBER_DELIMITER) {
27
- notationDecimalChar = decimalDelimiter;
28
- }
21
+ return formatValue(value, formatOptions);
22
+ }
29
23
 
30
- var numberResult = Number(value);
24
+ var result = '';
25
+ var lastChar = value == null ? void 0 : value.slice(-1);
26
+ var numberResult = parseFloat(value);
27
+ var notationDecimalChar = lastChar === NUMBER_DELIMITER ? notationDecimalDelimiter : '';
28
+ var zerosAtTheEnd = (_value$match = value.match(new RegExp('0+$'))) == null ? void 0 : _value$match[0];
29
+ var zerosWithDecimalDelimiterAtTheEnd = (_value$match2 = value.match(new RegExp("\\" + NUMBER_DELIMITER + "0+$"))) == null ? void 0 : _value$match2[0];
30
+ var numberDelimiterExists = new RegExp("\\" + NUMBER_DELIMITER).test(value);
31
+
32
+ if (Number.isNaN(numberResult)) {
33
+ return '';
34
+ }
31
35
 
32
- if (Number.isNaN(numberResult)) {
33
- return '';
34
- }
36
+ result = formatValue(numberResult, formatOptions);
37
+ result = "" + result + notationDecimalChar;
35
38
 
36
- result = formatValue(numberResult, formatOptions);
37
- result = "" + result + notationDecimalChar;
39
+ if (zerosWithDecimalDelimiterAtTheEnd) {
40
+ result = "" + result + zerosWithDecimalDelimiterAtTheEnd;
41
+ } else if (zerosAtTheEnd && numberDelimiterExists) {
42
+ result = "" + result + zerosAtTheEnd;
38
43
  }
39
44
 
40
45
  return result;
41
46
  }; // input: formatted number string
42
47
  // output: not formatted number string with decimal char
43
48
 
44
- export var parseFormattedNumber = function parseFormattedNumber(value, formatValue, thousandDelimiter, decimalDelimiter) {
49
+ export var parseFormattedNumber = function parseFormattedNumber(value, formatValue, notationThousandDelimiter, notationDecimalDelimiter) {
45
50
  if (value === undefined || value === '') {
46
51
  return '';
47
52
  }
48
53
 
49
- var result = value.split(thousandDelimiter).join('');
54
+ var result = value;
55
+ result = result.split(notationThousandDelimiter).join('');
56
+
57
+ if (result.length > MAXIMUM_NUMBER_DIGITS) {
58
+ result = result.slice(0, MAXIMUM_NUMBER_DIGITS);
59
+ }
50
60
 
51
- if (decimalDelimiter !== NUMBER_DELIMITER) {
52
- result = result.replace(decimalDelimiter, NUMBER_DELIMITER);
61
+ if (notationDecimalDelimiter !== NUMBER_DELIMITER) {
62
+ result = result.replace(notationDecimalDelimiter, NUMBER_DELIMITER);
53
63
  }
54
64
 
55
65
  if ((result.match(new RegExp("\\" + NUMBER_DELIMITER, 'g')) || []).length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-input-number",
3
- "version": "0.8.13",
3
+ "version": "0.8.15",
4
4
  "description": "Input-Number UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@synerise/ds-icon": "^0.53.0",
36
36
  "@synerise/ds-tooltip": "^0.13.7",
37
- "@synerise/ds-utils": "^0.24.10",
37
+ "@synerise/ds-utils": "^0.24.11",
38
38
  "uuid": "^7.0.2"
39
39
  },
40
40
  "peerDependencies": {
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "@types/uuid": "7.0.0"
47
47
  },
48
- "gitHead": "18ba824126ca4dd53128c5dac30abf7755fe7502"
48
+ "gitHead": "b2df0b45094602990b6ef46e20fb0eb655baf126"
49
49
  }