- Notifications
You must be signed in to change notification settings - Fork21
一个面向业务的 JavaScript/TypeScript 实用程序库。支持在浏览器、Node.js、小程序、Taro、Deno 下使用。
License
fjc0k/vtils
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
一个面向业务的 JavaScript/TypeScript 实用程序库。
import{md5}from'vtils'console.log(md5('龙'))// => 682570a229cbd3d67e76ad99b3152060
🙅♀️ 拒绝重复:基于社区优质程序库(Lodash、date-fns、react-use、type-fest、ts-essentials、yup 等),补充常用业务代码。
🌸 精致优雅:为每一个工具都添加了注释、测试,不看文档亦可直接使用。
🌈 面向未来:使用TypeScript 编写,支持Tree Shaking、ECMAScript Modules,也可以在Taro 3、Deno 中使用。
# npmnpm i vtils# yarnyarn add vtils# pnpmpnpm add vtils
若在国内,推荐安装tbify 使用淘宝镜像加速:
# npmtnpm i vtils# yarntyn add vtils# pnpmtpm add vtils
// 基础工具库import{wait,isNumber,EventBus,base64Encode}from'vtils'// 日期时间工具库import{formatRelative,subDays,zhCN}from'vtils/date'// React 工具库import{useClassName,useToggle,useScrollLoadMore}from'vtils/react'// 验证工具库import{yup}from'vtils/validator'// 类型工具库import{OmitStrict,LiteralUnion,PartialDeep}from'vtils/types'// 小程序工具库import{getTopBarInfo,navigatePageTo,redirectPageTo}from'vtils/mp'
详细用法见文档:https://fjc0k.github.io/vtils/v4/。
在Taro 3 中使用前需要修改 Webpack 配置,在config/index.js
中的mini
字段下设置:
mini:{webpackChain(config){// 该插件会影响 resolve.extensions 的表现,删去config.resolve.plugins.delete('MultiPlatformPlugin')// 支持 .taro.js 后缀config.resolve.extensions.prepend('.taro.js')},}
然后,就可以愉快地使用了:
// React 工具库import{useSearchParam}from'vtils/react'// 小程序工具库import{useTopBarInfo}from'vtils/mp'exportdefaultfunction(){constid=+useSearchParam('id')!consttopBarInfo=useTopBarInfo()// ...}
Deno 下暂只支持基础工具库。
// 基础工具库import{wait,isNumber,EventBus,base64Encode,}from'https://cdn.skypack.dev/vtils@4.131.0'
你可在本地或https://labs.play-with-docker.com/ 上运行下面的命令,然后打开http://localhost:9099
,接着选择你需要的工具,最后点击开始打包,等待请求执行完成后即可获取仅包含选中工具的 js 代码以及对应的类型定义。
docker run --rm -p 9099:9099 jayfong/vtils
Jay Fong (c) MIT
About
一个面向业务的 JavaScript/TypeScript 实用程序库。支持在浏览器、Node.js、小程序、Taro、Deno 下使用。
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.