@formio/text-mask-addons

中文文档
3.8.0-formio.4发布于 2024/11/16UnlicenseTypeScriptCommonJS零依赖近 30 天下载 32.4万
原始使用文档
文档目录6 节
  1. Installation
  2. Masks
  3. createNumberMask
  4. emailMask
  5. Pipes
  6. createAutoCorrectedDatePipe

Text Mask Addons

These addons are ready-to-use pipes and masks that can be used with Text Mask.

Installation

npm i text-mask-addons --save

Masks

These can be passed as a mask to Text Mask.

createNumberMask

createNumberMask returns a numberMask function that will format user input as currency. createNumberMask accepts an object with the following keys:

  1. prefix (string): what to display before the amount. Defaults to '$'.
  2. suffix (string): what to display after the amount. Defaults to empty string.
  3. includeThousandsSeparator (boolean): whether or not to separate thousands. Defaults to to true.
  4. thousandsSeparatorSymbol (string): character with which to separate thousands. Default to ','.
  5. allowDecimal (boolean): whether or not to allow the user to enter a fraction with the amount. Default to false.
  6. decimalSymbol (string): character that will act as a decimal point. Defaults to '.'
  7. decimalLimit (number): how many digits to allow after the decimal. Defaults to 2
  8. integerLimit (number): limit the length of the integer number. Defaults to null for unlimited
  9. requireDecimal (boolean): whether or not to always include a decimal point and placeholder for decimal digits after the integer. Defaults to false.
  10. allowNegative (boolean): whether or not to allow negative numbers. Defaults to false
  11. allowLeadingZeroes (boolean): whether or not to allow leading zeroes. Defaults to false

Usage

import createNumberMask from 'text-mask-addons/dist/createNumberMask'

// First, you need to create the `numberMask` with your desired configurations
const numberMask = createNumberMask({
  prefix: '',
  suffix: ' $' // This will put the dollar sign at the end, with a space.
})

// ...then pass `numberMask` to the Text Mask component as the mask

emailMask

emailMask formats user input as an email address.

Usage

import emailMask from 'text-mask-addons/dist/emailMask'

// ...then pass `emailMask` to the Text Mask component as the mask

Technical side note: even though emailMask is passed as a mask, it is actually made of both a mask and a pipe bundled together for convenience. The Text Mask component knows how to unwrap and separate the pipe and mask functions to use them.

Pipes

These functions here can be passed as a pipe to Text Mask.

createAutoCorrectedDatePipe

The createAutoCorrectedDatePipe returns a autoCorrectedDatePipe, which can help the user in entering a date. The createAutoCorrectedDatePipe accepts a string specifying date format and an object with the following keys:

  1. minYear (number): the minimum year allowed in the date field mask.
  2. maxYear (number): the maximum year allowed in the date field mask.

For example, if the user enters a value larger than 1 in the 1st slot of month, it appends 0 to it. That is 4 => 04. It does a similar thing for the day slots.

It also blocks the user from entering invalid days or months such as 33/44.

For createAutoCorrectedDatePipe to work properly, the Text Mask component needs to be configured with keepCharPositions set to true.

Usage

import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe'

const autoCorrectedDatePipe = createAutoCorrectedDatePipe('mm/dd/yyyy HH:MM')
// As you can see in the line above, you can pass a string argument to `createAutoCorrectedDatePipe` 
// to give it the order of day, month, year, hour and minute in your `mask`.

// ...now you can pass `autoCorrectedDatePipe` to the Text Mask component as the `pipe`

版本与发布记录

@formio/text-mask-addons 共发布 3 个版本,首次发布于 2022/09/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.8.0-formio.4latest2024/11/162 年前
3.8.0-formio.32024/10/292 年前
3.8.0-formio.22022/09/144 年前

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

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

Addons for Text Mask https://github.com/text-mask/text-mask

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

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

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

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

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

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

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

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

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

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

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

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