Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multi-number-parse

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multi-number-parse - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

84

dist/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,16 @@ Object.defineProperty(exports, "__esModule", {

});
exports["default"] = void 0;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }

@@ -24,3 +33,3 @@

exports.default = function (number) {
var _default = function _default(number) {
var standardDecSep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.';

@@ -31,5 +40,5 @@

return number;
}
} // check validity of parameters
// check validity of parameters
if (!number || typeof number !== 'string') {

@@ -41,20 +50,15 @@ throw new TypeError('number must be a string');

throw new TypeError('standardDecSep must be a single character string');
}
} // check if negative
// check if negative
var negative = number[0] === '-';
// strip unnecessary chars
var stripped = number
// get rid of trailing non-numbers
.replace(/[^\d]+$/, '')
// get rid of the signal
.slice(negative ? 1 : 0);
var negative = number[0] === '-'; // strip unnecessary chars
// analyze separators
var stripped = number // get rid of trailing non-numbers
.replace(/[^\d]+$/, '') // get rid of the signal
.slice(negative ? 1 : 0); // analyze separators
var separators = (stripped.match(/[^\d]/g) || []).reduce(function (acc, sep, idx) {
var sepChr = 'str_' + sep.codePointAt(0);
var sepChr = "str_".concat(sep.codePointAt(0));
var cnt = ((acc[sepChr] || {}).cnt || 0) + 1;
return _extends({}, acc, _defineProperty({}, sepChr, {
return _objectSpread({}, acc, _defineProperty({}, sepChr, {
sep: sep,

@@ -64,5 +68,4 @@ cnt: cnt,

}));
}, {});
}, {}); // check correctness of separators
// check correctness of separators
var sepKeys = Object.keys(separators);

@@ -86,20 +89,18 @@

if (sep1.lastIdx > sep2.lastIdx) {
// swap
var _ref = [sep2, sep1];
// swap
sep1 = _ref[0];
sep2 = _ref[1];
}
} // if more than one separator appears more than once, that's wrong
// if more than one separator appears more than once, that's wrong
if (sep1.cnt > 1 && sep2.cnt > 1) {
return Number.NaN;
}
} // check if the last separator is the single one
// check if the last separator is the single one
if (sep2.cnt > 1) {
return Number.NaN;
}
} // check the groupings
// check the groupings

@@ -112,9 +113,9 @@ var _stripped$split = stripped.split(sep2.sep),

return Number.NaN;
}
} // ok, we got here! let's handle it
// ok, we got here! let's handle it
return parseFloat(stripped.split(sep1.sep).join('').replace(sep2.sep, '.')) * (negative ? -1 : 1);
}
} // ok, only one separator, which is nice
// ok, only one separator, which is nice
var sep = separators[sepKeys[0]];

@@ -127,9 +128,9 @@

return Number.NaN;
}
} // it's valid, let's return an integer
// it's valid, let's return an integer
return parseInt(stripped.split(sep.sep).join(''), 10) * (negative ? -1 : 1);
}
} // just one separator, let's check last group
// just one separator, let's check last group
var groups = stripped.split(sep.sep);

@@ -139,3 +140,2 @@

// ok, we're in ambiguous territory here
if (sep.sep !== standardDecSep) {

@@ -145,6 +145,8 @@ // it's an integer

}
}
} // well, it looks like it's a simple float
// well, it looks like it's a simple float
return parseFloat(stripped.replace(sep.sep, '.')) * (negative ? -1 : 1);
};
};
exports["default"] = _default;
{
"name": "multi-number-parse",
"version": "1.0.9",
"version": "1.0.10",
"description": "Library for parsing numbers in any valid format.",

@@ -8,6 +8,6 @@ "main": "./dist/index.js",

"clean": "rimraf dist",
"build": "npm run clean && babel src -d dist --presets env",
"build": "npm run clean && babel src -d dist --presets @babel/preset-env",
"lint": "eslint src test --fix",
"prepublishOnly": "npm run build",
"test": "npm run lint && mocha --recursive --exit --require babel-register"
"test": "npm run lint && mocha --recursive --exit --require @babel/register"
},

@@ -30,14 +30,15 @@ "keywords": [

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^10.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-eslint": "^10.0.2",
"chai": "^4.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1",
"eslint": "^6.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-import-resolver-node": "^0.3.2",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsx-a11y": "^6.2",
"eslint-plugin-react": "^7.13.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.2",
"mocha": "^6.1.4",

@@ -44,0 +45,0 @@ "rimraf": "^2.6.3"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc