Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
string-math
Advanced tools
string-math
is a module (function) that computes the [Number]
result from the [String]
arithmetical formula.
eval()
"2+2"
into [Number] formulas 2+2
. Then it is performed as the common JavaScript arithmetic operation."2 + 2" //4
"3*(5-2)" //9
" 2.5 * 2.5 / .1" //62.5
"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
".25e+2*10" //250
0.30000000000000004
return values) or to perform arithmetic formulas with big numbers, check out exact-math
package. It implements string-math
features as the exactMath.formula
method.npm install string-math
var stringMath = require('string-math');
stringMath("--1") //1
stringMath("2/-2") //-1
stringMath("-5-5") //-10
<head>
<script src="./string-math.js"></script>
</head>
Any other dependencies are needed.
stringMath
global Function from string-math.js
.var result = stringMath("2+2");
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
yes | yes | yes | yes | yes |
> git clone https://github.com/devrafalko/string-math.git
> cd string-math
> npm install
> npm test
> npm test deep //displays error messages
stringMath(expression[,callback])
expression
[String][0-9]
digits1.5
, 0.5
or .5
decimal fractions-5
, -.4
, -5.55
negative values2e-2
, .25e+12
, -3e-10
exponential notation values*
multiplication sign/
division sign+
plus sign-
subtraction sign(
and )
parenthesescallback
[Function] (optional) (synchronous)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
.callback
argument is defined, it is called with the following arguments:
error
null
, if the expression
is of correct type and is valid math formula.Error
object.result
null
if the expression
is of incorrect type or if the math formula is invalid.If the math formula is of correct type and is valid, it returns the [Number] result. Otherwise it returns null
.
4(2+1)
; equals to 4*(2+1)
2 * -2
; equals to 2 * (-2)
2 / -2
; equals to 2 / (-2)
+2 + 2
; equals to 2 + 2
2 + +2
; equals to 2 + 2-2 - -2
equals to -2 + 2
-2 - +2
equals to -2 - 2
-2 + -2
equals to -2 - 2
2 + 2
2 + ( -2 - -2)
2 + (+2 + +4 / -1)
-.1 - -5
2 + 3e-5
.25e+5 * -.25e-5
-2 - - 2
5 + . 3
.2 e-5
, 2e - 5
, 3e +10
FAQs
Evaluates the result of the String arithmetical expression
The npm package string-math receives a total of 5,027 weekly downloads. As such, string-math popularity was classified as popular.
We found that string-math demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.