Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

manual-data-masking

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manual-data-masking

A super light javascript library for manual data masking

  • 0.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

A super light javascript library for manual datamasking.

Manual data masking ?

Manual data masking is an operation that label and hide sensitive data, create new text that hides (masks) sensitive information.

Imagine that there is a customer comment which includes sensitive data like swear word, person name, home address...

e.g.

Damn it, The phone i just bought last week has been broken 😠, I need refund
right now, Call me on this phone number: 080808080.

By using manual-data-masking you can do manual data masking job like this:

Of course, data masked and text after data masking will be generated by manual-data-masking at the same time:

data masked:

[
  {
    content: "Damn it",
    category: "Person Name",
    start: 0, // start index in text string
    end: 7, // start index in text string
  },
  {
    content: "080808080",
    category: "Phone Number",
    start: 120,
    end: 129,
  },
];

text after data masking:

*******, The phone i just bought last week has been broken 😠, I need refund
right now, Call me on this phone number: *********.

Online preview

Edit on CodeSandbox

How to use in your project

ES modules

npm install manual-data-masking
import { create as createManualDataMasking } from "manual-data-masking";

const dataMasked = [
  {
    "content": "Damn it",
    "category": "Person Name",
    "start": 0,
    "end": 7
  }
]

const categories = [
  {
    "value": "Person Name",
    "color": "#b6656c"
  },
  {
    "value": "Swear Word",
    "color": "#577eba"
  },
  {
    "value": "Phone Number",
    "color": "#3e6146"
  }
]

const text = "Damn it, The phone i just bought last week has been broken 😠, \n I need refund right now, Call me on this phone number: 080808080."

const $manualDataMasking = createManualDataMasking({
  container: document.getElementById("demo"),
  text,
  dataMasked,
  categories,
  replaceCharactor: "*",
  dataMaskingCharactor: "X",
  maxHeight: 100
})

$manualDataMasking.on("afterDataMasking", (dataMasked, textAfterDataMasking) => {
  console.log(JSON.stringify(dataMasked));
  console.log(textAfterDataMasking);
})
</script>

Script tag:

<script src="https://unpkg.com/manual-data-masking"></script>

<script>
  const dataMasked = [
    {
      content: "Damn it",
      category: "Person Name",
      start: 0,
      end: 7,
    },
  ];

  const categories = [
    {
      value: "Person Name",
      color: "#b6656c",
    },
    {
      value: "Swear Word",
      color: "#577eba",
    },
    {
      value: "Phone Number",
      color: "#3e6146",
    },
  ];

  const text =
    "Damn it, The phone i just bought last week has been broken 😠, \n I need refund right now, Call me on this phone number: 080808080.";

  const $manualDataMasking = manualDataMasking.create({
    container: document.getElementById("demo"),
    text,
    dataMasked,
    categories,
    replaceCharactor: "*",
    dataMaskingCharactor: "X",
    maxHeight: 100,
  });

  $manualDataMasking.on(
    "afterdataMasking",
    (dataMasked, textAfterDataMasking) => {
      console.log(JSON.stringify(dataMasked));
      console.log(textAfterDataMasking);
    }
  );
</script>

Options

PropertyDescriptionTypeRequiredDefault
categoriesCategories of sensitive data.
e.g.
[{
  value: "Person Name",
  color: "#3e6146"
},
{
  value: "Bad word"
}]
// if you don't set color property, the default color will be #577eba
arraytruenull
containerContainer dom element.Dom Element Objecttruenull
dataMaskedSensitive data been masked.
e.g.
[{
  content: "Damn it",
  category: "Person Name",
  start: 0, // start index in text string
  end: 7, // end index in text string
 }]
arrayfalse[]
dataMaskingCharactorCharactor in data masking. entitystringfalse'●'
maxHeightMax height of container, you can scroll the content if the height of container is over maxHeight.numberfalsenull
replaceCharactorCharactor be used to replace the sensitive. datastringfalse"*"
textOrigin text content.
Notice: please use \n in where you want to wrap a new line
stringtruenull

Instance functions

NameDescription
getDataMaskedGet sensitive data been masked
$manualDataMasking.getDataMasked()
getTextAfterDataMaskingGet text after data masking
$manualDataMasking.getTextAfterDataMasking()

Events

Event NameDescription
afterDataMaskingRegistered callback functions will be triggered when new sensitive data been masked. Value of text after masking and data msked can be used inside of the callback function.

$manualDataMasking.on( "afterdataMasking", (dataMasked, textAfterDataMasking) => {
  console.log(JSON.stringify(dataMasked));
  console.log(textAfterDataMasking);
});

Build Setup

# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build

Keywords

FAQs

Package last updated on 01 Jun 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc