npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

example-calculator

v0.7.2

Published

A simple calculator package developed as an exemplary, educational project using a range of libraries and external tools

Downloads

44

Readme

example-calculator

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.

Commitizen friendly

Why

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

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.

Usage

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.

console.log(calculator.value());
// Prints 0
console.log(calculator2.value());
// 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.

console.log(calculator2.clear().value());
// 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
calculator.add(2);
// Subtracts 1 from the current value in memory
calculator.sub(1);
// Multiplies the current value in memory with 2
calculator.mul(2);
// Divides the current value in memory by 2
calculator.div(2);
// Sets the value in memory to the modulus (remainder) of the current value and 3
calculator.mod(3);
// Sets the value in memory to the exponentiated current value
calculator.exp();
// Sets the value in memory to the natural logarithm of the current value
calculator.ln();
// Sets the value in memory to sine of the current value
calculator.sin();
// Sets the value in memory to cosine of the current value
calculator.cos();
// Sets the value in memory to tangent of the current value
calculator.tan();
// Sets the value to the inverse (1/x) of the current value
calculator.inverse();

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.

calculator.clear().add(1).div(0).value();
// Returns 0
calculator.clear().add(1).mod(0).value();
// Returns 0
calculator.clear().sub(1).ln().value();
// Returns 0
calculator.clear().inverse().value();
// 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
console.log(ln(1));
// Prints 0

Contributing

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.

Versioning

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

License

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

Acknowledgments

Authors

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

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

Contributors

Thanks goes to these wonderful people (emoji key):

| Frédérique Mittelstaedt📖 ⚠️ 💻 | | :---: |

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