master-utils-lib
v1.0.2
Published
A professional, lightweight, and compatible utility library for H5 and PC web development with TypeScript support
Maintainers
Readme
H5 Utils Lib
A professional, lightweight, and compatible utility library for H5 and PC web development.
Features
- 📱 Mobile First: Optimized for iOS and Android (compatible down to iOS 9, Android 4.4).
- 💻 PC Compatible: Supports IE11+ and modern browsers.
- 📦 Tree Shaking: ES Module support for smaller bundle sizes.
- 🛡️ TypeScript: Full type definitions included.
- 🔧 Developer Friendly: Includes source code and development tools for easy extension.
Installation
作为依赖使用
npm install h5-utils-lib
# 或
yarn add h5-utils-lib
# 或
pnpm add h5-utils-lib作为开发模板使用
安装后,你可以直接基于此项目继续开发:
npm install h5-utils-lib
cd node_modules/h5-utils-lib
npm install # 安装开发依赖
npm run build # 构建项目
npm test # 运行测试或者直接克隆项目到本地进行开发。
Usage
ES Modules (Vue/React/Vite/Webpack)
import { isIOS, getQueryString, formatMoney } from 'h5-utils-lib';
if (isIOS()) {
console.log('Running on iOS');
}
const id = getQueryString('id');
const price = formatMoney(1234.56); // ¥1,234.56Browser ()
<script src="path/to/h5-utils-lib/dist/index.min.js"></script>
<script>
if (H5Utils.isIOS()) {
console.log('Running on iOS');
}
</script>API
Device
isIOS(): Check if device is iOS.isAndroid(): Check if device is Android.isWeChat(): Check if running in WeChat.
URL
getQueryString(name): Get URL parameter by name.stringifyQuery(obj): Convert object to query string.
Storage
setStorage(key, value, expire?): Set LocalStorage with optional expiration (ms).getStorage(key): Get value from LocalStorage (returns null if expired).removeStorage(key): Remove item.
Format
formatMoney(amount, decimals?, symbol?): Format number as currency.formatDate(date, fmt?): Format date (default YYYY-MM-DD).
Validate
isPhone(phone): Validate Chinese phone number.isEmail(email): Validate email address.
Development
如果你想基于此项目继续开发或扩展功能,请查看 开发指南。
快速开始
# 安装依赖
npm install
# 开发模式(监听文件变化)
npm run dev
# 构建项目
npm run build
# 运行测试
npm test
# 测试覆盖率
npm run test:coverage项目结构
src/- 源代码目录tests/- 测试文件dist/- 构建输出(自动生成)rollup.config.js- 构建配置tsconfig.json- TypeScript 配置jest.config.js- 测试配置
License
ISC
