Skip to content

Commit

Permalink
fix: update deps, security fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruicsh committed Jan 8, 2023
1 parent a983ae8 commit 465d58f
Show file tree
Hide file tree
Showing 64 changed files with 1,718 additions and 1,469 deletions.
41 changes: 41 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"extends": [
"airbnb-base",
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"plugin:jest/all"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
],
"parserOptions": {
"ecmaVersion": 9,
"project": "./tsconfig.json"
},
"env": {
"node": true,
"jest": true
},
"rules": {
"@typescript-eslint/comma-dangle": "off",
"import/prefer-default-export": "off",
"jest/no-conditional-in-test": "off",
"jest/no-hooks": "off",
"jest/no-identical-title": "off",
"jest/prefer-expect-assertions": "off"
},
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"no-undef": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
yarn install --frozen-lockfile
yarn build
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@main
with:
branch: main
env:
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"printWidth": 80,
"useTabs": true
}
7 changes: 7 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"roots": ["<rootDir>/src"],
"testEnvironment": "node",
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
}
}
81 changes: 13 additions & 68 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,87 +30,32 @@
"dist/numberfmt.d.ts"
],
"devDependencies": {
"@types/jest": "29.2.0",
"@types/node": "18.11.7",
"@typescript-eslint/eslint-plugin": "5.41.0",
"@typescript-eslint/parser": "5.41.0",
"esbuild": "0.15.12",
"eslint": "8.26.0",
"@types/jest": "29.2.5",
"@types/node": "18.11.18",
"@typescript-eslint/eslint-plugin": "5.48.0",
"@typescript-eslint/parser": "5.48.0",
"esbuild": "0.16.15",
"eslint": "8.31.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.1.3",
"jest": "29.2.2",
"eslint-plugin-jest": "27.2.1",
"jest": "29.3.1",
"nyc": "15.1.0",
"prettier": "2.7.1",
"prettier": "2.8.2",
"ts-jest": "29.0.3",
"tsx": "3.11.0",
"typescript": "4.8.4",
"tsx": "3.12.1",
"typescript": "4.9.4",
"zx": "7.1.1"
},
"scripts": {
"build": "tsx sh/build.ts",
"coverage": "tsx sh/coverage.ts",
"format": "prettier --write src sh",
"lint:ts": "tsc --noEmit",
"lint": "eslint src --ext ts",
"test:ci": "LANG=en-GB jest --ci",
"test": "LANG=en-GB jest --watch"
},
"jest": {
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
}
},
"eslintConfig": {
"extends": [
"airbnb-base",
"airbnb-typescript/base",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"plugin:jest/all"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
],
"parserOptions": {
"ecmaVersion": 9,
"project": "./tsconfig.json"
},
"env": {
"node": true,
"jest": true
},
"rules": {
"@typescript-eslint/comma-dangle": "off",
"import/prefer-default-export": "off",
"jest/no-conditional-in-test": "off",
"jest/no-hooks": "off",
"jest/no-identical-title": "off",
"jest/prefer-expect-assertions": "off"
},
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"no-undef": "off"
}
}
]
},
"prettier": {
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 80,
"useTabs": true
}
}
10 changes: 5 additions & 5 deletions sh/build.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'zx/globals';
import "zx/globals";

