Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baht v1.0 #26

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2402039
Bump packages, add BahtRext to benchmark
narze Aug 12, 2024
cb11dfe
Update Github Action with Bun support
narze Aug 12, 2024
6f8c0b2
Remove unsupported node version in CI
narze Aug 12, 2024
c0cb529
Attempt to fix size-limit action
narze Aug 12, 2024
96f706d
Bump js packages
narze Aug 12, 2024
4e25844
Update benchmarks
narze Aug 12, 2024
bc09fa7
Test in Node >=18 due to tool requirements
narze Aug 12, 2024
d7ad463
Refactor
narze Aug 12, 2024
b7b9fc7
Add deno test
narze Aug 14, 2024
9918a67
Export default
narze Aug 14, 2024
8ac3a34
Cleanup & optimize
narze Aug 14, 2024
e52374e
Use latest macos runner
narze Aug 18, 2024
ccbed54
make string narok-less (#27)
NotRealPaz Aug 18, 2024
36bf6cb
Upgrade site
narze Aug 18, 2024
4a33cb0
Add compare page
narze Aug 18, 2024
624f7ba
Add custom input
narze Aug 18, 2024
f13b532
Import bahtjs from source
narze Aug 18, 2024
1b384e8
Add roundSatangs option to match with BAHTTEXT spreadsheet function
narze Aug 18, 2024
2be2f31
Refactor
narze Aug 19, 2024
36242ad
Update manifest & export convert function by default
narze Aug 19, 2024
5a8fefd
wip
narze Aug 19, 2024
4757560
Fix rounding
narze Sep 2, 2024
a1c7e56
Fix deno test
narze Sep 2, 2024
4435353
Convert benchmark to mjs, remove duplicated lib
narze Sep 2, 2024
41820a2
Import baht
narze Sep 2, 2024
f4b3169
Build main project before using in site
narze Sep 2, 2024
b246d79
Fix roundSatangs not working in string input mode
narze Sep 3, 2024
a21cfa4
Show diffs on samples
narze Sep 3, 2024
c7c668d
Remove numberformat & limit max input length
narze Sep 3, 2024
c91a7e5
Add link to compare page
narze Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI (Bun)
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build, and test with Bun
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2

- run: bun install
- run: bun test
- run: bun run build
35 changes: 35 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

name: Deno

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Setup Deno
# uses: denoland/setup-deno@v1
uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2
with:
deno-version: v1.x

# Uncomment this step to verify the use of 'deno fmt' on each commit.
# - name: Verify formatting
# run: deno fmt --check

# - name: Run linter
# run: deno lint

- name: Run tests
run: deno test ./deno
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.x', '14.x', '16.x', '18.x', '20.x']
os: [ubuntu-latest, windows-latest, macOS-11]
node: ['18.x', '20.x', '22.x']
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ jobs:
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
node-version: "22.x"

- run: yarn install --frozen-lockfile

- name: Check size-limit
run: yarn run size
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,35 @@ Convert number to Thai Baht format, but faster & fully typed.

Run the benchmark to measure the speed among other libraries.

- Apple Macbook Pro M1
- Apple Macbook M1 Pro (Node v22.6.0)

```shell
yarn benchmark

baht 0.5.0 (x100000): 355ms
baht 0.4.0 (x100000): 665ms
baht 0.3.2 (x100000): 2968ms
thaiBahtLib (x100000): 3189ms
bahttext (x100000): 3503ms
BAHTTEXT.js (x100000): 4816ms
thai-baht-text-ts (x100000): 7710ms
thai-baht-text (x100000): 8525ms
baht (x100000): 364ms
thai-baht-lib (code improved from baht.js) (x100000): 359ms
bahttext (x100000): 2791ms
BAHTTEXT.js (x100000): 2417ms
thai-baht-text (x100000): 5010ms
thai-baht-text-ts (x100000): 4465ms
BahtRext (x100000): 6131ms
```

- Apple Macbook Pro with Node v14.16.0
- Apple Macbook M1 Pro (Bun v1.1.22)

```shell
bun ./benchmark

baht (x100000): 336ms
thai-baht-lib (code improved from baht.js) (x100000): 329ms
bahttext (x100000): 3574ms
BAHTTEXT.js (x100000): 2799ms
thai-baht-text (x100000): 6163ms
thai-baht-text-ts (x100000): 5143ms
BahtRext (x100000): 7085ms
```

- Apple Macbook Pro (Intel) with Node v14.16.0

```shell
yarn benchmark
Expand Down
27 changes: 18 additions & 9 deletions benchmark/index.js → benchmark/index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { bahttext } = require('bahttext');
const THBText = require('thai-baht-text');
const { ThaiBaht } = require('thai-baht-text-ts');
const BAHTTEXTjs = require('./BAHTTEXT');
const thaiBahtLib = require('@to-da-moon/thai-baht-lib');
const { convert: baht } = require('../dist/baht.cjs.production.min');
const { convert: bahtLatest } = require('baht');
import { bahttext } from 'bahttext';
import THBText from 'thai-baht-text';
import { ThaiBaht } from 'thai-baht-text-ts';
import BAHTTEXTjs from '../site/src/lib/BAHTTEXT.js';
import thaiBahtLib from '@to-da-moon/thai-baht-lib';
import bahtRext from 'bahtrext';
import { convert as baht } from '../dist/baht.cjs.development.js';
import { convert as bahtLatest } from 'baht';

const times = 100000;
const numbers = [
Expand Down Expand Up @@ -59,21 +60,29 @@ const numbers = [
Number.MAX_SAFE_INTEGER - 1, // bahttext cannot count above this and will return empty string
];

const stringifiedNumbers = numbers.map(n => n.toString());

const libraries = {
baht: n => baht(n),
bahtLatest: n => bahtLatest(n),
thaiBahtLib: n => thaiBahtLib.bahtText(n),
'thai-baht-lib (code improved from baht.js)': n => thaiBahtLib.bahtText(n),
bahttext: n => bahttext(n),
'BAHTTEXT.js': n => BAHTTEXTjs(n),
'thai-baht-text': n => THBText(n),
'thai-baht-text-ts': n => ThaiBaht(n),
BahtRext: n => bahtRext.BT(n),
};

Object.entries(libraries).forEach(([name, fn]) => {
// BahtRext supports only string, so we need to convert them before testing
const numbersToTest = Array.from(
name === 'BahtRext' ? stringifiedNumbers : numbers
);

const start = new Date();

new Array(times).fill(0).forEach(_ => {
numbers.forEach(number => fn(number));
numbersToTest.forEach(number => fn(number));
});

const end = new Date();
Expand Down
Binary file added bun.lockb
Binary file not shown.
39 changes: 39 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions deno/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { assertEquals } from 'jsr:@std/assert@1';

import Baht from '../src/index.ts';

function assertBaht(value: number, expected: string) {
console.log(`${value} -> ${Baht(value)} (Expected: ${expected})`);
assertEquals(Baht(value), expected);
}

Deno.test('Baht.js works on Deno', () => {
assertBaht(123, 'หนึ่งร้อยยี่สิบสามบาทถ้วน');
assertBaht(123.45, 'หนึ่งร้อยยี่สิบสามบาทสี่สิบห้าสตางค์');
});
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"version": "0.7.1",
"version": "1.0.0",
"name": "baht",
"author": "Manassarn Manoonchai",
"description": "Convert number to Thai Baht format, but faster & fully typed.",
"description": "Convert number to Thai Baht & Satang format. Blazingly fast. TypeScript / Deno / Bun supported.",
"license": "MIT",
"main": "dist/index.js",
"homepage": "https://github.com/narze/baht.js",
"repository": "github:narze/baht.js",
"keywords": [
"Thai",
"Baht",
"bahttext",
"thai",
"baht",
"THB",
"Money",
"Number",
"Format",
"Convert",
"TypeScript",
"JavaScript"
"money",
"number",
"format",
"convert",
"TypeScript"
],
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -35,7 +35,7 @@
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why",
"benchmark": "node ./benchmark"
"benchmark": "node ./benchmark/index.mjs"
},
"peerDependencies": {},
"husky": {
Expand All @@ -61,17 +61,18 @@
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^6.0.0",
"@to-da-moon/thai-baht-lib": "^0.0.10",
"@size-limit/preset-small-lib": "^11.1.4",
"@to-da-moon/thai-baht-lib": "^0.0.12",
"baht": "^0.7.1",
"bahttext": "^2.0.2",
"husky": "^7.0.2",
"size-limit": "^6.0.0",
"thai-baht-text": "^1.0.8",
"thai-baht-text-ts": "^1.0.5",
"bahtrext": "^1.3.2",
"bahttext": "^2.3.0",
"husky": "^9.1.4",
"size-limit": "^11.1.4",
"thai-baht-text": "^2.0.5",
"thai-baht-text-ts": "^1.1.0",
"tsdx": "^0.14.1",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"tslib": "^2.6.3",
"typescript": "^5.5.4"
},
"dependencies": {}
}
21 changes: 19 additions & 2 deletions site/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
/node_modules/
/public/build/
node_modules

# Output
.output
.vercel
/.svelte-kit
/build

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions site/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
4 changes: 4 additions & 0 deletions site/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Package Managers
package-lock.json
pnpm-lock.yaml
yarn.lock
8 changes: 8 additions & 0 deletions site/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
3 changes: 0 additions & 3 deletions site/.vscode/extensions.json

This file was deleted.

Loading
Loading