Node modules

This commit is contained in:
fkereki
2018-04-05 15:24:54 -03:00
parent d86802252a
commit 405fa03d1d
5 changed files with 50 additions and 23 deletions
+1
View File
@@ -1,3 +1,4 @@
**/node_modules
**/flow-typed
**/flow-coverage
**/out
+1
View File
@@ -37,6 +37,7 @@
"prefer-const": "error"
}
},
"eslintIgnore": ["**/out/*.js"],
"flow-coverage-report": {
"concurrentFiles": 1,
"excludeGlob": ["node_modules/**"],
+7 -23
View File
@@ -15,10 +15,7 @@
"author": "Federico Kereki",
"license": "ISC",
"babel": {
"presets": [
"env",
"flow"
]
"presets": ["env", "flow"]
},
"eslintConfig": {
"parserOptions": {
@@ -31,34 +28,21 @@
"node": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"plugins": [
"babel",
"flowtype"
],
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"plugins": ["babel", "flowtype"],
"rules": {
"no-console": "off",
"no-var": "error",
"prefer-const": "error"
}
},
"eslintIgnore": ["**/out/*.js"],
"flow-coverage-report": {
"concurrentFiles": 1,
"excludeGlob": [
"node_modules/**"
],
"includeGlob": [
"src/**/*.js"
],
"excludeGlob": ["node_modules/**"],
"includeGlob": ["src/**/*.js"],
"threshold": 90,
"type": [
"text",
"html",
"json"
]
"type": ["text", "html", "json"]
},
"prettier": {
"tabWidth": 4,
+11
View File
@@ -0,0 +1,11 @@
/* @flow */
"use strict";
const RM = require("./roundmath.js");
const { multR, divR } = require("./roundmath.js");
console.log(RM.addR(12.348, 4.221)); // 16.57
console.log(multR(22.9, 12.4)); // 283.96
console.log(divR(22, 7)); // 3.14
console.log(RM.changeSign(0.07)); // error; RM.changeSign is not a function
+30
View File
@@ -0,0 +1,30 @@
/* @flow */
"use strict";
const roundToCents = (x: number): number => Math.round(x * 100) / 100;
const changeSign = (x: number): number => -x;
const addR = (x: number, y: number): number => roundToCents(x + y);
const subR = (x: number, y: number) => addR(x, changeSign(y));
const multR = (x: number, y: number): number => roundToCents(x * y);
const divR = (x: number, y: number): number => {
if (y === 0) {
throw new Error("Divisor must be nonzero");
} else {
return roundToCents(x / y);
}
};
/*
NOTES:
1. Exports are all together, at the end, per convention
2. roundToCents and changeSign are not exported, on purpose
*/
exports.addR = addR;
exports.subR = subR;
exports.multR = multR;
exports.divR = divR;