@johnrob1880/string-calc

1.0.2 • Public • Published

string-calc

Utililty function to calculate literal strings.

Perform addition, subtraction, multiplication, and division on numbers.

let str = '1+2'
console.log(stringCalc(str)) // 3

str = '3-2';
console.log(stringCalc(str)) // 1

str = '2*2'
console.log(stringCalc(str)) // 4

str = '8/2'
console.log(stringCalc(str)) // 4

Add days to a date

// expects date format to be YYYYMMDD.
let str = '20180101d+10';
console.log(stringCalc(str)) // 20180121

Subtract days from a date

// expects date format to be YYYYMMDD.
let str = '20180131d-30';
console.log(stringCalc(str)) // 20180101

License

MIT.

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i @johnrob1880/string-calc

    Weekly Downloads

    2

    Version

    1.0.2

    License

    none

    Unpacked Size

    6.85 kB

    Total Files

    6

    Last publish

    Collaborators

    • johnrob1880