https://github.com/neki-dev/digital-mask
🧩 Easy digital mask for string and inputs
https://github.com/neki-dev/digital-mask
digital format input mask number pattern
Last synced: 3 months ago
JSON representation
🧩 Easy digital mask for string and inputs
- Host: GitHub
- URL: https://github.com/neki-dev/digital-mask
- Owner: neki-dev
- License: mit
- Created: 2021-02-26T09:32:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-04T23:08:57.000Z (almost 2 years ago)
- Last Synced: 2025-10-19T13:31:35.725Z (8 months ago)
- Topics: digital, format, input, mask, number, pattern
- Language: TypeScript
- Homepage:
- Size: 242 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## âš¡ Digital mask
[](https://npmjs.com/package/digital-mask)
[](https://github.com/neki-dev/digital-mask/blob/master/dist/index.js)
[](https://github.com/neki-dev/digital-mask/actions/workflows/test.yml)
[](https://github.com/neki-dev/digital-mask/actions/workflows/build.yml)
Easy digital mask for string and inputs
.
* ### Install
```sh
npm i digital-mask
```
* ### Usage
```js
/**
* Return masked value from source string
*/
applyStringMask(
// Unformatted string
source: string,
// Mask for format
format: string,
// Сhar from replace
def: string = '_'
): string
/**
* Update input value to masked
*/
applyInputMask(
// Input
input: HTMLInputElement,
// Mask for format
format: string,
// Сhar from replace
def: string = '_'
): void
```
* ### Example for string
```ts
import { applyStringMask } from 'digital-mask';
applyStringMask('1234', '___-___');
// => 123-4__
applyStringMask('1234', '***-***', '*');
// => 123-4**
applyStringMask('chars1234and56', '___-___');
// => 123-456
```
* ### Example for input
```ts
import { applyInputMask } from 'digital-mask';
const input = document.getElementById('inputPhone');
input.addEventListener('input', (event) => {
applyInputMask(event.target, '___-___');
});
```