@alxhghs/stringmask
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

stringmask

Simple library for masking strings

Installation

npm install --save @alxhghs/stringmask

Usage

import { maskString } from "@alxhghs/stringmask";

let str = maskString("hello");
// *****
str = maskString("hello", { maskWith: "-" });
// -----
str = maskString("hello again", { unmaskedStartCharacters: 3 });
// hel********
str = maskString("123-00-0000", { unmaskedEndCharacters: 4 });
// *******0000
str = maskString("123-00-0000", { ignoreChars: ["-"] });
// ***-**-****
str = maskString("abcdefghijklmnopqrstuvwxyz123456", {
    ignoreChars: ["a-p", "1-3"],
});
// abcdefghijklmnop**********123***

Types

declare type Options = {
    maskWith?: string;
    unmaskedStartCharacters?: number;
    unmaskedEndCharacters?: number;
    ignoreChars?: string[];
};
export declare function maskString(text: string, options?: Options): string;

Options

Option Type Description Default
maskWith string Optional: character to use for masking *
unmaskedStartCharacters number Optional: number of unmasked characters at the start of the string 0
unmaskedEndCharacters number Optional: number of unmasked characters at the end of the string 0
ignoreChars string[] Optional: characters to leave unmasked []

Readme

Keywords

Package Sidebar

Install

npm i @alxhghs/stringmask

Weekly Downloads

2

Version

1.0.6

License

ISC

Unpacked Size

6.07 kB

Total Files

5

Last publish

Collaborators

  • alxhghs