Skip to content

Commit 8e3032f

Browse files
Upgrade Project (#37)
* feat: configure project structure and add tooling setup Added `syncpack` and `biome` configuration for consistent project dependencies and formatting. Updated `renovate.json` and introduced additional tooling files like `.syncpackrc.json`, `biome.json`, `pnpm-workspace.yaml`, and `mise.toml`. Enhanced TypeScript configurations for better compilation and bundling settings. * ci: add autofix workflow and update test workflows Introduced a new `autofix.ci` workflow to apply automated fixes on PRs and pushes to the main branch. Replaced individual Node.js and pnpm setup in test workflows with a unified toolchain setup using `jdx/mise-action` for consistency. * refactor: standardize code style and fix formatting inconsistencies Updated function syntax in test files to use arrow functions for consistency. Added trailing commas in multiline arguments and object definitions. Reorganized imports in `NumberReader.ts` and improved object method access in static methods for better clarity. * feat: add configurations for tsdown and vitest Introduced `tsdown.config.ts` for bundling settings with ESM output and DTS generation. Added `vitest.config.mts` with Codspeed plugin and custom exclusions for tests and coverage. Enhances development and testing workflows. * docs: update README badges for downloads and JSR Replaced the outdated JSR badge with separate badges for weekly downloads and JSR. Improves the README's informational clarity and visual appeal by showcasing key project metrics. * docs: fix README formatting and minor phrasing Adjusted formatting by moving the description above the badges for better structure. Updated a minor phrasing in the release notes section for clarity. * docs: refine section titles in README for clarity Simplified and standardized section titles by removing example text from headers. This improves readability and maintains a consistent structure throughout the documentation. * feat(benchmark): add comprehensive benchmark tests Introduced benchmarking for `formatVnNumber`, `formatVnCurrency`, `formatVnPercent`, and `readVnNumber` to evaluate performance under various scenarios. These tests help identify performance bottlenecks and ensure the reliability and efficiency of the formatting functions. Updated CI workflow to include a benchmark step using CodSpeed. * ci: update workflows to replace Prettier with Biome Replaced Prettier checks with Biome for formatting and added `syncpack` commands for dependency management. Updated test workflow to improve coverage reporting using Codecov, and removed obsolete Prettier configurations from the repository. * [autofix.ci] apply automated fixes * chore(deps): update vitest and add CodSpeed plugin Upgraded `vitest` to 4.0.5 for compatibility and performance improvements. Added `@codspeed/vitest-plugin` to enhance benchmarking capabilities, ensuring better testing accuracy and performance analysis. * [autofix.ci] apply automated fixes * chore(deps): remove unused dependencies from devDependencies Removed `@edge-runtime/vm`, `happy-dom`, and `jsdom` from `devDependencies` in `package.json` as they were no longer in use. Adjusted `pnpm-lock.yaml` to reflect these changes and marked related dependencies as optional where applicable. * [autofix.ci] apply automated fixes * ci: enhance autofix workflow with audit fixes and lock sync Added a step to automatically fix audit issues using `pnpm audit --fix` for improved dependency security. Adjusted `pnpm install` step to no longer use the `--fix-lockfile` option for better compatibility and workflow stability. * [autofix.ci] apply automated fixes * chore(deps): add @vitest/coverage-v8 and clean overrides Added `@vitest/coverage-v8` to `devDependencies` for enhanced test coverage reporting. Removed outdated overrides for `happy-dom` in `pnpm-lock.yaml` and `pnpm-workspace.yaml` to simplify dependency management. Adjusted the lockfile to include new transitive dependencies. * Add Changesets setup for versioning Introduced Changesets configuration files to support version management and publishing workflows. This setup provides tools for managing multi-package or single-package repositories, improving release processes. * Streamline publishes workflow and removes semantic-release Optimized the GitHub Actions workflow by simplifying and restructuring steps in the publish process. Replaced `semantic-release` with `changesets` for improved versioning and release management, and removed the obsolete `.releaserc.json` configuration. This enhances the workflow's efficiency and maintainability. * Prepare package for publication Added `main`, `module`, `types`, and `exports` fields in `package.json` to establish proper package entry points. Updated `files` to include `dist` for NPM publication and upgraded `version` to `1.5.7`. Enhanced the build setup with `tsdown` and `[email protected]` for improved TypeScript support. * Rename test job to unit-test for clarity Updated the test job name in the GitHub Actions workflow to `unit-test`. This improves job naming consistency and distinguishes unit tests from other potential test types in the workflow. * Update vitest dependencies to 4.0.6 Bumped `vitest` and related packages (`@vitest/coverage-v8`, `@vitest/expect`, etc.) to version 4.0.6 in `package.json` and `pnpm-lock.yaml`. These updates ensure compatibility, performance improvements, and the latest features for testing. * Remove unused coverage and exclude settings Simplified `vitest.config.mts` by removing redundant `coverage` and `exclude` settings. These configurations are no longer applicable or needed, streamlining the test configuration. * Upgrade esbuild and clean up dependencies Updated `esbuild` to version 0.25.12 in `pnpm-lock.yaml`, ensuring compatibility with the latest features and bug fixes. Removed multiple unused dependencies from the lockfile, significantly simplifying and streamlining the dependency tree. * Rename bench description for clarity Updated the bench description in `number.bench.ts` to replace "100%" with "100 percent". This improves readability and aligns with descriptive naming conventions in benchmarks. * Update actions and dependencies in workflow Updated `actions/checkout` to v5.0.0 and `denoland/setup-deno` to v2.0.3 in the GitHub Actions workflows. Added descriptive step names for better readability and consistency across the workflow. * Add `override` specifier and fix doc comments Added the `override` specifier to `read` methods in `Billion` and `Zerofill` classes for better clarity and adherence to TypeScript standards. Updated doc comments for consistency and clarity by correcting phrasing. * Remove unused `needs` in Deno job Removed the `needs: lints` dependency from the Deno job in the GitHub Actions workflow. This cleanup eliminates a redundant configuration, streamlining the workflow setup without affecting functionality. * Remove unused CODSPEED_TOKEN from workflow Removed the `CODSPEED_TOKEN` secret from the bench job in the GitHub Actions workflow. This token is no longer necessary and its removal simplifies the job configuration. * Downgrade vitest and related packages Downgraded `vitest` and `@vitest/coverage-v8` to version 3.2.4 in `package.json`. This change addresses compatibility issues or aligns with project requirements by using stable, well-supported versions. * Remove unused env variables from bench job Removed the `NODE_OPTIONS` environment variable from the bench job in the GitHub Actions workflow. This cleanup eliminates redundant settings, simplifying the workflow configuration without affecting functionality. * Downgrade esbuild to 0.25.11 Reverted `esbuild` from 0.25.12 to 0.25.11 in `pnpm-lock.yaml` for compatibility with `[email protected]`. Removed unused references to `[email protected]`, simplifying the lockfile and ensuring a consistent dependency tree. * Allow non-frozen lockfile in autofix workflow Updated the autofix workflow to use `pnpm install --no-frozen-lockfile`. This ensures flexibility in resolving dependencies, particularly when the lockfile may not align with the current environment. * Add timeout to vitest bench command Updated the bench command in the GitHub Actions workflow to include a `--testTimeout 10000` flag. This ensures that benchmarks have adequate time to complete without timing out in CI environments. * Simplify benchmarking configurations Removed redundant `--testTimeout` flag from vitest bench command in workflows. Standardized and clarified benchmark descriptions for better readability and alignment with typical usage scenarios. Streamlined batch and real-world operation setups across all benchmarks without affecting functionality. * Reformat metric data generation loop Refactored `metrics` data generation and number reading loops for better readability and maintainability. Ensured consistent code style and alignment with project formatting guidelines without altering functionality. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c311668 commit 8e3032f

36 files changed

+2768
-1031
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/workflows/autofix.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: autofix.ci
2+
3+
on:
4+
pull_request:
5+
branches-ignore:
6+
- 'renovate/**'
7+
push:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
apply:
16+
name: Apply automated fixes
17+
runs-on: ubuntu-latest
18+
if: ${{ github.actor != 'renovate[bot]' && ! contains(github.event.head_commit.author.name , 'renovate[bot]') && ! contains(github.event.head_commit.message , 'chore(release)') }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+
- name: Setup toolchains
23+
uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
24+
- name: Install Dependencies
25+
run: pnpm install --no-frozen-lockfile
26+
- name: Format code
27+
run: pnpm biome check --write
28+
- name: Fix package.json
29+
run: pnpm syncpack fix
30+
- name: Format package.json
31+
run: pnpm syncpack format
32+
- name: Fix audit issues
33+
run: pnpm audit --fix
34+
- name: Update package lock file
35+
run: pnpm install --no-frozen-lockfile
36+
- name: Submit autofix
37+
uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27 # v1.3.2
38+
with:
39+
fail-fast: false

.github/workflows/publish.yml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,34 @@ jobs:
1212
secrets: inherit
1313
release:
1414
name: Release
15-
needs: test
1615
runs-on: ubuntu-latest
1716
permissions:
17+
id-token: write
1818
contents: write
19-
issues: write
2019
pull-requests: write
21-
id-token: write
2220
steps:
23-
- uses: actions/checkout@v4
24-
with:
25-
fetch-depth: 0
26-
- name: Install jq
27-
uses: dcarbone/install-jq-action@v2
28-
- name: Setup pnpm
29-
uses: pnpm/action-setup@v3
30-
with:
31-
version: latest
32-
- name: Setup Node.js
33-
uses: actions/setup-node@v4
21+
- name: Checkout
22+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
- name: Setup toolchains
24+
uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
25+
- name: Install Dependencies
26+
run: pnpm install
27+
- name: Update npm
28+
run: npm install -g npm@latest
29+
- name: Create Release Pull Request or Publish to npm
30+
uses: changesets/action@e0145edc7d9d8679003495b11f87bd8ef63c0cba # v1.5.3
31+
id: changesets
3432
with:
35-
node-version: 'lts/*'
36-
cache: 'pnpm'
37-
- name: Release on GitHub
38-
run: pnpm --package conventional-changelog-conventionalcommits --package semantic-release dlx semantic-release
33+
publish: 'pnpm tsdown && pnpm changeset publish'
34+
commitMode: 'github-api'
35+
title: 'Release new version'
36+
commit: 'Bump version package'
3937
env:
4038
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
- name: Update version for JSR registry
39+
- name: Publish to JSR
4240
run: |
4341
VERSION=$(node -p "require('./package.json').version")
4442
jq --arg version "$VERSION" '.version = $version' jsr.json > jsr.json.tmp
4543
mv jsr.json.tmp jsr.json
46-
echo "VERSION=$VERSION" >> $GITHUB_ENV
47-
- name: Publish package to JSR
48-
if: env.VERSION != '0.0.0-development'
49-
run: pnpm dlx jsr publish
44+
pnpm dlx jsr publish --allow-dirty
45+
if: steps.changesets.outputs.published == 'true'

.github/workflows/tests.yml

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,70 @@ jobs:
1111
name: Lints
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4
15-
- name: Setup pnpm
16-
uses: pnpm/action-setup@v3
17-
with:
18-
version: latest
19-
- uses: actions/setup-node@v4
20-
with:
21-
node-version: 'lts/*'
22-
cache: 'pnpm'
14+
- name: Checkout
15+
uses: actions/[email protected]
16+
- name: Setup toolchains
17+
uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
2318
- name: Install dependencies
2419
run: pnpm install
25-
- name: Prettier check
26-
run: pnpm test:prettier
20+
- name: Biome check
21+
run: pnpm biome check
22+
- name: Syncpack lint
23+
run: pnpm syncpack lint
24+
- name: Syncpack format
25+
run: pnpm syncpack format --check
2726
- name: Checks for known security issues with the installed packages
2827
run: pnpm audit
2928
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
3029
run: pnpm npm audit signatures
3130
- name: Verify the package for publishing performing all checks and validations
3231
run: pnpm dlx jsr publish --dry-run
33-
node:
34-
name: Node
35-
needs: lints
32+
unit-test:
33+
name: Unit Test
3634
runs-on: ubuntu-latest
37-
strategy:
38-
matrix:
39-
node: [18, 20, 21]
35+
permissions:
36+
id-token: write
37+
contents: read
4038
steps:
41-
- uses: actions/checkout@v4
42-
- name: Setup pnpm
43-
uses: pnpm/action-setup@v3
39+
- name: Checkout
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
- name: Setup toolchains
42+
uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
43+
- name: Install Dependencies
44+
run: pnpm install
45+
- name: Run Tests
46+
run: pnpm vitest --coverage --reporter=junit --outputFile=test-report.junit.xml
47+
- name: Upload coverage reports to Codecov
48+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
4449
with:
45-
version: latest
46-
- name: Set up Node.js ${{matrix.node}}
47-
uses: actions/setup-node@v4
50+
use_oidc: true
51+
- name: Upload test results to Codecov
52+
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
53+
if: ${{ !cancelled() }}
4854
with:
49-
node-version: ${{matrix.node}}
50-
cache: 'pnpm'
51-
- name: Install dependencies
52-
run: pnpm install
53-
- name: Run unit tests
54-
run: pnpm test -- --environment=node
55-
test:
56-
name: Test
57-
needs: lints
55+
use_oidc: true
56+
benchmark:
57+
name: Benchmark
5858
runs-on: ubuntu-latest
59-
strategy:
60-
matrix:
61-
environment: [edge-runtime, jsdom, happy-dom]
6259
steps:
63-
- uses: actions/checkout@v4
64-
- name: Setup pnpm
65-
uses: pnpm/action-setup@v3
66-
with:
67-
version: latest
68-
- name: Set up Node.js
69-
uses: actions/setup-node@v4
70-
with:
71-
node-version: 'lts/*'
72-
cache: 'pnpm'
73-
- name: Install dependencies
60+
- name: Checkout
61+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
62+
- name: Setup toolchains
63+
uses: jdx/mise-action@be3be2260bc02bc3fbf94c5e2fed8b7964baf074 # v3.4.0
64+
- name: Install Dependencies
7465
run: pnpm install
75-
- name: Run unit tests
76-
run: pnpm test -- --environment=${{ matrix.environment }}
66+
- name: Run Benchmarks
67+
uses: CodSpeedHQ/action@4348f634fa7309fe23aac9502e88b999ec90a164 # v4.3.1
68+
with:
69+
run: pnpm vitest bench
70+
mode: 'instrumentation'
7771
deno:
7872
name: Deno
79-
needs: lints
8073
runs-on: ubuntu-latest
8174
steps:
82-
- uses: actions/checkout@v4
75+
- name: Checkout
76+
uses: actions/[email protected]
8377
- name: Install Deno
84-
uses: denoland/setup-deno@v1
78+
uses: denoland/setup-deno@v2.0.3
8579
- name: Type-check the dependencies
8680
run: deno check src/index.ts

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.prettierrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.releaserc.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

.syncpackrc.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$schema": "./node_modules/syncpack/schema.json",
3+
"sortFirst": [
4+
"name",
5+
"description",
6+
"version",
7+
"productName",
8+
"author",
9+
"homepage",
10+
"repository",
11+
"bugs",
12+
"private",
13+
"publishConfig",
14+
"sideEffects",
15+
"type",
16+
"main",
17+
"module",
18+
"types",
19+
"exports",
20+
"scripts",
21+
"dependencies",
22+
"devDependencies",
23+
"peerDependencies",
24+
"trustedDependencies",
25+
"workspaces",
26+
"packageManager"
27+
],
28+
"sortExports": ["import", "types"],
29+
"sortAz": [
30+
"exports",
31+
"scripts",
32+
"workspaces",
33+
"dependencies",
34+
"devDependencies",
35+
"peerDependencies",
36+
"trustedDependencies"
37+
],
38+
"semverGroups": [
39+
{
40+
"label": "All non-peer dependencies must be pinned",
41+
"range": "",
42+
"dependencyTypes": ["!peer"],
43+
"dependencies": ["**"],
44+
"packages": ["**"]
45+
},
46+
{
47+
"label": "Allow peer deps to be equal or higher than current versions",
48+
"range": ">=",
49+
"dependencyTypes": ["peer"],
50+
"dependencies": ["**"],
51+
"packages": ["**"]
52+
}
53+
],
54+
"formatBugs": false,
55+
"formatRepository": false
56+
}

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# vn-number 🇻🇳
22

3-
[![JSR Score](https://jsr.io/badges/@hckhanh/vn-number)](https://jsr.io/@hckhanh/vn-number)
4-
53
🛠 A bunch of utility functions that work with number in 🇻🇳 Vietnamese language
64

5+
[![NPM Downloads](https://img.shields.io/npm/dw/vn-number)](https://www.npmjs.com/package/vn-number)
6+
[![JSR](https://jsr.io/badges/@hckhanh/vn-number/weekly-downloads)](https://jsr.io/@hckhanh/vn-number)
7+
78
## Features
89

910
- [Zero dependencies](https://jsr.io/@hckhanh/vn-number/dependencies)
@@ -13,7 +14,7 @@
1314

1415
## Functions
1516

16-
### Read Vietnamese number (một triệu hai trăm năm mươi nghìn)
17+
### Read Vietnamese number
1718

1819
```ts
1920
import { readVnNumber } from '@hckhanh/vn-number'
@@ -22,7 +23,7 @@ const result = readVnNumber(1250000)
2223
console.log(result) // một triệu hai trăm năm mươi nghìn
2324
```
2425

25-
### Format number in Vietnamese format (1.250.000)
26+
### Format number in Vietnamese format
2627

2728
```ts
2829
import { formatVnNumber } from '@hckhanh/vn-number'
@@ -31,7 +32,7 @@ const result = formatVnNumber(1250000)
3132
console.log(result) // 1.250.000
3233
```
3334

34-
### Format VN currency (VND) (1.250.000 ₫)
35+
### Format VN currency (VND - ₫)
3536

3637
```ts
3738
import { formatVnCurrency } from '@hckhanh/vn-number'
@@ -40,7 +41,7 @@ const result = formatVnCurrency(1250000)
4041
console.log(result) // 1.250.000 ₫
4142
```
4243

43-
### Format percentage in Vietnamese format (99,1%)
44+
### Format percentage in Vietnamese format
4445

4546
```ts
4647
import { formatVnPercent } from '@hckhanh/vn-number'
@@ -51,4 +52,4 @@ console.log(result) // 99,1%
5152

5253
## Release Notes
5354

54-
You can go to [Releases](https://github.com/hckhanh/vn-number/releases) page to see the release notes.
55+
You can go to [the Releases](https://github.com/hckhanh/vn-number/releases) page to see the release notes.

0 commit comments

Comments
 (0)