Skip to content

Commit

Permalink
feat: 增加number package
Browse files Browse the repository at this point in the history
  • Loading branch information
JuctTr committed Aug 16, 2023
1 parent 326a643 commit 14a4ac0
Show file tree
Hide file tree
Showing 14 changed files with 735 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dist-ssr
*.local

# Editor directories and files
.vscode/*
# .vscode/*
!.vscode/extensions.json
.idea
.DS_Store
Expand All @@ -31,3 +31,7 @@ web-docs/**/**/cache/*

packages/**/cjs/*
packages/**/es/*


packages/storage
packages/datatime
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "test2 vite build",
"request": "launch",
"runtimeArgs": ["build"],
"runtimeExecutable": "pnpm",
"skipFiles": ["<node_internals>/**"],
"type": "node"
},
{
"type": "node",
"request": "launch",
"name": "启动程序",
"skipFiles": ["<node_internals>/**"],
"program": "${file}"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
11 changes: 8 additions & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"npmClient": "pnpm",
"version": "independent",
"command": {
"version": {
"allowBranch": ["main", "master"],
"allowBranch": [
"main",
"master"
],
"conventionalCommits": true,
"message": "chore(release): publish %s"
},
"publish": {
"allowBranch": ["main", "master"],
"allowBranch": [
"main",
"master"
],
"conventionalCommits": true
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 描述

解决浮动运算问题,避免小数点后产生多位数和计算精度丢失,使得 javascript 能够精确执行加、减、乘、除运算。

## 安装

```bash
npm i -S @jucttr/number --registry=https://registry.npmjs.org/
```

## 使用

## 参考

https://github.com/nefe/number-precision
34 changes: 34 additions & 0 deletions packages/number/__test__/addComma.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, test } from 'vitest'
import { addComma } from '../src/addComma'

describe('addComma', () => {
test('非数字', () => {
expect(addComma(NaN)).toBe('NaN')
})

test('测试正整数', () => {
expect(addComma(5)).toBe('5')
expect(addComma(95)).toBe('95')
expect(addComma(995)).toBe('995')
expect(addComma(1995)).toBe('1,995')
expect(addComma(9945995)).toBe('9,945,995')
expect(addComma(123349945995)).toBe('123,349,945,995')
})

test('负正整数', () => {
expect(addComma(-1)).toBe('-1')
expect(addComma(-123)).toBe('-123')
expect(addComma(-1234)).toBe('-1,234')
expect(addComma(-9945995)).toBe('-9,945,995')
})

test('小数', () => {
expect(addComma(1.1)).toBe('1.1')
expect(addComma(1.11)).toBe('1.11')
expect(addComma(1.111)).toBe('1.111')
expect(addComma(1.1111)).toBe('1.1111')
expect(addComma(11111.11111)).toBe('11,111.11111')
expect(addComma(1234.11111)).toBe('1,234.11111')
expect(addComma(-12345.11111)).toBe('-12,345.11111')
})
})
Loading

0 comments on commit 14a4ac0

Please sign in to comment.