Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
text-mask-addons
Advanced tools
The text-mask-addons npm package provides a set of useful add-ons for the text-mask library, which is used to create input masks for form fields. These add-ons include pre-defined masks for common input types such as phone numbers, email addresses, and dates.
createNumberMask
The createNumberMask function allows you to create a mask for numeric inputs. This is useful for formatting currency, percentages, or any other numerical input.
const createNumberMask = require('text-mask-addons/dist/createNumberMask');
const numberMask = createNumberMask({
prefix: '$',
suffix: '',
includeThousandsSeparator: true,
thousandsSeparatorSymbol: ',',
allowDecimal: true,
decimalSymbol: '.',
decimalLimit: 2,
integerLimit: 7,
allowNegative: false,
allowLeadingZeroes: false
});
emailMask
The emailMask is a pre-defined mask for email addresses. It ensures that the input follows the general structure of an email address.
const emailMask = require('text-mask-addons/dist/emailMask');
const maskedInput = emailMask;
createAutoCorrectedDatePipe
The createAutoCorrectedDatePipe function creates a pipe that auto-corrects date input as the user types. This is useful for ensuring that dates are entered in a valid format.
const createAutoCorrectedDatePipe = require('text-mask-addons/dist/createAutoCorrectedDatePipe');
const autoCorrectedDatePipe = createAutoCorrectedDatePipe('mm/dd/yyyy');
react-text-mask is a library for creating input masks in React applications. It provides similar functionality to text-mask-addons but is specifically designed for use with React components.
Cleave.js is a JavaScript library for formatting input fields. It offers a wide range of formatting options, including credit card numbers, phone numbers, dates, and more. Cleave.js provides more flexibility and customization options compared to text-mask-addons.
inputmask is a library for creating input masks in JavaScript. It supports a wide range of input types and provides extensive customization options. Inputmask is more feature-rich and versatile compared to text-mask-addons.
These addons are ready-to-use pipes and masks that can be used with Text Mask.
npm i text-mask-addons --save
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:
prefix
(string): what to display before the amount. Defaults to '$'
.suffix
(string): what to display after the amount. Defaults to empty string.includeThousandsSeparator
(boolean): whether or not to separate thousands. Defaults to to true
.thousandsSeparatorSymbol
(string): character with which to separate thousands. Default to ','
.allowDecimal
(boolean): whether or not to allow the user to enter a fraction with the amount. Default to false
.decimalSymbol
(string): character that will act as a decimal point. Defaults to '.'
decimalLimit
(number): how many digits to allow after the decimal. Defaults to 2
integerLimit
(number): limit the length of the integer number. Defaults to null
for unlimitedrequireDecimal
(boolean): whether or not to always include a decimal point and placeholder for decimal digits
after the integer. Defaults to false
.allowNegative
(boolean): whether or not to allow negative numbers. Defaults to false
allowLeadingZeroes
(boolean): whether or not to allow leading zeroes. Defaults to false
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.
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.
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.
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
.
import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe'
const autoCorrectedDatePipe = createAutoCorrectedDatePipe('mm/dd/yyyy')
// As you can see in the line above, you can pass a string argument to `createAutoCorrectedDatePipe`
// to give it the order of day, month, and year in your `mask`.
// ...now you can pass `autoCorrectedDatePipe` to the Text Mask component as the `pipe`
FAQs
Addons for Text Mask https://github.com/text-mask/text-mask
The npm package text-mask-addons receives a total of 105,713 weekly downloads. As such, text-mask-addons popularity was classified as popular.
We found that text-mask-addons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.