New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

calculate-string

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculate-string

Parses a string containing mathematical operators to a number

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
increased by371.32%
Maintainers
1
Weekly downloads
 
Created
Source

Calculate String

Patreon David Travis CI GitHub package.json version RunKit RunKit

Parses strings containing mathematical operations.

Table of Contents

Introduction

Why?

So you can parse a string without using unsafe evals nor have to spend a detour creating a parser.

Installation

With npm:

$ npm install calculate-string

With yarn:

$ yarn add calculate-string

Usage

Try me on RunKit

const calculateString = require('calculate-string')

calculateString('1,000 + 1,000') // String: '2000'
calculateString('(100 + 10) / 10') // String: '11'
BigInt(calculateString('2 ** 64')) // BigInt: 18,446,744,073,709,551,616
BigInt(calculateString('NaN')) // SyntaxError: Cannot convert NaN to a BigInt
Number(calculateString('1e+6 ^ -1e+6')) // Number: -Infinity
calculateString("this won't get parsed")) == 'NaN' // Boolean: true
calculateString('1,000,000 ^ 10') // String: '1e+60'
Number(calculateString('1,000,000 ^ 10')) // Number: 1e+60
<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/calculate-string/index.min.js"></script>
  </head>
  <body>
    <p id="result"></p>
    <script>
      document.getElementById("result").innerHTML = calculateString(
        "100 + 100"
      );
    </script>
  </body>
</html>

Keywords

FAQs

Package last updated on 12 Aug 2021

Did you know?

Socket

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.

Install

Related posts

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