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

nested-mask-attributes

v1.1.1

Published

Library to hide or mask specific nested attributes that you desire from a javascript object

Downloads

4,601

Readme

npm version

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

Table of Contents

Install

npm install nested-mask-attributes

Usage

Example of masking attributes:

import {
  MaskActions,
  maskAttribute,
} from 'nested-mask-attributes';

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

const testObjectMask = maskAttribute(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,
  maskAttribute,
} from 'nested-mask-attributes';

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


const testObjectHide = maskAttribute(testObject, ["name", "isEnabled"], {
  action: MaskActions.HIDE,
});
// or
/* 
  const testObjectHide = maskAttribute(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

maskAttribute(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. | | 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] |

License

Author