@formio/vanilla-text-mask

中文文档
5.1.1-formio.1发布于 2022/09/14UnlicenseCommonJS零依赖近 30 天下载 33.2万

JavaScript function that makes input HTML element accept mask pattern

原始使用文档
文档目录4 节
  1. Getting started
  2. Documentation
  3. Example
  4. Contributing

JavaScript Input Mask

Note: IE9 is not supported in this module.

Getting started

First, install it.

npm i vanilla-text-mask --save

Then, use it as follows:

<script
  type="text/javascript"
  src="./node_modules/vanilla-text-mask/dist/vanillaTextMask.js"></script>
<script type="text/javascript">
  var phoneMask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]

  // Assuming you have an input element in your HTML with the class .myInput
  var myInput = document.querySelector('.myInput')

  var maskedInputController = vanillaTextMask.maskInput({
    inputElement: myInput,
    mask: phoneMask
  })
  
  // Calling `vanillaTextMask.maskInput` adds event listeners to the input element. 
  // If you need to remove those event listeners, you can call
  maskedInputController.destroy()
</script>

Documentation

As you can see in the code above, you are passing an object to vanillaTextMask.maskInput(...).

The object takes inputElement, which is the <input/> element that you are masking. It also accepts other values which are documented here.

Example

To see an example of the code running, follow these steps:

  1. Clone the repo, git clone [email protected]:text-mask/text-mask.git
  2. cd text-mask
  3. npm install
  4. npm run vanilla:dev
  5. Open http://localhost:3000

The code of the example is in vanilla/example.

Contributing

We would love some contributions! Check out this document to get started.

版本与发布记录

@formio/vanilla-text-mask 共发布 2 个版本,首次发布于 2021/04/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.1.1-formio.1latest2022/09/144 年前
5.1.12021/04/205 年前

关于 @formio/vanilla-text-mask 的常见问题

@formio/vanilla-text-mask 是什么?

JavaScript function that makes input HTML element accept mask pattern

如何安装 @formio/vanilla-text-mask?

在项目目录运行 npm install @formio/vanilla-text-mask,或使用 pnpm add / yarn add / bun add。

@formio/vanilla-text-mask 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/formio__vanilla-text-mask 是否存在。

@formio/vanilla-text-mask 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@formio/vanilla-text-mask 可以商用吗?

@formio/vanilla-text-mask 使用 Unlicense 许可。作者将代码贡献到公共领域,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@formio/vanilla-text-mask 的下载量有多少?

根据 npm 官方下载统计,@formio/vanilla-text-mask 在 2026/10/16 – 2026/11/14 这 30 天内被下载 331,537 次,日均约 11,051 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formio/vanilla-text-mask 还在维护吗?

最新版本 5.1.1-formio.1 发布于 2022/09/14(4 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。