‚̧Nomenclature Predictably Misunderstood
    Wondering what‚Äôs next for npm?Check out our public roadmap! ¬Ľ

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



    This package provides a simple calculator class and several "safe" mathematical operations, in which all undefined or infinite results are replaced with 0. It is a simple educational project using a range of fully-configured and integrated external tools.

    Github license Open issues Closed issues Open Pull Requests Closed Pull Requests Commit activity Github contributors Last commit

    Travis.CI build status Codecov Coverage Status Known Vulnerabilities Dependencies DevDependencies OptionalDependencies PeerDependencies Code Climate issues Code Climate maintainability Code Climate maintainability (percentage) Code Climate technical debt Code Climate coverage Code Climate coverage (letter)

    NPM license Known Vulnerabilities

    Actively maintained (2020) Chat on Gitter Blazing Fast Follow gfmio on Twitter code style: prettier All Contributors

    Commitizen friendly


    This is a simple educational project to set up and work with a variety of libraries and external tools. Among others, it uses:

    • ts-pkg-scripts build tools for compiling, bundling and packaging TypeScript libraries (uses gulp and rollup internally)
    • TypeScript for all source, test, and gulp task files
    • the mocha test framework, chai assertion library and istanbul code coverage tool with its nyc command line interface
    • Travis.CI for continuous integration (running tests and deploying new package versions)
    • CodeCov and Code Climate for monitoring code coverage and watching the codebase for code smells
    • semantic-release to release new versions of the package, when code gets pushed to the master branch and significant changes have occurred, and for generating the changelog
    • husky to run commit hooks
    • prettier for auto-formatting the source code (run as a pre-commit hook on all staged changes)
    • commitlint for ensuring that all commit messages follow the same format (run as a commit message hook)
    • commitizen for writing commit messages adhering to the required format. Instead of using git commit to push commits, you use yarn commit, which invokes commitizen.
    • Shields from shields.io for displaying a range of status info about the repository and package
    • David for monitoring if all dependencies are up to date
    • Snyk for monitoring the project for security vulnerabilities
    • Gitter as community chat
    • typedoc for generating documentation
    • gh-pages for pushing the documentation to Github pages. It is accessible at https://gfmio.github.io/example-calculator.
    • All Contributors for managing contributors

    The repository also features Github issue templates, a pull request template, a code of conduct and a contributing guideline.

    Explore some of the tools above and look at the configuration for each to see how they are used and start using them in your own projects, if they fit your needs.

    If you want to suggest changes or additions, find an error or that anything does not work or no longer works, please file an issue or submit a pull request with your suggested changes.


    Install the package from NPM:

    # If you use yarn 
    yarn add example-calculator
    # If you use NPM 
    npm install example-calculator

    You can also import the package bundle from unpkg by inserting the following script tag in your HTML code.

    <script src="https://unpkg.com/example-calculator/example-calculator.umd.min.js"></script>

    The module content will be available as the UMD global exampleCalculator.


    The package provides a calculator class.

    import Calculator from "example-calculator";
    const calculator = new Calculator();

    You can supply an initial value to the calculator as an argument to its constructor (by default 0).

    const calculator2 = new Calculator(2);

    The current value of the calculator can be accessed using the value() method.

    // Prints 0
    // Prints 2

    clear() resets the value in the memory of the calculator to 0. All operations of the calculator, apart from value() return the instance, so operations can be chained.

    // Prints 0

    The calculator provides a range of simple mathematical operations, which perform an operation on the value in memory.

    // Adds 2 to the current value in memory
    // Subtracts 1 from the current value in memory
    // Multiplies the current value in memory with 2
    // Divides the current value in memory by 2
    // Sets the value in memory to the modulus (remainder) of the current value and 3
    // Sets the value in memory to the exponentiated current value
    // Sets the value in memory to the natural logarithm of the current value
    // Sets the value in memory to sine of the current value
    // Sets the value in memory to cosine of the current value
    // Sets the value in memory to tangent of the current value
    // Sets the value to the inverse (1/x) of the current value

    Some mathematical operations are not defined for all values, such as division by 0 or the logarithm of a negative number or 0. In all of these circumstances, the return values are 0.

    // Returns 0
    // Returns 0
    // Returns 0
    // Returns 0

    You can also import some operations as standalone functions from their submodules:

    import add from "example-calculator/add";
    import sub from "example-calculator/sub";
    import mul from "example-calculator/mul";
    import div from "example-calculator/div";
    import mod from "example-calculator/mod";
    import ln from "example-calculator/ln";
    console.log(add(1, 1));
    // Prints 2
    console.log(sub(1, 1));
    // Prints 0
    console.log(mul(2, 2));
    // Prints 4
    console.log(div(6, 3));
    // Prints 2
    console.log(mod(6, 4));
    // Prints 2
    // Prints 0


    Please read CODE_OF_CODUCT.md for details on our code of conduct and CONTRIBUTING.md for all details on how to contribute to this project (with code or otherwise) and the process for submitting pull requests to us.


    We use SemVer for versioning. Releases are generated using semantic-release. For the versions available, see the tags on this repository.


    This project is licensed under the MIT License - see the LICENSE file for details.



    • Fr√©d√©rique Mittelstaedt (@gfmio) - Initial work

    See also the list of contributors who participated in this project.


    Thanks goes to these wonderful people (emoji key):

    Frédérique Mittelstaedt
    Frédérique Mittelstaedt

    ūüďĖ ‚ö†ÔłŹ ūüíĽ

    This project follows the all-contributors specification. Contributions of any kind welcome!


    npm i example-calculator

    DownloadsWeekly Downloads






    Unpacked Size

    49.1 kB

    Total Files


    Last publish


    • avatar