React Utils for GateWeb
npm install @gateweb/react-utils@gateweb/react-utils 是 GateWeb 的 TypeScript-first utility library,包含常用的 functions / hooks / types(日期、格式化、轉換、驗證、web、React hooks 等),並且有測試與自動化文件。
> This repo also provides a docs site + auto-generated API reference.

- React Hooks: A collection of useful hooks like useCountdown and useValue.
- Date Utilities: Powerful and flexible functions for handling dates and time periods, built on top of dayjs.
- Core Helpers: A wide range of utilities for type conversion (bytes, searchParams), case style formatting, object manipulation, and more.
- Web APIs: Simplified functions for common web tasks like file downloads (download) and managing browser storage (webStorage).
- Validation: A set of predefined regex patterns and validation functions for common data types.
- TypeScript First: Fully written in TypeScript, providing excellent type safety and autocompletion out of the box.
- Lightweight & Tree-Shakable: Built with bunchee to ensure minimal bundle size.
``bashWith pnpm (recommended)
pnpm add @gateweb/react-utils
🚀 快速開始(Quick Start)
`ts
import { bytesToSize } from '@gateweb/react-utils';bytesToSize(1024);
`更多範例與用法請看 react-utils docs
🤝 Contributing
Contributions are welcome! To ensure a smooth development process, please follow these steps:
1. Fork & Clone: Fork the repository and clone it to your local machine.
2. Set Up: This project uses
pnpm as the package manager. Install dependencies with:
`bash
pnpm install
`
3. Develop: Create a new branch for your feature or bug fix.
4. Test: Write tests for your changes and ensure all existing tests pass.
`bash
# Run all tests
pnpm test # Run tests in watch mode
pnpm test:watch
`5. Submit a Pull Request: Push your changes to your fork and open a pull request to the
main branch. Your code will be automatically linted and formatted upon commit.Publishing (For Maintainers)
$3
1. Update the version in
package.json.
2. Install dependencies and build the package:
`sh
pnpm install && pnpm build
`
3. Log in to npm:
`sh
pnpm login
`
4. Publish the package:
`sh
pnpm publish --access public --no-git-checks
`$3
When a pull request is merged into the
main branch, the release GitHub Action will automatically bump the version, create a changelog, and publish the new version to npm. The version bump follows Semantic Versioning based on the commit messages (e.g., feat: for minor, fix:` for patch).