initial
This commit is contained in:
parent
554b53c43e
commit
694e106bcf
10
.editorconfig
Normal file
10
.editorconfig
Normal file
@ -0,0 +1,10 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{js,json,yml}]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/.yarn/** linguist-vendored
|
||||
/.yarn/releases/* binary
|
||||
/.yarn/plugins/**/* binary
|
||||
/.pnp.* binary linguist-generated
|
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
|
||||
# Swap the comments on the following lines if you wish to use zero-installs
|
||||
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
|
||||
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
|
||||
|
||||
#!.yarn/cache
|
||||
.pnp.*
|
15
libs/index.ts
Normal file
15
libs/index.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export function helloWorld() {
|
||||
console.log("Hello World!");
|
||||
}
|
||||
/**
|
||||
* 将数字格式化为美式金额表示法
|
||||
* 将金额格式化为两位小数,需要处理千分位格式
|
||||
* @param amount - 需要格式化的数字金额
|
||||
* @returns 返回格式化后的金额字符串,保留2位小数
|
||||
* @example
|
||||
* formatMoney(1234.5) // 返回 "1,234.50"
|
||||
* formatMoney(1000000) // 返回 "1,000,000.00"
|
||||
*/
|
||||
export function formatMoney(amount: number) {
|
||||
return new Intl.NumberFormat('en-US', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(amount);
|
||||
}
|
30
package.json
Normal file
30
package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "packages",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"author": "callmeyan <me@xiaoyan.me>",
|
||||
"main": "dist/index.cjs",
|
||||
"types": "dist/index.d.cts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://git.wm-app.xyz/packages/npm-package-demo.git"
|
||||
},
|
||||
"keywords": [
|
||||
"packages",
|
||||
"package",
|
||||
"manager",
|
||||
"demo",
|
||||
"yarn"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsup libs/index.ts --dts --clean",
|
||||
"clean": "git clean -xdf dist",
|
||||
"test": "bun test"
|
||||
},
|
||||
"packageManager": "yarn@4.5.2",
|
||||
"devDependencies": {
|
||||
"tsup": "^8.4.0",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
52
tests/index.test.ts
Normal file
52
tests/index.test.ts
Normal file
@ -0,0 +1,52 @@
|
||||
// index.test.ts
|
||||
import { formatMoney } from '../libs/index';
|
||||
|
||||
describe('FormatMoneyTest', () => {
|
||||
test('should format positive integer correctly', () => {
|
||||
// Arrange
|
||||
const input = 1234;
|
||||
const expectedOutput = "1,234.00";
|
||||
|
||||
// Act
|
||||
const result = formatMoney(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
test('should format zero correctly', () => {
|
||||
// Arrange
|
||||
const input = 0;
|
||||
const expectedOutput = "0.00";
|
||||
|
||||
// Act
|
||||
const result = formatMoney(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
test('should format large integer correctly', () => {
|
||||
// Arrange
|
||||
const input = 1000000;
|
||||
const expectedOutput = "1,000,000.00";
|
||||
|
||||
// Act
|
||||
const result = formatMoney(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
test('should format negative integer correctly', () => {
|
||||
// Arrange
|
||||
const input = -5000;
|
||||
const expectedOutput = "-5,000.00";
|
||||
|
||||
// Act
|
||||
const result = formatMoney(input);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedOutput);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user