Skip to content

Repository files navigation

Calculator

用 TypeScript 寫成的簡單計算機。

使用方式

import{Calculator}from"@hizollo/calculator";constcalculator=newCalculator();constformula='1 + 2 * 3';constresult=calculator.calculate(formula);console.log(result);// 7

支援語法

文件

錯誤系統

class CalcError extends Error

  • 額外屬性
    • codeErrorCodes):錯誤代碼
    • typeErrorTypes):錯誤類別
    • positionnumber):出錯位置
    • argsunknown[]):出錯參數

使用範例

import{Calculator,CalcError,ErrorCodes}from"@hizollo/calculator";constcalculator=newCalculator();constformula='random thing';try{constresult=calculator.calculate(formula);console.log(result);}catch(e){consterror=easCalcError<ErrorCodes>;console.log(`${error.message}\nAt: ${error.position}`);}

About

用 TypeScript 寫成的簡單計算機。

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages