- Make a new project directory:
$ mkdir easyCalc
- Check login in npmjs.com:
$ npm login
- Iniciate a new npm project:
$ cd easyCalc
$ npm init -f
- Lastly, install 'myeasycalc' package:
$ npm install myeasycalc
After a clean instalation, these are the files should came up:
package-lock.json
package.json
node_modules:
package-lock.json
myeasycalc:
easyCalc.js
easyCalc.ts
package.json
readme.md
test.js
test.ts
virtualCalc.js
virtualCalc.ts
-
EasyCalc class.First, import the class in order to use it:
import { EasyCalc } from './node_modules/myeasycalc/easyCalc'
The class contains four methods (sum, rest, multiplication and division),wich are ready to apply basic aritmetic operations. All of them are listenfor an (optional) argument, in form of array of numbers, to operate with andas return, a calculated number is obtained.
If no argument is passed at the invocation moment, these methodswill be delivering a result anyway operating from two random numbers.console.log(myObjetCalc.suma());
It is posible invoque these methods with or without an instancefrom the class.console.log(new EasyCalc().resta([3,2]));
console.log(EasyCalc.resta([3, 2]));
There are Get and Set methods to call or update every attributeinto the class.
The last method is used to erease all value in every attributeand initialice them with value 0.myObjetCalc.reset();
-
VirtualCalc class.First, import the class in order to use it:
import { VirtualCalc } from './node_modules/myeasycalc/virtualCalc'
This class has only one method: pint() An argument EasyCalc objetmust be provide and as return, the class deliver every calculationresults in a calculator simulation skin.myVirtualCalc(myObjetCalc);
The file 'test.ts' includes a full display of examples using
both classes and all their methods and attributes.