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

@algorithm.ts/calculate

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algorithm.ts/calculate

A tiny calculator for number arithmetics such as '+-*/()'

  • 2.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-94.44%
Maintainers
1
Weekly downloads
 
Created
Source

@algorithm.ts/calculate


A tiny calculator for number arithmetics such as +-*/().

Install

  • npm

    npm install --save @algorithm.ts/calculate
    
  • yarn

    yarn add @algorithm.ts/calculate
    
  • deno

    import calculate from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/calculate/src/index.ts'
    

Usage

// Perform integer arithmetics.
import calculate from 'algorithm.ts/calculate'
// or 
import { calculate } from 'algorithm.ts/calculate'

// Perform decimal arithmetics.
import { decimalCalculate } from 'algorithm.ts/calculate'

// Perform bigint arithmetics.
import { bigintCalculate } from 'algorithm.ts/calculate'

Examples

  • integer arithmetics

    import calculate from '@algorithm.ts/calculate'
    
    calculate('3/2')                  // => 1
    calculate('-2+1')                 // => -1
    calculate('-2*3 + 2*5*3/6')       // => -1
    calculate('(1+(4+5+2)-3)+(6+8)')  // => 23
    
  • decimal arithmetics

    import { decimalCalculate as calculate } from '@algorithm.ts/calculate'
    
    calculate('3/2')                  // => 1.5
    calculate('-2+1')                 // => -1
    calculate('-2*3 + 2*5*3/6')       // => -1
    calculate('(1+(4+5+2)-3)+(6+8)')  // => 23
    
  • bigint arithmetics

    import { bigintCalculate as calculate } from '@algorithm.ts/calculate'
    
    calculate('22222222222222222222222222222 * 3333333333333333333323232')
    // => 74074074074074074073849599999259259259259259259261504n
    
  • Illegal inputs

    import calculate from '@algorithm.ts/calculate'
    
    calculate('-2++1')      // => SyntaxError
    calculate('-2*/23')     // => SyntaxError
    calculate('1+(4+5+2))') // => SyntaxError
    calculate('1+(4+5+2')   // => SyntaxError
    
  • A solution of https://leetcode.com/problems/basic-calculator/

    export { calculate } from '@algorithm.ts/calculate'
    
  • A solution of https://leetcode.com/problems/basic-calculator-ii/

    export { calculate } from '@algorithm.ts/calculate'
    

Keywords

FAQs

Package last updated on 27 Aug 2022

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