Skip to content

Commit

Permalink
feat: start using esbuild, drop commitizen
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed May 11, 2021
1 parent d8baf5b commit 1fab45b
Show file tree
Hide file tree
Showing 36 changed files with 347 additions and 2,990 deletions.
44 changes: 15 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,36 @@
"types": "dist/index.d.ts",
"source": "src/index.ts",
"devDependencies": {
"@types/jest": "26.0.19",
"@types/node": "14.14.16",
"@types/numeral": "0.0.28",
"@typescript-eslint/eslint-plugin": "4.11.1",
"@typescript-eslint/parser": "4.11.1",
"commitizen": "4.2.2",
"cz-conventional-changelog": "3.3.0",
"eslint": "7.16.0",
"eslint-config-airbnb-typescript": "12.0.0",
"eslint-config-prettier": "7.1.0",
"@types/jest": "26.0.23",
"@types/node": "15.0.2",
"@typescript-eslint/eslint-plugin": "4.23.0",
"@typescript-eslint/parser": "4.23.0",
"esbuild": "^0.11.20",
"eslint": "7.26.0",
"eslint-config-airbnb-typescript": "12.3.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.1.3",
"husky": "4.3.6",
"eslint-plugin-jest": "24.3.6",
"jest": "26.6.3",
"microbundle": "0.13.0",
"prettier": "2.2.1",
"prettier": "2.3.0",
"pretty-quick": "3.1.0",
"rimraf": "3.0.2",
"ts-jest": "26.4.4",
"typescript": "4.1.3"
"ts-jest": "26.5.6",
"typescript": "4.2.4"
},
"scripts": {
"build": "microbundle --target node --sourcemap false --format cjs,modern --tsconfig tsconfig.build.json",
"build": "bash scripts/build.sh",
"ci:test": "LANG=en-GB jest --ci",
"ci:test:coverage": "LANG=en-GB jest --ci --coverage",
"lint": "eslint src --ext ts",
"test": "LANG=en-GB jest --watch",
"ts-check": "tsc --noEmit"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"release": {
"branches": [
"main"
]
},
"husky": {
"hooks": {
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
"pre-commit": "pretty-quick --staged"
}
},
"jest": {
"roots": [
"<rootDir>/src"
Expand Down Expand Up @@ -95,7 +80,8 @@
},
"rules": {
"jest/no-hooks": "off",
"@typescript-eslint/comma-dangle": "off"
"@typescript-eslint/comma-dangle": "off",
"jest/no-identical-title": "off"
},
"overrides": [
{
Expand Down
6 changes: 6 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

rimraf dist
tsc --build tsconfig.build.json
esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js
esbuild src/index.ts --bundle --outfile=dist/index.modern.js
1 change: 1 addition & 0 deletions src/formats/ordinal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('formats ordinals', () => {
['0o', 1, '1', 'en-GB', '1st'],
['0o', 2, '2', 'en-GB', '2nd'],
])('ordinals - %s', (format, value, formatted, locale, expected) => {
expect.assertions(1);
const result = formatOrdinal({ value, formatted, locale, format });
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/formats/percentage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('percentage', () => {
])(
'percentage: %s = %s',
(format, expected, value, minimumFractionDigits) => {
expect.assertions(1);
const nf = new Intl.NumberFormat('en-GB', {
style: 'percent',
minimumFractionDigits,
Expand Down
1 change: 1 addition & 0 deletions src/helpers/convert-to-number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('convert to number', () => {
['1234', 1234],
[1234, 1234],
])('converts from user input to number', (userInput, expected) => {
expect.assertions(1);
const result = convertToNumber(userInput);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/helpers/digits-format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('digits format', () => {
['0,0', '0,000'],
['0,000[.]00', '0,000[.]00'],
])('digits format: %s = %s', (format, expected) => {
expect.assertions(1);
const result = getDigitsFormat(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/helpers/fraction-digits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('fraction digits', () => {
['0.00[0]', [2, 1]],
['0.0[00]', [1, 2]],
])('gets fraction digits on format - %s', (format, expected) => {
expect.assertions(1);
const result = getFractionDigits(format);
expect(result).toStrictEqual(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/helpers/from-parts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('from parts', () => {
{ integer: ['2', '000'], group: ',' },
],
])('converts from parts to object - %s', (_, parts, expected) => {
expect.assertions(1);
const result = fromParts(parts as Intl.NumberFormatPart[]);
expect(result).toStrictEqual(expected);
});
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/regex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('operational regular expressions', () => {
['0,0[.]0[0]', '0,0[.]0[0]'],
['0.0a', '0.0'],
])('extracts digits format - %s', (format, expected) => {
expect.assertions(1);
const [, result] = format.match(rgDigitsFormat) || [''];
expect(result).toBe(expected);
});
Expand All @@ -17,6 +18,7 @@ describe('operational regular expressions', () => {
['0.000a', true],
['0.000A', true],
])('compact display - %s', (format, expected) => {
expect.assertions(1);
const result = rgIsCompact.test(format);
expect(result).toBe(expected);
});
Expand All @@ -29,6 +31,7 @@ describe('operational regular expressions', () => {
['USDs', 'USDs'],
['EURn', 'EURn'],
])('extracts currency format - %s', (format, expected) => {
expect.assertions(1);
const [, result] = format.match(rgCurrencyFormat) || [''];
expect(result).toBe(expected);
});
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/value.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('calculates value based on format', () => {
['0b', 1, 1048576],
['0b', 1, 1073741824],
])('value: %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = getValue(value, format);
expect(result).toBe(expected);
});
Expand All @@ -24,6 +25,7 @@ describe('calculates value based on format', () => {
['kilometer', 1000, 1],
['kilometer', 1200, 1.2],
])('get metric value: %s - %s', (_, value, expected) => {
expect.assertions(1);
const result = getMetricValue(value);
expect(result).toBe(expected);
});
Expand All @@ -36,6 +38,7 @@ describe('calculates value based on format', () => {
[1048576, 1],
[1278541824, 1.19073486328125],
])('get compact powers of two: %s', (value, expected) => {
expect.assertions(1);
const result = getCompactPowersOfTwo(value);
expect(result).toBe(expected);
});
Expand Down
3 changes: 2 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numberfmt from '.';

describe('numberfmt', () => {
it('has default foramt', () => {
it('has default format', () => {
expect.assertions(1);
const result = numberfmt(123456);
const expected = '123,456';
Expand All @@ -19,6 +19,7 @@ describe('numberfmt', () => {
['1234', '1,234'],
[1234, '1,234'],
])('handles non numeric values: %s', (value, expected) => {
expect.assertions(1);
const result = numberfmt(value, '0,0');
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/compact-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('compact display', () => {
['0.0a', 'short'],
['0.0A', 'long'],
])('compact display: %s', (format, expected) => {
expect.assertions(1);
const result = getCompactDisplay(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/currency-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('currency display', () => {
['0GBPc', 'code'],
['0GBPn', 'name'],
])('compact display - %s', (format, expected) => {
expect.assertions(1);
const result = getCurrencyDisplay(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/currency-sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('currency sign', () => {
['0.0', 'standard'],
['(0.0)', 'accounting'],
])('currency sign: %s = %s', (format, expected) => {
expect.assertions(1);
const result = getCurrencySign(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/currency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('currency', () => {
['0GBPn', 'GBP'],
['0EUR', 'EUR'],
])('currency: %s = %s', (format, expected) => {
expect.assertions(1);
const result = getCurrency(format);
expect(result).toBe(expected);
});
Expand Down
2 changes: 2 additions & 0 deletions src/options/maximum-fraction-digits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('maximum fraction digits', () => {
['0[.]00[0]', 1.23, 3],
['0[.]00[0]', 1.234, 3],
])('gets maximum fraction digits - %s', (format, value, expected) => {
expect.assertions(1);
const result = getMaximumFractionDigits(value, format);
expect(result).toBe(expected);
});
Expand All @@ -20,6 +21,7 @@ describe('maximum fraction digits', () => {
['0B', 1200, 2],
['0m', 1200, 2],
])('fraction digits on unit systems: %s', (format, value, expected) => {
expect.assertions(1);
const result = getMaximumFractionDigits(value, format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/minimum-fraction-digits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('minimum fraction digits', () => {
['0[.]0[0]', 1.23, 2],
['0[.]00[0]', 1.234, 3],
])('gets minimum fraction digits - %s', (format, value, expected) => {
expect.assertions(1);
const result = getMinimumFractionDigits(value, format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/minimum-integer-digits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('integer digits configuration', () => {
['0e', undefined, 1000],
['0E', undefined, 1000],
])('gets minimum integer digits: %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = getMinimumIntegerDigits(value, format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/notation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('notation', () => {
['0.0E', 'engineering'],
['(0.0E)', 'engineering'],
])('notation: %s = %s', (format, expected) => {
expect.assertions(1);
const result = getNotation(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/sign-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('format sign display', () => {
['-0,0.0', 'auto'],
['(0,0.0)', 'never'],
])('sign display: %s = %s', (format, expected) => {
expect.assertions(1);
const result = getSignDisplay(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('get style', () => {
['0.0GBPn', 'currency'],
['0.0%', 'percent'],
])('style: $s = $s', (format, expected) => {
expect.assertions(1);
const result = getStyle(format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/options/unit-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('unit display', () => {
['0 k', 'short'],
['0k', 'narrow'],
])('unit display: % = %s', (format, expected) => {
expect.assertions(1);
const result = getUnitDisplay(format);
expect(result).toBe(expected);
});
Expand Down
4 changes: 4 additions & 0 deletions src/options/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('get unit', () => {
['gigabit', 1024 * 1024 * 1024],
['terabit', 1024 * 1024 * 1024 * 1024],
])('unit for power of twos (bits): %s - %s', (expected, value) => {
expect.assertions(1);
const result = getUnitFromPowerOfTwo(value, [
'bit',
'kilobit',
Expand All @@ -30,6 +31,7 @@ describe('get unit', () => {
['terabyte', 1024 * 1024 * 1024 * 1024],
['petabyte', 1024 * 1024 * 1024 * 1024 * 1024],
])('unit for power of twos (bits): %s - %s', (expected, value) => {
expect.assertions(1);
const result = getUnitFromPowerOfTwo(value, [
'byte',
'kilobyte',
Expand All @@ -47,6 +49,7 @@ describe('get unit', () => {
['meter', 1],
['kilometer', 1000],
])('metric value: %s - %s', (expected, value) => {
expect.assertions(1);
const result = getMetricUnit(value);
expect(result).toBe(expected);
});
Expand All @@ -57,6 +60,7 @@ describe('get unit', () => {
['0B', 'byte', 1],
['0B', 'kilobyte', 1024],
])('unit: %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = getUnit(value, format);
expect(result).toBe(expected);
});
Expand Down
2 changes: 2 additions & 0 deletions src/tests/compact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('compact notation', () => {
['0.000a', '1.235M', 1234567],
['0.000a', '1.235M', 1234567],
])('short format: %s, %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand All @@ -42,6 +43,7 @@ describe('compact notation', () => {
['0.0A', '1.2 million', 1234567],
['0.00A', '1.23 million', 1234567],
])('long format: %s, %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand Down
1 change: 1 addition & 0 deletions src/tests/compound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('compound format', () => {
['(0m)', '(1.23km)', -1234],
['(0.000m)', '(1.234km)', -1234],
])('compounds: %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand Down
5 changes: 5 additions & 0 deletions src/tests/currency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('currency', () => {
['0,0CAD', 'CA$1,000', 1000],
['0,0GBP', '£123,456', 123456],
])('currency (symbol): %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand All @@ -21,6 +22,7 @@ describe('currency', () => {
['0,0JPYs', '¥1,000', 1000],
['0,0CADs', '$1,000', 1000],
])('currency (narrow symbol): %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand All @@ -32,6 +34,7 @@ describe('currency', () => {
['0,0JPYc', 'JPY 1,000', 1000],
['0,0CADc', 'CAD 1,000', 1000],
])('currency (code): %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand All @@ -48,6 +51,7 @@ describe('currency', () => {
['0,0JPYn', '1,000 Japanese yen', 1000],
['0,0CADn', '1,000 Canadian dollars', 1000],
])('currency (name): %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand All @@ -58,6 +62,7 @@ describe('currency', () => {
['0,0GBPca', 'GBP 1M', 1234567],
['0,0GBPna', '1M British pounds', 1234567],
])('currency: %s = %s', (format, expected, value) => {
expect.assertions(1);
const result = numberfmt(value, format);
expect(result).toBe(expected);
});
Expand Down
Loading

0 comments on commit 1fab45b

Please sign in to comment.