npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hefty-mask-info

v2.0.3

Published

Another library to use for masking or deleting one or multiple nested attributes from a Javascript object.

Downloads

11

Readme

Hefty Mask Info

Another library to use for masking or deleting one or multiple nested attributes from a Javascript object.

Table of Contents

Install

npm install hefty-mask-info

Usage

Example of masking attributes

import {
  MaskActions,
  maskInfo,
} from 'hefty-mask-info';

// The object that has the attribute(s) to hide or mask
const testObject = {
  name: "hefty-mask-info",
  features: {
    id: "nm123456",
    date: "2021-10-01T14:36:06.265Z",
    isEnabled: true,
    author: {
      country: "Spain",
      name: "Rodrigo",
    }
  }
}

const testObjectMask = maskInfo(testObject, ["name", "isEnabled"], {
  action: MaskActions.MASK,
});

// RESULT
/*
  {
    name: "*****",
    features: {
      id: "nm123456",
      date: "2021-10-01T14:36:06.265Z",
      isEnabled: "****",
      author: {
        country: "Spain",
        name: "*****",
      }
    }
  }
*/

Example of hiding attributes

import {
  MaskActions,
  maskInfo,
} from 'hefty-mask-info';

// The object that has the attribute(s) to hide or mask
const testObject = {
  name: "hefty-mask-info",
  features: {
    id: "nm123456",
    date: "2021-10-01T14:36:06.265Z",
    isEnabled: true,
    author: {
      country: "Spain",
      name: "Rodrigo",
    }
  }
}


const testObjectHide = maskInfo(testObject, ["name", "isEnabled"], {
  action: MaskActions.HIDE,
});
// or
/* 
  const testObjectHide = maskInfo(testObject, ["name", "isEnabled"], {
    action: MaskActions.HIDE,
  });
*/

// RESULT
/*
  {
    features: {
      id: "nm123456",
      date: "2021-10-01T14:36:06.265Z",
      author: {
        country: "Spain",
      }
    }
  }
*/

Notes

If the attribute is contained in the object but it is of type "object" then it will not work. Admitted data types:

  • string
  • number
  • boolean
  • array

Methods

maskInfo(object, attributes, options);

  • object(any): The input object that you want to get the attribute(s) from. Any Javascript object is valid.

  • attributes(string[]): Array of attributes from which you want to mask or hide.

  • options(Options): There are different options:

| OPTIONS | TYPE | DESCRIPTION | |:--------------:|:-----------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | action | MaskAction (HIDE/MASK) | Action to execute when the attribute is found. | | urlParse | boolean (optional) | Default is false. If true, the url will be parsed and the attributes will be masked.| | substituteChar | string (optional) | Default is "*". Char or string to substitute current value. [It is only applied if the action is MaskActions.MASK] | | useSameLength | boolean (optional) | Default is false. Flag to indicate if the length of the string that will replace the original value of the attribute will keep the same length. If set to false, by default the length used is 5. [It is only applied if the action is MaskActions.MASK] | | useSameLength | boolean (optional) | Default is false. Flag to indicate if the length of the string that will replace the original value of the attribute will keep the same length. If set to false, by default the length used is 5. [It is only applied if the action is MaskActions.MASK] | | maskTimePropsNormally | boolean (optional) | Default is false. Flag to indicate if the time properties of the date object will be masked normally. See More. [It is only applied if the action is MaskActions.MASK] | | maskFromRight | boolean (optional) | Default is false. Flag to indicate if the masking will be done from right to left. [It is only applied if the action is MaskActions.MASK] | | fullLengthList | Array of string (optional) | Default is []. Flag to indicate if the list of attributes will be masked with the full length of the attribute. The list of attributes will be masked as "*".[It is only applied if the action is MaskActions.MASK] | | isMaskable | (value: any) => boolean (optional) | A callback that decides whether types are maskable. Should return true|false. Default function says no to objects and functions, yes to other types. [It is only applied if the action is MaskActions.MASK] |

Time & Date

mask-info can handle values that are Date objects without any problem. However, logging applications (e.g. Kibana) sometimes call new Date() on properties whose keys make them look like times/dates e.g. 'timeStamp' or 'createDate'. If called on an asterisked string this can lead to a wrong but misleading (and unmasked) date.

Therefore, to be on the safe side, if asked to mask properties like this maskInfo will return an empty string unless the option maskTimePropsNormally is set to true. If it is, properties with 'time' or 'date' in their keys will be masked normally as strings, e.g. masking { createTime: new Date(2013, 13, 1) } will return { createTime: '*******************************00 (GMT)' }.

Date objects with keys that do not have 'time' or 'date' in them will always be masked in this way regardless of the configured options.

License

MIT

Author

Md Nasir Uddin

Credits

  • Rodrigo Luque

  • George Maddocks

  • This library was generated with Nx.

Building

Run nx build hefty-mask-info to build the library.

Running unit tests

Run nx test hefty-mask-info to execute the unit tests via Jest.