@shuaijg/utils
v0.3.0
Published
TypeScript utils & Vue3 hooks for admin / AI apps (tree-shakable, zero runtime deps for core utils)
Maintainers
Readme
@shuaijg/utils
百度云项目通用 TypeScript 工具库(utils + Vue3 hooks)。
版本 0.3.0 — 封装完成清单
纯函数 import { ... } from '@shuaijg/utils'
| 模块 | 函数 |
|------|------|
| array | unique, orderBy, groupBy |
| object | cloneDeep, merge |
| function | sleep, debounce, throttle, retry |
| string | capitalize, kebabCase, truncate, trimObjectStrings |
| storage | createStorage, localStorageCache |
| date | formatDateTime, parseApiTime, fromNow |
| format | formatBytes, formatDuration, formatPercent |
| validate | isEmpty, isUrl, isEmail |
| auth | isValidTokenString, decodeJwtPayload, isTokenExpired, isAuthEndpoint, isUnauthorizedError, toBearerToken, saveLoginRedirect, consumeLoginRedirect, resolvePostLoginPath, createUnauthorizedHandler |
| form | normalizePageQuery, toApiPagination, fromApiPageResult, omitEmpty |
| ops | parsePm2Status, formatDeployOutput, formatSmokeResult |
| env | isProd, getEnv, getRuntimePlatform, getUniPlatform |
| stream | readTextStream, parseSseLines, extractStreamDelta |
| mask | maskEmail, maskPhone |
| url | joinUrl, buildServerUrl, toQueryString |
| clipboard | copyText |
| download | downloadText, downloadJson |
Vue Hooks import { ... } from '@shuaijg/utils/hooks'
| Hook | 说明 |
|------|------|
| useOnPageShow | 进入页 / KeepAlive / Tab 切回时刷新(需 vue-router) |
| useCopy | 复制 + 成功/失败回调 |
| usePolling | 定时轮询 |
| useConfirmAction | 确认 → 执行 → 回调 |
| useLocalStorage | 响应式本地存储 |
| useUnauthorized | 401 统一处理(UI 由业务注入) |
| useEventSource | SSE |
| useStreamFetch / readFetchStream | AI 流式 fetch |
| useDark / useMediaQuery / useWindowSize | 布局与环境 |
子路径 @shuaijg/utils/alias
别名导出,避免与业务同名冲突。
本地命令
cd learn-npm-utils
pnpm install
pnpm test
pnpm build
pnpm play # http://localhost:5178发布到 npm
package.json 已配置 publishConfig(public scoped 包)。不会发布 src/、playground/、.env,仅 dist/。
npm login # 邮箱 OTP 验证码
npm whoami
npm publish --access public安装:pnpm add @shuaijg/utils
业务接入(尚未做)
- [ ]
pnpm link @shuaijg/utils到 ai-admin / ai-assistant - [ ] 逐步替换页面内联工具函数
- [x]
package.json发布配置(publishConfig+files仅 dist) - [ ] 本机执行
npm publish --access public
