{"_id":"string-math","_rev":"3-9a6845c6956ec33fb037a612b79b64c7","name":"string-math","description":"Evaluates the result of the String arithmetical expression","dist-tags":{"latest":"1.2.2"},"versions":{"1.0.0":{"name":"string-math","version":"1.0.0","description":"Evaluates the result of the String arithmetical expression","main":"string-math.js","scripts":{"test":"node tests/jasmine.conf.js"},"repository":{"type":"git","url":"git+https://github.com/devrafalko/string-math.git"},"keywords":["string","math","arithmetic","result","parse","evaluate","addition","sum","plus","division","subtraction","multiplication","add","divide","subtract","multiple","equation","sign","mark","symbol","mathematical"],"author":{"name":"Paweł Rafałko"},"license":"MIT","bugs":{"url":"https://github.com/devrafalko/string-math/issues"},"homepage":"https://github.com/devrafalko/string-math#readme","devDependencies":{"jasmine":"^2.9.0","jasmine-spec-reporter":"^4.2.1"},"gitHead":"4edf3503ba66ef30f3a3fdeffa78784c1335666e","_id":"string-math@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.1","_npmUser":{"name":"devrafalko","email":"dev.rafalko@gmail.com"},"dist":{"integrity":"sha512-oIjv6lWYZtUj+bnmgU/tRpw/9zGcOrDW90RuWqTmXlAhxwoqYspQbWbnyZV7wJUU8b2bFKSdUtnTotMEWaD9Ow==","shasum":"deca4c29dae6cf08ad5c351a9215e1d80a5a8d1f","tarball":"https://registry.npmjs.org/string-math/-/string-math-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG8mbscQXok+d4bSYDaZULIO1FcQhijhRFS6LHBow9bQAiEAtcym7faXKiuGY5Z+hqbNRG38VuoDVe0DUCteYn/LYkk="}]},"maintainers":[{"name":"devrafalko","email":"dev.rafalko@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/string-math-1.0.0.tgz_1517516477658_0.698805223684758"},"directories":{}},"1.2.1":{"name":"string-math","version":"1.2.1","description":"Evaluates the result of the String arithmetical expression","main":"string-math.js","scripts":{"test":"node tests/jasmine.conf.js"},"repository":{"type":"git","url":"git+https://github.com/devrafalko/string-math.git"},"keywords":["string","math","arithmetic","result","parse","evaluate","addition","sum","plus","division","subtraction","multiplication","add","divide","subtract","multiple","equation","sign","mark","symbol","mathematical"],"author":{"name":"Paweł Rafałko"},"license":"MIT","bugs":{"url":"https://github.com/devrafalko/string-math/issues"},"homepage":"https://github.com/devrafalko/string-math#readme","devDependencies":{"jasmine":"^2.9.0","jasmine-spec-reporter":"^4.2.1"},"gitHead":"92939239049126f9a57bef1f903204fd9cd6a2b3","_id":"string-math@1.2.1","_npmVersion":"5.6.0","_nodeVersion":"8.10.0","_npmUser":{"name":"devrafalko","email":"dev.rafalko@gmail.com"},"dist":{"integrity":"sha512-r5ouWjy+qzWW4UsKSa8Annd5w6n1Z+7LyN3NySTW5UDBG9oeM3aq2+IL7yy+XkCpQIaEK8AcDyIdwI2B2td5Aw==","shasum":"3abe7ce4225ee14f8ddf10037e7a44ab2aa79c1c","tarball":"https://registry.npmjs.org/string-math/-/string-math-1.2.1.tgz","fileCount":9,"unpackedSize":20302,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa7CFLCRA9TVsSAnZWagAAhl4QAIhG+4/DfhD8pvVQtzIu\ny0c/h0WC+5B2AADi2PbU50seH1nIDW7TNcvcVDxLoUf37ts2ieUQQdINvtoW\nsJsAX4cnrX3NQXWhuHtc22G0XU8cf4bKBxQyEdZCUA2Bopzt+wGVfbe+7Nfd\nNUgr6PWuIK8ARmX6hWxhiMZDIM9E44AIt1uK5Kf3BkiegS7CuBDIm5UhfbjK\nNXphKsjlwTDrrTzLkQpnIX+Ea+LKTQhLibcDPp/imYb8ea9YrLm0XxgYQ+EZ\nt04gkHHxeToPJ8wannsUXlQBMg/R/zbKQ9x14nuFwRRfif4xBPXRNM/6H5Xx\nteKVy212fYvzbyfKV+ei/sKTITnaHoInQFT7rQDKLvyW1BJX90KGSdysFMic\ns9fq7uWz28UQV3snjiJDpx4cGH10G75YdJhMbXktOCI6XUtBLr2VsyffS4qz\n9lT63xYgkazBGBYGcwA/L/gXIYxsg8ShGjF99hW24Z4xCOA+q7KC8kSYe7pY\nseqE/0q3n8ODMxopNTdrDPU16vu+qMmV7XulYMu0M6Nc075fchZm/tdpOYMI\nNUPXyKfAC5JGj0ERbkbSrRmjZbjLIL89tGkeuBMc2SzKvmeKmKRjEocGLDcU\nvQ559XsYU9WsOlNszz6JOJdbVx067WcRyusioCUpuPz6szqLUPdvVzAXOou/\nmAOp\r\n=X82r\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC9Bx762bPGUxGvDpaljONUqmNdeOc1ZTYYfijySCs9SAIhAMhSL8EyKaAdyA5K/EsVtwRRaNboq9xJmCt0lOqKcxX0"}]},"maintainers":[{"name":"devrafalko","email":"dev.rafalko@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/string-math_1.2.1_1525424457717_0.4046573460014653"},"_hasShrinkwrap":false},"1.2.2":{"name":"string-math","version":"1.2.2","description":"Evaluates the result of the String arithmetical expression","main":"string-math.js","scripts":{"test":"node tests/jasmine.conf.js"},"repository":{"type":"git","url":"git+https://github.com/devrafalko/string-math.git"},"keywords":["string","math","arithmetic","result","parse","evaluate","addition","sum","plus","division","subtraction","multiplication","add","divide","subtract","multiple","equation","sign","mark","symbol","mathematical"],"author":{"name":"Paweł Rafałko"},"license":"MIT","bugs":{"url":"https://github.com/devrafalko/string-math/issues"},"homepage":"https://github.com/devrafalko/string-math#readme","devDependencies":{"jasmine":"^3.6.1","jasmine-spec-reporter":"^5.0.2"},"gitHead":"a6e8c9f90dad8c624b7470433758cdb1312969f1","_id":"string-math@1.2.2","_nodeVersion":"12.16.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-rfRZpMZbIy+0pepaW8iDCR+iW+GONxyi0jXfdyW4MgpFATH/Vlz+d3vt8UMu/a1RjA9xiejBDFayvTXzs/ROTw==","shasum":"c6a9362fac81476092f6f920e5379df00313c1e3","tarball":"https://registry.npmjs.org/string-math/-/string-math-1.2.2.tgz","fileCount":9,"unpackedSize":20302,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfO4bzCRA9TVsSAnZWagAAZTIP/ipDX9iTdBehalUL8daB\nDReY121UGAqNI50/qEas8O3KtJxGX4mQWqQYVGHbYyTEYjODoNXpe/cmy7Rl\nHnK184Y5Yq0aivNzJmGgAWL83AzPw/DA/VXxw5njhbWi9MJfsCVTLG+6T4UR\nCefghamvV8JyDrO5eAjX0hqSrGkR0UzsCN97L9xWsEWPe39eGbh1/1crQ7nA\n140CCpG4qJISjnZPGeTBCr6zaxvo9va2rdTN9pOCURCDBblo1McoJWpoEGKw\nL5x0nULqUb0jXhGKZNrNwNiD1P44lP3yOXeJ2avxg+v43ZOZiekf6CRrbKqG\nb6k2WgCtfdW/u0ntJQGHBVsfmwGGi0gTwchvrrmBPW9iN2aNFj2E6D5Xt1uV\n2UDwhmBghlU8bFs52r5dLBeUW/JzZk4jJOMjAnBatoMJ70fw83daGBGloImS\nR2nWbYto2J0bOmMqIbdf4wf8fvpwQ84moIjuBZ2jacrgwMrrIFqU4ZwN8a3T\nEftAAw8A0Naj71DqJxrkRkayqGJzYghjdadGoknFXinupmlK8C/LOv6hGtBl\nIu6ZUecOX1mPcFB6PnIEBwBnOWvZ6y9lssXJNNTKkr6lr0olNhQ6rAVZjz+S\nRUbzLYej/gVKT5r3sKvIGyh/FpyWxNFYv5Ncln99QrK06b6YtCg1rishL/UW\n0EXd\r\n=eDcp\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDlxZ0B1AVOIshyRCrhKUodUwUh4/UMV2HW6jJ5iZNfaAiALQUC/qXoexUyUQhM04e+t5HtNKv+vAlKyF+pHklkJ5Q=="}]},"maintainers":[{"name":"devrafalko","email":"dev.rafalko@gmail.com"}],"_npmUser":{"name":"devrafalko","email":"dev.rafalko@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/string-math_1.2.2_1597736691111_0.24925800893479355"},"_hasShrinkwrap":false}},"readme":"# Description\r\n\r\n`string-math` is a module *(function)* that computes the `[Number]` result from the `[String]` arithmetical formula.\r\n* It **does not use** `eval()`\r\n* It uses regular expressions to parse [String] formulas `\"2+2\"` into [Number] formulas `2+2`. Then it is performed as the common JavaScript arithmetic operation.\r\n\r\n```javascript\r\n\"2 + 2\"  //4\r\n\"3*(5-2)\"  //9\r\n\" 2.5  *   2.5  /   .1\" //62.5\r\n\"3.5+5*(-4-(3/(3+1)-12*3-.2*22)-16/4*12-5/(2)+3.5+2.5*(1.5-2*7))-16\" //-225.5\r\n\".25e+2*10\" //250\r\n```\r\n\r\n* Any bugs found? Give me to know on [GitHub](https://github.com/devrafalko/string-math)\r\n* If you need to perform arithmetic formulas with the **floating point precision** *(avoid `0.30000000000000004` return values)* or to perform arithmetic formulas with **big numbers**, check out [**`exact-math`**](https://www.npmjs.com/package/exact-math) package. It implements `string-math` features as the `exactMath.formula` method.\r\n\r\n\r\n# Installation\r\n\r\n#### with NodeJS / bundlers\r\n\r\n`npm install string-math`\r\n\r\n```javascript\r\nvar stringMath = require('string-math');\r\n\r\nstringMath(\"--1\") //1\r\nstringMath(\"2/-2\") //-1\r\nstringMath(\"-5-5\") //-10\r\n```\r\n\r\n#### with Browser\r\n\r\n##### 1. Add string-math.js to the HTML file.\r\n```html\r\n<head>\r\n  <script src=\"./string-math.js\"></script>\r\n</head>\r\n```\r\n> Any other dependencies are needed.\r\n\r\n##### 2. Use `stringMath` **global Function** from `string-math.js`.\r\n```javascript\r\nvar result = stringMath(\"2+2\");\r\n```\r\n\r\n##### Browser Support\r\n|Chrome|Firefox|IE|Safari|Opera|\r\n:---:|:---:|:---:|:---:|:---:|\r\n|yes|yes|yes|yes|yes|\r\n\r\n# Tests\r\n```\r\n> git clone https://github.com/devrafalko/string-math.git\r\n> cd string-math\r\n> npm install\r\n> npm test\r\n> npm test deep //displays error messages\r\n```\r\n\r\n# Usage\r\n\r\n### `stringMath(expression[,callback])`\r\n##### `expression` **[String]**\r\n* the arithmetical formula\r\n* it can contain:\r\n  * `[0-9]` digits\r\n  * `1.5`, `0.5` or `.5` decimal fractions\r\n  * `-5`, `-.4`, `-5.55` negative values\r\n  * `2e-2`, `.25e+12`, `-3e-10` exponential notation values\r\n  * `*` multiplication sign\r\n  * `/` division sign\r\n  * `+` plus sign\r\n  * `-` subtraction sign\r\n  * `(` and `)` parentheses\r\n\r\n##### `callback` **[Function]** *(optional)* *(synchronous)*\r\n* by default, if the `callback` argument **is omitted** and the `expression` is of incorrect type or is invalid, the `Error` object is **`thrown`**. If the `callback` is defined, the `Error` object is passed through the `callback` function, rather than being **`thrown`**.\r\n* if the [Function] `callback` argument is defined, it is called with the following arguments:\r\n  * [0] `error`  \r\n    It equals `null`, if the `expression` is of correct type and is valid math formula.  \r\n    Otherwise it equals `Error` object.\r\n  * [1] `result`  \r\n    It equals `null` if the `expression` is of incorrect type or if the math formula is invalid.  \r\n    Otherwise it equals [Number] result.\r\n\r\n# Return\r\n\r\nIf the math formula is of correct type and is valid, it returns the [Number] result. Otherwise it returns `null`.\r\n\r\n# Tips\r\n* the arithmetic **order of operations** is respected:\r\n  * *parentheses first*\r\n  * *then division and multiplication (from left to right)*\r\n  * *then addition and subtraction (from left to right)*\r\n* the multiplication sign can be omitted before parentheses; `4(2+1)`; *equals to `4*(2+1)`*\r\n* the following signs combinations are allowed:\r\n  * `2 * -2`; *equals to `2 * (-2)`*\r\n  * `2 / -2`; *equals to `2 / (-2)`*\r\n  * `+2 + 2`; *equals to `2 + 2`*\r\n  * `2 + +2`; *equals to 2 + 2*\r\n  * `-2 - -2` *equals to `-2 + 2`*\r\n  * `-2 - +2` *equals to `-2 - 2`*\r\n  * `-2 + -2` *equals to `-2 - 2`*\r\n* the (multi)spaces between values, signs and parentheses are allowed:\r\n  * `2 + 2`\r\n  * `2 +  ( -2 - -2)`\r\n  * ` 2  +  (+2  +   +4   /   -1)`\r\n  * `  -.1   -   -5`\r\n  * `2 + 3e-5`\r\n  * `.25e+5 * -.25e-5`\r\n* the spaces are **not allowed** between:\r\n  * negative sign and value: `-2 - - 2`\r\n  * period and digit in decimal fraction: `5 + . 3`\r\n  * exponential notation formula: `.2 e-5`, `2e - 5`, `3e +10`","maintainers":[{"name":"devrafalko","email":"dev.rafalko@gmail.com"}],"time":{"modified":"2022-05-18T20:47:43.648Z","created":"2018-02-01T20:21:17.741Z","1.0.0":"2018-02-01T20:21:17.741Z","1.2.1":"2018-05-04T09:00:57.859Z","1.2.2":"2020-08-18T07:44:51.228Z"},"homepage":"https://github.com/devrafalko/string-math#readme","keywords":["string","math","arithmetic","result","parse","evaluate","addition","sum","plus","division","subtraction","multiplication","add","divide","subtract","multiple","equation","sign","mark","symbol","mathematical"],"repository":{"type":"git","url":"git+https://github.com/devrafalko/string-math.git"},"author":{"name":"Paweł Rafałko"},"bugs":{"url":"https://github.com/devrafalko/string-math/issues"},"license":"MIT","readmeFilename":"readme.md"}