This commit is contained in:
LittleBoy 2025-04-18 10:32:59 +08:00
parent 554b53c43e
commit 694e106bcf
8 changed files with 1827 additions and 0 deletions

10
.editorconfig Normal file
View 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
View File

@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated

13
.gitignore vendored Normal file
View 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.*

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# packages
git+https

15
libs/index.ts Normal file
View 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
View 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
View 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);
});
});

1701
yarn.lock Normal file

File diff suppressed because it is too large Load Diff