max-mask
Version:
Simple masking solution for any frontend as well as nodejs. Provides composable for Vue3
68 lines (43 loc) • 1.45 kB
Markdown
A simple masking solution for frontend applications as well as NodeJS. This package also provides a Vue3 composable for easier integration into Vue projects.
You can install this package via npm or yarn.
```bash
npm install max-mask
```
```bash
yarn add max-mask
```
You can use the maskInput function to format strings according to a specified mask.
```js
import { maskInput } from "max-mask";
const formattedPhone = maskInput("1234567890", "(###) ###-####");
console.log(formattedPhone); // Output: (123) 456-7890
```
If you are working in a Vue3 environment, you can use the useMasking composable.
```js
import { useMasking } from "max-mask";
const { mask } = useMasking();
//example 1
const formattedPhone = mask("1234567890", "(###) ###-####");
//example 2
const input = ref("");
const formatted = computed(() => mask(input.value, "(###) ###-####"));
```
-
- U: Alphanumeric, converts to uppercase
- a: Letters, converts to lowercase
- A: Letters, converts to uppercase
- S: Alphanumeric, keeps the original case
- X: Alphanumeric, keeps the original case
- \*: Makes the previous pattern repeatable forever
Feel free to open issues and pull requests!
This project is licensed under the MIT License.
Created by Maksym max@kozachenko.io.