diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 59511d8..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,11 +0,0 @@ -const config = { - extends: [require.resolve('@umijs/fabric/dist/eslint')], - rules: { - 'react/no-did-update-set-state': 0, - 'react/no-find-dom-node': 0, - 'import/no-extraneous-dependencies': 0, - 'react/sort-comp': 0, - }, -}; - -module.exports = config; \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..758659a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: ant-design +open_collective: ant-design diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5e6c7fa --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,27 @@ +version: 2 +updates: + - package-ecosystem: npm + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 + groups: + npm-dependencies: + patterns: + - '*' + + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: weekly + day: monday + time: '21:00' + timezone: Asia/Shanghai + open-pull-requests-limit: 10 + groups: + github-actions: + patterns: + - '*' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..6082fc6 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,43 @@ +name: 'CodeQL' + +on: + push: + branches: ['master'] + pull_request: + branches: ['master'] + schedule: + - cron: '36 13 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [javascript-typescript] + + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Initialize CodeQL + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + with: + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 1426eec..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: ✅ test - -on: [push, pull_request] - -jobs: - test: - uses: react-component/rc-test/.github/workflows/test.yml@main - secrets: inherit diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index d02059a..0000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: 🔂 Surge PR Preview - -on: [pull_request] - -jobs: - preview: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: afc163/surge-preview@v1 - id: preview_step - with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - dist: .doc - build: | - npm install - npm run docs:build - - name: Get the preview_url - run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml new file mode 100644 index 0000000..29d6f76 --- /dev/null +++ b/.github/workflows/react-doctor.yml @@ -0,0 +1,22 @@ +name: React Doctor + +on: + pull_request: + push: + branches: [master] + +permissions: + contents: read + pull-requests: write + issues: write + statuses: write + +jobs: + react-doctor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + persist-credentials: false + - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3 diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 0000000..f9e3639 --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,52 @@ +name: Surge Preview + +on: + pull_request: + +permissions: + contents: read + pull-requests: write + checks: write + +jobs: + preview: + runs-on: ubuntu-latest + concurrency: + group: surge-preview-${{ github.event.pull_request.number }} + cancel-in-progress: true + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Check Surge token + id: surge-token + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + run: | + if [ -n "$SURGE_TOKEN" ]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "enabled=false" >> "$GITHUB_OUTPUT" + fi + - name: Setup utoo + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + uses: utooland/setup-utoo@v1 + + - name: Build preview + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + run: | + ut install + npm run build + - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec + if: ${{ steps.surge-token.outputs.enabled == 'true' }} + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + with: + surge_token: ${{ env.SURGE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + dist: dist + failOnError: false + setCommitStatus: false + - name: Skip Surge preview + if: ${{ steps.surge-token.outputs.enabled != 'true' }} + run: echo "SURGE_TOKEN is not configured; skip Surge preview." diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..10c0ebb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: ✅ test + +on: + push: + branches: [master] + pull_request: + branches: [master] + +permissions: + contents: read + +jobs: + test: + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 9d43240..3a5f7fd 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,73 @@ -# @rc-component/mini-decimal +
+

@rc-component/mini-decimal

+

Ant Design Part of the Ant Design ecosystem.

+

🧮 Small decimal calculator for precise string-based arithmetic.

-A mini decimal calculator which only support `add`, `multi` or compare operation for mini bundle size. +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

+
-[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url] +

English | 简体中文

-[npm-image]: http://img.shields.io/npm/v/@rc-component/mini-decimal.svg?style=flat-square -[npm-url]: http://npmjs.org/package/@rc-component/mini-decimal -[github-actions-image]: https://github.com/react-component/mini-decimal/workflows/CI/badge.svg -[github-actions-url]: https://github.com/react-component/mini-decimal/actions -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/mini-decimal/master.svg?style=flat-square -[codecov-url]: https://codecov.io/gh/react-component/mini-decimal/branch/master -[download-image]: https://img.shields.io/npm/dm/@rc-component/mini-decimal.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/mini-decimal +## Highlights -## Development +| Area | Support | +| ------- | ------------------------------------------------------------- | +| Purpose | Small decimal calculator for precise string-based arithmetic. | +| Package | `@rc-component/mini-decimal` | +| Release | `@rc-component/np` / `rc-np` | + +## Install ```bash -npm install -npm test +npm install @rc-component/mini-decimal ``` ## Usage -```tsx +```tsx | pure import getMiniDecimal from '@rc-component/mini-decimal'; -// Add getMiniDecimal('0.1').add('0.2').toString(); // 0.3 - -// Multi getMiniDecimal('0.1').multi('0.2').toString(); // 0.02 +``` + +## API -// Negate -getMiniDecimal('0.1').negate().toString(); // -0.1 +| Method | Description | +| ------------------- | ---------------------------------- | +| `add(value)` | Add another decimal value. | +| `multi(value)` | Multiply by another decimal value. | +| `negate()` | Return the negated value. | +| `equal(value)` | Check equality. | +| `lessEquals(value)` | Check whether the current value is less than or equal to another decimal value. | -// Equal -getMiniDecimal('0.1').equal('0.1'); // true -getMiniDecimal('0.1').equal('0.2'); // false +## Development -// Less Equals -getMiniDecimal('0.1').lessEquals('0.2'); // true -getMiniDecimal('0.1').lessEquals('0.1'); // false +```bash +npm install +npm test +npm run lint +npm run tsc +npm run compile ``` + +The dumi site runs at `http://localhost:8000`. + +## Release + +```bash +npm run prepublishOnly +``` + +The release flow is handled by `@rc-component/np` through the `rc-np` command when the package uses the shared release flow. + +## License + +@rc-component/mini-decimal is released under the [MIT](./LICENSE) license. diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..b8595d4 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,73 @@ +
+

