Skip to content

Commit 77ea545

Browse files
committed
chore: build package
chore: do not include dev files in npm package
1 parent 5f80f27 commit 77ea545

File tree

5 files changed

+99
-7
lines changed

5 files changed

+99
-7
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ src/
2222
test/
2323
tmp/
2424
flow-typed/
25+
.idea/
26+
.vscode/

dist/react-number-format.es.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
257257
function roundToPrecision(numStr, scale, fixedDecimalScale) {
258258
//if number is empty don't do anything return empty string
259259
if (['', '-'].indexOf(numStr) !== -1) return numStr;
260-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
260+
var normalizedNum = getRidOfScientificNotation(numStr);
261+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
261262

262-
var _splitDecimal = splitDecimal(numStr),
263+
var _splitDecimal = splitDecimal(normalizedNum),
263264
beforeDecimal = _splitDecimal.beforeDecimal,
264265
afterDecimal = _splitDecimal.afterDecimal,
265266
hasNagation = _splitDecimal.hasNagation;
@@ -277,6 +278,34 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
277278
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
278279
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
279280
}
281+
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
282+
function getRidOfScientificNotation(value) {
283+
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
284+
return value;
285+
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case
286+
287+
288+
var number = parseFloat(value);
289+
290+
if (Math.abs(number) < 1.0) {
291+
var e = parseInt(number.toString().split("e-")[1]);
292+
293+
if (e) {
294+
number *= Math.pow(10, e - 1);
295+
return "0." + new Array(e).join("0") + number.toString().substring(2);
296+
}
297+
} else {
298+
var _e = parseInt(number.toString().split("+")[1]);
299+
300+
if (_e > 20) {
301+
_e -= 20;
302+
number /= Math.pow(10, _e);
303+
return number + new Array(_e + 1).join("0");
304+
}
305+
}
306+
307+
return number.toString();
308+
}
280309
function omit(obj, keyMaps) {
281310
var filteredObj = {};
282311
Object.keys(obj).forEach(function (key) {

dist/react-number-format.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@
263263
function roundToPrecision(numStr, scale, fixedDecimalScale) {
264264
//if number is empty don't do anything return empty string
265265
if (['', '-'].indexOf(numStr) !== -1) return numStr;
266-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
266+
var normalizedNum = getRidOfScientificNotation(numStr);
267+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
267268

268-
var _splitDecimal = splitDecimal(numStr),
269+
var _splitDecimal = splitDecimal(normalizedNum),
269270
beforeDecimal = _splitDecimal.beforeDecimal,
270271
afterDecimal = _splitDecimal.afterDecimal,
271272
hasNagation = _splitDecimal.hasNagation;
@@ -283,6 +284,34 @@
283284
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
284285
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
285286
}
287+
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
288+
function getRidOfScientificNotation(value) {
289+
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
290+
return value;
291+
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case
292+
293+
294+
var number = parseFloat(value);
295+
296+
if (Math.abs(number) < 1.0) {
297+
var e = parseInt(number.toString().split("e-")[1]);
298+
299+
if (e) {
300+
number *= Math.pow(10, e - 1);
301+
return "0." + new Array(e).join("0") + number.toString().substring(2);
302+
}
303+
} else {
304+
var _e = parseInt(number.toString().split("+")[1]);
305+
306+
if (_e > 20) {
307+
_e -= 20;
308+
number /= Math.pow(10, _e);
309+
return number + new Array(_e + 1).join("0");
310+
}
311+
}
312+
313+
return number.toString();
314+
}
286315
function omit(obj, keyMaps) {
287316
var filteredObj = {};
288317
Object.keys(obj).forEach(function (key) {

dist/react-number-format.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports.splitDecimal = splitDecimal;
1414
exports.fixLeadingZero = fixLeadingZero;
1515
exports.limitToScale = limitToScale;
1616
exports.roundToPrecision = roundToPrecision;
17+
exports.getRidOfScientificNotation = getRidOfScientificNotation;
1718
exports.omit = omit;
1819
exports.setCaretPosition = setCaretPosition;
1920
exports.findChangedIndex = findChangedIndex;
@@ -112,9 +113,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
112113
function roundToPrecision(numStr, scale, fixedDecimalScale) {
113114
//if number is empty don't do anything return empty string
114115
if (['', '-'].indexOf(numStr) !== -1) return numStr;
115-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
116+
var normalizedNum = getRidOfScientificNotation(numStr);
117+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
116118

117-
var _splitDecimal = splitDecimal(numStr),
119+
var _splitDecimal = splitDecimal(normalizedNum),
118120
beforeDecimal = _splitDecimal.beforeDecimal,
119121
afterDecimal = _splitDecimal.afterDecimal,
120122
hasNagation = _splitDecimal.hasNagation;
@@ -133,6 +135,36 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
133135
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
134136
}
135137

138+
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
139+
140+
function getRidOfScientificNotation(value) {
141+
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
142+
return value;
143+
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case
144+
145+
146+
var number = parseFloat(value);
147+
148+
if (Math.abs(number) < 1.0) {
149+
var e = parseInt(number.toString().split("e-")[1]);
150+
151+
if (e) {
152+
number *= Math.pow(10, e - 1);
153+
return "0." + new Array(e).join("0") + number.toString().substring(2);
154+
}
155+
} else {
156+
var _e = parseInt(number.toString().split("+")[1]);
157+
158+
if (_e > 20) {
159+
_e -= 20;
160+
number /= Math.pow(10, _e);
161+
return number + new Array(_e + 1).join("0");
162+
}
163+
}
164+
165+
return number.toString();
166+
}
167+
136168
function omit(obj, keyMaps) {
137169
var filteredObj = {};
138170
Object.keys(obj).forEach(function (key) {

0 commit comments

Comments
 (0)