
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
[](https://github.com/dqn/calc-ts/actions) [](https://www.npmjs.com/package/calc-ts)
Type-level calculator.
Using npm:
$ npm install calc-ts
Using yarn:
$ yarn add calc-ts
import type { Calculate } from "calc-ts";
type Result1 = Calculate<"1 + 2">; // 3
type Result2 = Calculate<"1+2+3-4">; // 2
type Result3 = Calculate<"2 * (7 + (8))">; // 30
type Result4 = Calculate<"5 - / 9">; // never
const num1: Calculate<"1 + 4"> = 5; // OK
const num2: Calculate<"1 + 4"> = 6; // Type '6' is not assignable to type '5'.ts(2322)
type ValidExpr<S extends string> = Calculate<S> extends never ? never : S;
function safeEval<S extends string>(expr: ValidExpr<S>): Calculate<S> {
return eval(expr);
}
const result1 = safeEval("12 + 3"); // 15
const result2 = safeEval("12 = 3"); // Argument of type 'string' is not assignable to parameter of type 'never'. ts(2345)
declare const expr: string;
const result3 = safeEval(expr); // Argument of type 'string' is not assignable to parameter of type 'never'. ts(2345)
MIT
FAQs
[](https://github.com/dqn/calc-ts/actions) [](https://www.npmjs.com/package/calc-ts)
The npm package calc-ts receives a total of 0 weekly downloads. As such, calc-ts popularity was classified as not popular.
We found that calc-ts 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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.