async function main() {
await $`rm -rf dist`;
await $`tsc --build tsconfig.build.json`;

const modes = ['cjs', 'esm'];
const modes = ["cjs", "esm"];
for await (const mode of modes) {
const flags = [
'src/index.ts',
'--bundle',
"src/index.ts",
"--bundle",
`--format=${mode}`,
'--minify',
"--minify",
`--outfile=dist/index.${mode}.js`,
];
await $`esbuild ${flags}`;
Expand Down
2 changes: 1 addition & 1 deletion sh/coverage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'zx/globals';
import "zx/globals";

async function main() {
await $`rm -rf ./node_modules/.cache`;
Expand Down
16 changes: 8 additions & 8 deletions src/bug-reports.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import nf from './index';
import nf from "./index";

describe('bug reports', () => {
it('shows mismatched values between nodejs and browser', () => {
describe("bug reports", () => {
it("shows mismatched values between nodejs and browser", () => {
const value = 47_939;
const actual = nf(value, '0.0a');
const actual = nf(value, "0.0a");

// const expected = '48K'; // chrome, firefox
const expected = '47.9K'; // nodejs
const expected = "47.9K"; // nodejs
expect(actual).toBe(expected);
});

it('respect number of fraction digits', () => {
it("respect number of fraction digits", () => {
const value = 123.4;
const actual = nf(value, '0.00[0]');
const actual = nf(value, "0.00[0]");

const expected = '123.40';
const expected = "123.40";
expect(actual).toBe(expected);
});
});
10 changes: 5 additions & 5 deletions src/formats/ordinal.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { formatOrdinal } from './ordinal';
import { formatOrdinal } from "./ordinal";

describe('formats ordinals', () => {
describe("formats ordinals", () => {
it.each([
['0o', 1, '1', 'en-GB', '1st'],
['0o', 2, '2', 'en-GB', '2nd'],
])('ordinals: %s', (format, value, formatted, locale, expected) => {
["0o", 1, "1", "en-GB", "1st"],
["0o", 2, "2", "en-GB", "2nd"],
])("ordinals: %s", (format, value, formatted, locale, expected) => {
const result = formatOrdinal({ value, formatted, locale, format });
expect(result).toBe(expected);
});
Expand Down
14 changes: 7 additions & 7 deletions src/formats/ordinal.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { rgSpaceBetween } from '../helpers/regex';
import { rgSpaceBetween } from "../helpers/regex";

function getSuffixes(locale: string) {
switch (locale) {
case 'en-GB':
case "en-GB":
default:
return new Map([
['one', 'st'],
['two', 'nd'],
['few', 'rd'],
['other', 'th'],
["one", "st"],
["two", "nd"],
["few", "rd"],
["other", "th"],
]);
}
}
Expand All @@ -23,7 +23,7 @@ interface IFormatOrdinalParams {
export function formatOrdinal(params: IFormatOrdinalParams) {
const { value, formatted, locale, format } = params;
const pluralRules = new Intl.PluralRules(locale, {
type: 'ordinal',
type: "ordinal",
});

const rule = pluralRules.select(value);
Expand Down
28 changes: 14 additions & 14 deletions src/formats/percentage.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { formatPercentage } from './percentage';
import { formatPercentage } from "./percentage";

describe('percentage', () => {
describe("percentage", () => {
it.each([
['0%', '100%', 1, undefined],
['0 %', '100 %', 1, undefined],
['0.0%', '1.0%', 0.01, 1],
['0.0 %', '1.0 %', 0.01, 1],
['0.00 %', '1.20 %', 0.012, 2],
['0.00 %', '1.23 %', 0.0123, 2],
['0,0.0 %', '2,000 %', 20, undefined],
['0,0.0 %', '2,000,000 %', 20_000, undefined],
['0,0.0 %', '2,000,000.00 %', 20_000, 2],
["0%", "100%", 1, undefined],
["0 %", "100 %", 1, undefined],
["0.0%", "1.0%", 0.01, 1],
["0.0 %", "1.0 %", 0.01, 1],
["0.00 %", "1.20 %", 0.012, 2],
["0.00 %", "1.23 %", 0.0123, 2],
["0,0.0 %", "2,000 %", 20, undefined],
["0,0.0 %", "2,000,000 %", 20_000, undefined],
["0,0.0 %", "2,000,000.00 %", 20_000, 2],
])(
'percentage: %s = %s',
"percentage: %s = %s",
(format, expected, value, minimumFractionDigits) => {
const nf = new Intl.NumberFormat('en-GB', {
style: 'percent',
const nf = new Intl.NumberFormat("en-GB", {
style: "percent",
minimumFractionDigits,
});
const params = { format, value, numberFormatter: nf };
Expand Down
10 changes: 5 additions & 5 deletions src/formats/percentage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rgSpaceBetween } from '../helpers/regex';
import { fromParts } from '../helpers/from-parts';
import { rgSpaceBetween } from "../helpers/regex";
import { fromParts } from "../helpers/from-parts";

interface IFormatPercentageParams {
format: string;
Expand All @@ -14,12 +14,12 @@ export function formatPercentage(params: IFormatPercentageParams) {

return [
minusSign,
(integer as string[]).join((group as string) || ''),
(integer as string[]).join((group as string) || ""),
decimal,
fraction,
rgSpaceBetween.test(format) && ' ',
rgSpaceBetween.test(format) && " ",
percentSign,
]
.filter(Boolean)
.join('');
.join("");
}
10 changes: 5 additions & 5 deletions src/helpers/convert-to-number.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { convertToNumber } from './convert-to-number';
import { convertToNumber } from "./convert-to-number";

describe('convert to number', () => {
describe("convert to number", () => {
it.each([
[undefined, null],
[null, null],
[{}, null],
[[], null],
[[1_234], 1_234],
[[1_234, 5_678], null],
['abc', null],
['1234', 1_234],
["abc", null],
["1234", 1_234],
[1_234, 1_234],
])('converts from user input to number', (userInput, expected) => {
])("converts from user input to number", (userInput, expected) => {
const result = convertToNumber(userInput);
expect(result).toBe(expected);
});
Expand Down
14 changes: 7 additions & 7 deletions src/helpers/digits-format.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getDigitsFormat } from './digits-format';
import { getDigitsFormat } from "./digits-format";

describe('digits format', () => {
describe("digits format", () => {
it.each([
[undefined, '0,000'],
['0', '0'],
['0,0', '0,000'],
['0,000[.]00', '0,000[.]00'],
])('digits format: %s = %s', (format, expected) => {
[undefined, "0,000"],
["0", "0"],
["0,0", "0,000"],
["0,000[.]00", "0,000[.]00"],
])("digits format: %s = %s", (format, expected) => {
const result = getDigitsFormat(format);
expect(result).toBe(expected);
});
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/digits-format.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { rgDigitsFormat } from './regex';
import { rgDigitsFormat } from "./regex";

export function getDigitsFormat(format?: string) {
const [digitsFormat] = rgDigitsFormat.exec(format || '') || ['0,000'];
const [digitsFormat] = rgDigitsFormat.exec(format || "") || ["0,000"];

if (digitsFormat === '0,0') return '0,000';
if (digitsFormat === "0,0") return "0,000";

return digitsFormat;
}
Loading

0 comments on commit 465d58f

Please sign in to comment.