🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More
Socket
Book a DemoInstallSign in
Socket

vtils

Package Overview
Dependencies
Maintainers
1
Versions
544
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vtils

一个面向业务的 JavaScript/TypeScript 实用程序库。

latest
Source
npmnpm
Version
4.136.0
Version published
Weekly downloads
1.1K
18.19%
Maintainers
1
Weekly downloads
 
Created
Source

vtils Test Coverage

一个面向业务的 JavaScript/TypeScript 实用程序库。

文档:https://fjc0k.github.io/vtils/v4/

测试报告:https://fjc0k.github.io/vtils/v4-coverage/

import { md5 } from 'vtils'

console.log(md5('龙'))
// => 682570a229cbd3d67e76ad99b3152060

特性

安装

# npm
npm i vtils

# yarn
yarn add vtils

# pnpm
pnpm add vtils

若在国内,推荐安装 tbify 使用淘宝镜像加速:

# npm
tnpm i vtils

# yarn
tyn add vtils

# pnpm
tpm add vtils

使用

在 NodeJS 中使用

// 基础工具库
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 中使用

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'

export default function () {
  const id = +useSearchParam('id')!
  const topBarInfo = useTopBarInfo()
  // ...
}

在 Deno 中使用

Deno 下暂只支持基础工具库。

// 基础工具库
import {
  wait,
  isNumber,
  EventBus,
  base64Encode,
} from 'https://cdn.skypack.dev/vtils@4.136.0'

自定义打包

你可在本地或 https://labs.play-with-docker.com/ 上运行下面的命令,然后打开 http://localhost:9099,接着选择你需要的工具,最后点击开始打包,等待请求执行完成后即可获取仅包含选中工具的 js 代码以及对应的类型定义。

docker run --rm -p 9099:9099 jayfong/vtils

许可

Jay Fong (c) MIT

Keywords

util

FAQs

Package last updated on 31 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts