Skip to content

Commit 4d612c6

Browse files
committed
chore: build package
chore: do not include dev files in npm package
1 parent fc015be commit 4d612c6

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
@@ -254,9 +254,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
254254
function roundToPrecision(numStr, scale, fixedDecimalScale) {
255255
//if number is empty don't do anything return empty string
256256
if (['', '-'].indexOf(numStr) !== -1) return numStr;
257-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
257+
var normalizedNum = getRidOfScientificNotation(numStr);
258+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
258259

259-
var _splitDecimal = splitDecimal(numStr),
260+
var _splitDecimal = splitDecimal(normalizedNum),
260261
beforeDecimal = _splitDecimal.beforeDecimal,
261262
afterDecimal = _splitDecimal.afterDecimal,
262263
hasNagation = _splitDecimal.hasNagation;
@@ -274,6 +275,34 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
274275
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
275276
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
276277
}
278+
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
279+
function getRidOfScientificNotation(value) {
280+
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
281+
return value;
282+
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case
283+
284+
285+
var number = parseFloat(value);
286+
287+
if (Math.abs(number) < 1.0) {
288+
var e = parseInt(number.toString().split("e-")[1]);
289+
290+
if (e) {
291+
number *= Math.pow(10, e - 1);
292+
return "0." + new Array(e).join("0") + number.toString().substring(2);
293+
}
294+
} else {
295+
var _e = parseInt(number.toString().split("+")[1]);
296+
297+
if (_e > 20) {
298+
_e -= 20;
299+
number /= Math.pow(10, _e);
300+
return number + new Array(_e + 1).join("0");
301+
}
302+
}
303+
304+
return number.toString();
305+
}
277306
function omit(obj, keyMaps) {
278307
var filteredObj = {};
279308
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
@@ -260,9 +260,10 @@
260260
function roundToPrecision(numStr, scale, fixedDecimalScale) {
261261
//if number is empty don't do anything return empty string
262262
if (['', '-'].indexOf(numStr) !== -1) return numStr;
263-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
263+
var normalizedNum = getRidOfScientificNotation(numStr);
264+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
264265

265-
var _splitDecimal = splitDecimal(numStr),
266+
var _splitDecimal = splitDecimal(normalizedNum),
266267
beforeDecimal = _splitDecimal.beforeDecimal,
267268
afterDecimal = _splitDecimal.afterDecimal,
268269
hasNagation = _splitDecimal.hasNagation;
@@ -280,6 +281,34 @@
280281
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
281282
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
282283
}
284+
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
285+
function getRidOfScientificNotation(value) {
286+
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
287+
return value;
288+
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case
289+
290+
291+
var number = parseFloat(value);
292+
293+
if (Math.abs(number) < 1.0) {
294+
var e = parseInt(number.toString().split("e-")[1]);
295+
296+
if (e) {
297+
number *= Math.pow(10, e - 1);
298+
return "0." + new Array(e).join("0") + number.toString().substring(2);
299+
}
300+
} else {
301+
var _e = parseInt(number.toString().split("+")[1]);
302+
303+
if (_e > 20) {
304+
_e -= 20;
305+
number /= Math.pow(10, _e);
306+
return number + new Array(_e + 1).join("0");
307+
}
308+
}
309+
310+
return number.toString();
311+
}
283312
function omit(obj, keyMaps) {
284313
var filteredObj = {};
285314
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
@@ -13,6 +13,7 @@ exports.splitDecimal = splitDecimal;
1313
exports.fixLeadingZero = fixLeadingZero;
1414
exports.limitToScale = limitToScale;
1515
exports.roundToPrecision = roundToPrecision;
16+
exports.getRidOfScientificNotation = getRidOfScientificNotation;
1617
exports.omit = omit;
1718
exports.setCaretPosition = setCaretPosition;
1819
exports.findChangedIndex = findChangedIndex;
@@ -107,9 +108,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
107108
function roundToPrecision(numStr, scale, fixedDecimalScale) {
108109
//if number is empty don't do anything return empty string
109110
if (['', '-'].indexOf(numStr) !== -1) return numStr;
110-
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
111+
var normalizedNum = getRidOfScientificNotation(numStr);
112+
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;
111113

112-
var _splitDecimal = splitDecimal(numStr),
114+
var _splitDecimal = splitDecimal(normalizedNum),
113115
beforeDecimal = _splitDecimal.beforeDecimal,
114116
afterDecimal = _splitDecimal.afterDecimal,
115117
hasNagation = _splitDecimal.hasNagation;
@@ -128,6 +130,36 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
128130
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
129131
}
130132

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

0 commit comments

Comments
 (0)