Skip to content

Commit

Permalink
chore: build package
Browse files Browse the repository at this point in the history
chore: do not include dev files in npm package
  • Loading branch information
yhnavein committed Feb 13, 2021
1 parent 5f80f27 commit 77ea545
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ src/
test/
tmp/
flow-typed/
.idea/
.vscode/
33 changes: 31 additions & 2 deletions dist/react-number-format.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
function roundToPrecision(numStr, scale, fixedDecimalScale) {
//if number is empty don't do anything return empty string
if (['', '-'].indexOf(numStr) !== -1) return numStr;
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
var normalizedNum = getRidOfScientificNotation(numStr);
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;

var _splitDecimal = splitDecimal(numStr),
var _splitDecimal = splitDecimal(normalizedNum),
beforeDecimal = _splitDecimal.beforeDecimal,
afterDecimal = _splitDecimal.afterDecimal,
hasNagation = _splitDecimal.hasNagation;
Expand All @@ -277,6 +278,34 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
}
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
function getRidOfScientificNotation(value) {
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
return value;
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case


var number = parseFloat(value);

if (Math.abs(number) < 1.0) {
var e = parseInt(number.toString().split("e-")[1]);

if (e) {
number *= Math.pow(10, e - 1);
return "0." + new Array(e).join("0") + number.toString().substring(2);
}
} else {
var _e = parseInt(number.toString().split("+")[1]);

if (_e > 20) {
_e -= 20;
number /= Math.pow(10, _e);
return number + new Array(_e + 1).join("0");
}
}

return number.toString();
}
function omit(obj, keyMaps) {
var filteredObj = {};
Object.keys(obj).forEach(function (key) {
Expand Down
33 changes: 31 additions & 2 deletions dist/react-number-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@
function roundToPrecision(numStr, scale, fixedDecimalScale) {
//if number is empty don't do anything return empty string
if (['', '-'].indexOf(numStr) !== -1) return numStr;
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
var normalizedNum = getRidOfScientificNotation(numStr);
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;

var _splitDecimal = splitDecimal(numStr),
var _splitDecimal = splitDecimal(normalizedNum),
beforeDecimal = _splitDecimal.beforeDecimal,
afterDecimal = _splitDecimal.afterDecimal,
hasNagation = _splitDecimal.hasNagation;
Expand All @@ -283,6 +284,34 @@
var decimalSeparator = shoudHaveDecimalSeparator ? '.' : '';
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
}
var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;
function getRidOfScientificNotation(value) {
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
return value;
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case


var number = parseFloat(value);

if (Math.abs(number) < 1.0) {
var e = parseInt(number.toString().split("e-")[1]);

if (e) {
number *= Math.pow(10, e - 1);
return "0." + new Array(e).join("0") + number.toString().substring(2);
}
} else {
var _e = parseInt(number.toString().split("+")[1]);

if (_e > 20) {
_e -= 20;
number /= Math.pow(10, _e);
return number + new Array(_e + 1).join("0");
}
}

return number.toString();
}
function omit(obj, keyMaps) {
var filteredObj = {};
Object.keys(obj).forEach(function (key) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-number-format.min.js

Large diffs are not rendered by default.

36 changes: 34 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.splitDecimal = splitDecimal;
exports.fixLeadingZero = fixLeadingZero;
exports.limitToScale = limitToScale;
exports.roundToPrecision = roundToPrecision;
exports.getRidOfScientificNotation = getRidOfScientificNotation;
exports.omit = omit;
exports.setCaretPosition = setCaretPosition;
exports.findChangedIndex = findChangedIndex;
Expand Down Expand Up @@ -112,9 +113,10 @@ function limitToScale(numStr, scale, fixedDecimalScale) {
function roundToPrecision(numStr, scale, fixedDecimalScale) {
//if number is empty don't do anything return empty string
if (['', '-'].indexOf(numStr) !== -1) return numStr;
var shoudHaveDecimalSeparator = numStr.indexOf('.') !== -1 && scale;
var normalizedNum = getRidOfScientificNotation(numStr);
var shoudHaveDecimalSeparator = normalizedNum.indexOf('.') !== -1 && scale;

var _splitDecimal = splitDecimal(numStr),
var _splitDecimal = splitDecimal(normalizedNum),
beforeDecimal = _splitDecimal.beforeDecimal,
afterDecimal = _splitDecimal.afterDecimal,
hasNagation = _splitDecimal.hasNagation;
Expand All @@ -133,6 +135,36 @@ function roundToPrecision(numStr, scale, fixedDecimalScale) {
return "".concat(negation).concat(intPart).concat(decimalSeparator).concat(decimalPart);
}

var SCIENTIFIC_NUMBER_REGEX = /\d+\.?\d*e[\+\-]?\d+/i;

function getRidOfScientificNotation(value) {
if (!SCIENTIFIC_NUMBER_REGEX.test(value)) {
return value;
} // This looks like a scientific notation. We will use parseFloat this time as this is not gonna be a limitation in this case


var number = parseFloat(value);

if (Math.abs(number) < 1.0) {
var e = parseInt(number.toString().split("e-")[1]);

if (e) {
number *= Math.pow(10, e - 1);
return "0." + new Array(e).join("0") + number.toString().substring(2);
}
} else {
var _e = parseInt(number.toString().split("+")[1]);

if (_e > 20) {
_e -= 20;
number /= Math.pow(10, _e);
return number + new Array(_e + 1).join("0");
}
}

return number.toString();
}

function omit(obj, keyMaps) {
var filteredObj = {};
Object.keys(obj).forEach(function (key) {
Expand Down

0 comments on commit 77ea545

Please sign in to comment.