Node modules
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
**/node_modules
|
||||
**/flow-typed
|
||||
**/flow-coverage
|
||||
**/out
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"prefer-const": "error"
|
||||
}
|
||||
},
|
||||
"eslintIgnore": ["**/out/*.js"],
|
||||
"flow-coverage-report": {
|
||||
"concurrentFiles": 1,
|
||||
"excludeGlob": ["node_modules/**"],
|
||||
|
||||
+7
-23
@@ -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,
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user