Skip to content

Commit f231616

Browse files
authored
v2.1.1 (#12)
* Update style guide (#11)
1 parent 20f200f commit f231616

6 files changed

Lines changed: 356 additions & 62 deletions

File tree

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arrowParens": "avoid",
3+
"printWidth": 100,
4+
"singleQuote": true,
5+
"trailingComma": "all"
6+
}

__tests__/arithmetic.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('Arithmetic', () => {
103103

104104
describe('max function', () => {
105105
const { max } = Math;
106+
106107
it('should handle max with no arguments', () => {
107108
const result = runArithmetic('max()');
108109
expect(result).toEqual(-Infinity);

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beyondessential/arithmetic",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Utility to evaluate BODMAS arithmetic formulas",
55
"keywords": [
66
"arithmetic",
@@ -23,6 +23,8 @@
2323
"scripts": {
2424
"build": "babel src --out-dir dist --ignore 'src/__tests__/**'",
2525
"postinstall": "yarn build",
26+
"lint": "eslint --ignore-path .gitignore .",
27+
"lint:fix": "yarn lint --fix",
2628
"test": "NODE_ENV=test jest",
2729
"test:coverage": "yarn test --coverage",
2830
"test:watch": "yarn test --watch"
@@ -35,21 +37,17 @@
3537
]
3638
},
3739
"eslintConfig": {
38-
"extends": "@beyondessential/eslint-config-beyondessential",
39-
"overrides": [
40-
{
41-
"files": "**/__tests__/**",
42-
"env": {
43-
"jest": true
44-
}
45-
}
40+
"extends": [
41+
"@beyondessential/js",
42+
"@beyondessential/jest"
4643
]
4744
},
4845
"devDependencies": {
4946
"@babel/cli": "^7.10.5",
5047
"@babel/core": "^7.11.1",
5148
"@babel/preset-env": "^7.11.0",
52-
"@beyondessential/eslint-config-beyondessential": "^2.5.0",
49+
"@beyondessential/eslint-config-jest": "^1.0.1",
50+
"@beyondessential/eslint-config-js": "^1.0.1",
5351
"babel-jest": "^26.3.0",
5452
"eslint": "^7.7.0",
5553
"jest": "^26.4.0",

src/arithmetic.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
// that, don't sweat! There're unit tests and you can validate that things
2323
// work over there.
2424

25-
import {
26-
isOperator, getPrecedence, FUNCTION_NAMES, isFunctionToken,
27-
} from './symbols';
25+
import { isOperator, getPrecedence, FUNCTION_NAMES, isFunctionToken } from './symbols';
2826

2927
const unaryRegex = /(^|[*x/+\-u,(])-/g;
3028
function replaceUnaryMinus(text) {
@@ -160,7 +158,7 @@ const noWhitespace = /\s/g;
160158
// Names with a '(' after them are function calls, not variables
161159
// e.g. max(5 + max)
162160
// the first max would not be replaced
163-
const buildVariableReplacer = (key) => new RegExp(`${key}(?!\\s*\\()`, 'g');
161+
const buildVariableReplacer = key => new RegExp(`${key}(?!\\s*\\()`, 'g');
164162

165163
export function runArithmetic(formulaText, values = {}) {
166164
// first replace variables with their actual values

src/symbols.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
export const FUNCTION_NAMES = ['max'];
99

10-
export const isFunctionToken = (token) => FUNCTION_NAMES.includes(token);
10+
export const isFunctionToken = token => FUNCTION_NAMES.includes(token);
1111

1212
export function isOperator(token) {
1313
return ['+', '-', '/', '*', 'x', 'u'].includes(token) || isFunctionToken(token);
@@ -38,7 +38,7 @@ export function getVariables(formulaText) {
3838
// Replace functions with a non-alphanumeric character
3939
.replace(new RegExp(`${FUNCTION_NAMES.join('|')}\\s*\\(`, 'g'), ' ')
4040
.split(/[+-/*() ]/g)
41-
.filter((v) => v !== '' && Number.isNaN(Number(v)));
41+
.filter(v => v !== '' && Number.isNaN(Number(v)));
4242

4343
return [...new Set(variables)];
4444
}

0 commit comments

Comments
 (0)