typed-eval
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

typed-eval

Type-based calculation does right.

npm i typed-eval
import { add, sub, mul, divmod, calc } from 'typed-eval'

type P1 = add<114514, 1919810>
//   ^? type P1 = 2034324

const P2 = add(114514, -1919810)
//    ^? const P2 = -1805296

type S1 = sub<-114514, 1919810>
//   ^? type S1 = -2034324

const S2 = sub(-114514, -1919810)
//    ^? const S2 = 1805296

type M1 = mul<114, 514>
//   ^? type M1 = 58596

const M2 = mul(2000, 5000)
//    ^? type M2 = 10000000

type D1 = divmod<10, 3>
//   ^? type D1 = [3, 1]

const D2 = divmod(-514, 114)
//    ^? const D2 = [-4, -58]

type C1 = calc<'114 + 514 + 1919 + 810'>
//   ^? type E1: 3357

const C2 = calc('100 - (2 - 3 * 4) * 5')
//    ^? const E2: 150

Package Sidebar

Install

npm i typed-eval

Weekly Downloads

0

Version

2.1.0

License

MIT

Unpacked Size

4.04 kB

Total Files

6

Last publish

Collaborators

  • shigma