gitlon

gitlon 生态主包:聚合所有 @gitlon/* 子包并统一导出
1,840
Install
npm install gitlon
Latest Version:0.2.7
Vue:3
License:MIT
Last Updated:Oct 13, 2026
Links: npm
Maintainer: gitlon

gitlon

gitlon 主包,统一聚合 Gitlon 生态下的工具包。也可以只安装需要的子包,减少依赖范围。

安装

pnpm add gitlon

导入

主包转发各子包的命名导出:

import {
  onLoad,
  onShow,
  formatDate,
  formatMoney,
  isEmail,
  add,
} from 'gitlon'

默认导出仍是 GitlonHooks Vue 插件:

import gitlonHooks from 'gitlon'

app.use(gitlonHooks)

需要使用 dayjs 默认实例时,请从 @gitlon/time 直接导入:

import time from '@gitlon/time'

构建期使用的 Vite 插件从子路径 gitlon/vite 导入:

// vite.config.ts
import { buildVersionPlugin } from 'gitlon/vite'

export default defineConfig({
  plugins: [buildVersionPlugin()],
})

gitlon/vite 依赖 Node 内置模块,只能在 vite.config.ts 等 Node 环境导入;浏览器代码引入会让打包报 node:path 解析失败。

当前子包

包名 说明
@gitlon/hooks Vue 3 页面生命周期:onLoad / onShow
@gitlon/time dayjs 默认与命名导出
@gitlon/format 日期、数字、金额等展示格式化
@gitlon/validate 常用表单与业务校验
@gitlon/math 防精度丢失的四则运算与精度处理

API 总览

Hooks

import { onLoad, onShow } from 'gitlon'

onLoad((query) => {
  console.log(query) // Record<string, string> | undefined
})

onShow(() => {
  console.log('页面显示')
})

onLoad、onShow 必须在 Vue 组件 setup() 或 <script setup> 中同步调用。完整行为、Vue 插件配置和 <keep-alive> 用法见 @gitlon/hooks。

Format

import {
  formatDate,
  formatDateTime,
  formatMoney,
  formatNumber,
  formatPercent,
  formatFileSize,
  formatPhone,
  formatBankCard,
  formatString,
} from 'gitlon'

formatDate('2026-09-15')
formatMoney(1234567.8, { symbol: '¥' })
formatNumber(1234567.8, { decimals: 2 })
formatPercent(0.1234)
formatFileSize(1024)
formatPhone('13812345678', { mask: true })
formatBankCard('6222021234567890123', { mask: true })
formatString('  hello  ')

日期、金额、数字选项以及空值行为见 @gitlon/format。

Validate

import {
  isEmail,
  isPhone,
  isUrl,
  isIdCard,
  isBankCard,
  isNumber,
  isInteger,
  isPositiveNumber,
  isEmpty,
  isDate,
  isChinese,
  isEnglish,
  isSocialCreditCode,
  isPassword,
} from 'gitlon'

isEmail('user@example.com')       // { success: true, message: '' }
isPhone('12812345678')            // { success: false, message: '手机号格式不正确' }
isSocialCreditCode('91330100MA27X9Q42W')
isPassword('Gitlon123')

校验函数统一返回 { success, message } 结果对象,失败时 message 为对应文案,非法输入不会抛异常。完整规则和选项见 @gitlon/validate。

Math

import { add, subtract, multiply, divide, round, toFixed } from 'gitlon'

add(0.1, 0.2) // 0.3
subtract(1, 0.1) // 0.9
multiply(0.1, 0.2) // 0.02
divide(0.3, 0.1) // 3
round(1.005, 2) // 1.01
toFixed(1.2, 2) // '1.20'

完整参数、非法输入和多参数计算规则见 @gitlon/math。

直接使用子包

pnpm add @gitlon/format @gitlon/validate
import { formatMoney } from '@gitlon/format'
import { isEmail } from '@gitlon/validate'

直接安装子包适合只需要部分能力的项目;@gitlon/hooks 还需要项目提供 Vue 3,vue-router 为可选依赖。

Related Packages

@gitlon/hooks

面向 Vue3 项目的页面生命周期插件:提供与 uniapp 行为一致的 onLoad / onShow

291
@alova/adapter-uniapp

uniapp adapter for alova.js

40,899 4,022
vue3-hotkey

Hotkey Hooks for Vue3

19,819 31
@aplus-frontend/hooks

Vue hooks for Aplus frontend team.

11,237
@skiyee/oiyo

以融合AI协作、提升开发体验、降低使用心智为目的 UniApp 增强型工程框架

8,700 39

Version History

Version Released License
0.2.7 MIT
0.2.6 MIT
0.2.5 MIT
0.2.4 MIT
0.2.3 MIT