@rc-component/mini-decimal

+

Ant Design Ant Design 生态的一部分。

+

🧮 用于精确字符串小数运算的轻量计算工具。

+ +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

+
+ +

English | 简体中文

+ +## 亮点 + +| 方向 | 支持 | +| ---- | -------------------------------------- | +| 定位 | 用于精确字符串小数运算的轻量计算工具。 | +| 包名 | `@rc-component/mini-decimal` | +| 发布 | `@rc-component/np` / `rc-np` | + +## 安装 + +```bash +npm install @rc-component/mini-decimal +``` + +## 用法 + +```tsx | pure +import getMiniDecimal from '@rc-component/mini-decimal'; + +getMiniDecimal('0.1').add('0.2').toString(); // 0.3 +getMiniDecimal('0.1').multi('0.2').toString(); // 0.02 +``` + +## API + +| 名称 | 说明 | +| ------------------- | ------------------ | +| `add(value)` | 加上另一个小数值。 | +| `multi(value)` | 乘以另一个小数值。 | +| `negate()` | 返回相反数。 | +| `equal(value)` | 判断是否相等。 | +| `lessEquals(value)` | 判断当前值是否小于或等于另一个小数值。 | + +## 本地开发 + +```bash +npm install +npm test +npm run lint +npm run tsc +npm run compile +``` + +本地 dumi 站点默认运行在 `http://localhost:8000`. + +## 发布 + +```bash +npm run prepublishOnly +``` + +发布流程通过 `@rc-component/np` 提供的 `rc-np` 命令处理。 + +## 许可证 + +@rc-component/mini-decimal 基于 [MIT](./LICENSE) 协议发布。 diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..40f08ec --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,115 @@ +import js from '@eslint/js'; +import { defineConfig } from 'eslint/config'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import prettier from 'eslint-config-prettier'; +import jest from 'eslint-plugin-jest'; +import react from 'eslint-plugin-react'; +import reactHooks from 'eslint-plugin-react-hooks'; +import globals from 'globals'; +import tseslint from 'typescript-eslint'; + +const tsconfigRootDir = dirname(fileURLToPath(import.meta.url)); + +export default defineConfig([ + { + plugins: { + '@typescript-eslint': tseslint.plugin, + }, + }, + { + linterOptions: { + reportUnusedDisableDirectives: 'warn', + }, + }, + { + ignores: [ + 'node_modules/', + 'coverage/', + 'es/', + 'lib/', + 'dist/', + 'docs-dist/', + '.docs-dist/', + '.dumi/', + '.doc/', + '.vercel/', + ], + }, + { + files: ['**/*.{js,jsx,ts,tsx}'], + extends: [ + js.configs.recommended, + react.configs.flat.recommended, + react.configs.flat['jsx-runtime'], + prettier, + ], + plugins: { + 'react-hooks': reactHooks, + }, + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + }, + }, + settings: { + react: { + version: 'detect', + }, + }, + rules: { + 'no-async-promise-executor': 'off', + 'no-empty-pattern': 'off', + 'no-irregular-whitespace': 'off', + 'no-prototype-builtins': 'off', + 'no-useless-escape': 'off', + 'no-extra-boolean-cast': 'off', + 'no-undef': 'off', + 'no-unused-vars': 'off', + 'react/no-find-dom-node': 'off', + 'react/display-name': 'off', + 'react/no-unknown-property': 'off', + 'react/prop-types': 'off', + 'react-hooks/exhaustive-deps': 'warn', + 'react-hooks/rules-of-hooks': 'error', + }, + }, + { + files: ['**/*.{ts,tsx}'], + extends: [...tseslint.configs.recommended], + rules: { + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-object-type': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-unnecessary-type-constraint': 'off', + '@typescript-eslint/no-unused-vars': 'off', + }, + }, + { + files: ['src/**/*.{ts,tsx}'], + languageOptions: { + parserOptions: { + projectService: true, + tsconfigRootDir, + }, + }, + }, + { + files: ['tests/**/*.{js,jsx,ts,tsx}', '**/*.{test,spec}.{js,jsx,ts,tsx}'], + extends: [jest.configs['flat/recommended']], + rules: { + 'jest/no-disabled-tests': 'off', + 'jest/no-done-callback': 'off', + 'jest/no-identical-title': 'off', + 'jest/expect-expect': 'off', + 'jest/no-alias-methods': 'off', + 'jest/no-conditional-expect': 'off', + 'jest/no-export': 'off', + 'jest/no-standalone-expect': 'off', + 'jest/valid-expect': 'off', + 'jest/valid-title': 'off', + }, + }, +]); diff --git a/package.json b/package.json index 4b192ba..54345fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@rc-component/mini-decimal", "version": "1.1.4", - "description": "Lite lib to only support decimal add calculation", + "description": "🧮 Small decimal calculator for precise string-based arithmetic.", "keywords": [ "decimal" ], @@ -30,35 +30,42 @@ "coverage": "rc-test --coverage", "lint": "eslint src/ --ext .tsx,.ts", "lint:tsc": "tsc -p tsconfig.json --noEmit", - "now-build": "npm run docs:build", "prepublishOnly": "npm run compile && rc-np", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", "start": "dumi dev", "test": "rc-test", - "watch": "father dev" + "watch": "father dev", + "build": "dumi build", + "tsc": "npm run lint:tsc" }, "dependencies": { - "@babel/runtime": "^7.18.0" + "@babel/runtime": "^7.29.7" }, "devDependencies": { + "@eslint/js": "^9.39.4", "@rc-component/father-plugin": "^2.2.0", "@rc-component/np": "^1.0.4", - "@testing-library/jest-dom": "^6.1.5", - "@testing-library/react": "^16.1.0", - "@types/jest": "^29.5.12", - "@types/node": "^22.1.0", - "@types/react": "^18.3.12", - "@types/react-dom": "^18.3.1", - "@umijs/fabric": "^4.0.1", - "dumi": "^2.3.8", - "eslint": "^8.57.0", - "father": "^4.4.4", + "@testing-library/jest-dom": "^6.9.1", + "@testing-library/react": "^16.3.2", + "@types/jest": "^30.0.0", + "@types/node": "^26.0.1", + "@types/react": "^19.2.17", + "@types/react-dom": "^19.2.3", + "dumi": "^2.4.38", + "eslint": "^9.39.4", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-jest": "^29.15.4", + "eslint-plugin-react": "^7.37.5", + "eslint-plugin-react-hooks": "^7.1.1", + "father": "^4.6.24", "gh-pages": "^6.1.1", - "prettier": "^3.3.3", - "react": "^18.0.0", - "react-dom": "^18.0.0", - "rc-test": "^7.0.15", - "typescript": "^5.4.5" + "globals": "^17.7.0", + "prettier": "^3.9.4", + "rc-test": "^7.1.3", + "react": "^19.2.7", + "react-dom": "^19.2.7", + "typescript": "^6.0.3", + "typescript-eslint": "^8.62.1" }, "engines": { "node": ">=8.x" diff --git a/src/MiniDecimal.ts b/src/MiniDecimal.ts index 34e47d6..90ff97d 100644 --- a/src/MiniDecimal.ts +++ b/src/MiniDecimal.ts @@ -1,13 +1,14 @@ -/* eslint-disable max-classes-per-file */ +/* eslint @typescript-eslint/consistent-type-exports: off */ -import BigIntDecimal from './BigIntDecimal'; -import NumberDecimal from './NumberDecimal'; +import BigIntDecimalBase from './BigIntDecimal'; +import NumberDecimalBase from './NumberDecimal'; import type { DecimalClass, ValueType } from './interface'; import { trimNumber } from './numberUtil'; import { supportBigInt } from './supportUtil'; // Still support origin export -export { NumberDecimal, BigIntDecimal }; +export const NumberDecimal = NumberDecimalBase; +export const BigIntDecimal = BigIntDecimalBase; export type { DecimalClass, ValueType }; diff --git a/src/index.ts b/src/index.ts index c63a3a2..ae3e66d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +/* eslint @typescript-eslint/consistent-type-exports: off */ + import getMiniDecimal from './MiniDecimal'; export * from './MiniDecimal'; import { diff --git a/tsconfig.json b/tsconfig.json index 5fbc200..05144a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,17 @@ { "compilerOptions": { "target": "esnext", - "moduleResolution": "node", - "baseUrl": "./", + "strict": false, + "moduleResolution": "bundler", "jsx": "preserve", "declaration": true, "skipLibCheck": true, "esModuleInterop": true, "types": ["@testing-library/jest-dom", "node", "jest"], "paths": { - "@/*": ["src/*"], - "@@/*": ["src/.umi/*"], - "@rc-component/portal": ["src/Portal.tsx"] + "@/*": ["./src/*"], + "@@/*": ["./src/.umi/*"], + "@rc-component/portal": ["./src/Portal.tsx"] } }, "include": [ diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..e884e1b --- /dev/null +++ b/vercel.json @@ -0,0 +1,6 @@ +{ + "framework": "umijs", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "dist" +}