@spenserca/scrub-a-dub-dub
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

scrub-a-dub-dub

A utility for marking object properties for data sanitization

Usage

This library provides these defaults to apply during scrubbing:

type default
string ********
number 8675309
Date 12/31/9999
all others ********

You can use the default values by following these steps:

  1. For a given class mark properties that you want scrubbed with the @scrub decorator

    export class SomeClass {
      @scrub()
      propertyToScrub: string;
    
      constructor (message: string) {
        this.propertyToScrub = message;
      }
    }
  2. Scrub the object by calling scrubObject

    const scrubbed = scrubObject(new SomeClass('hello world'));
  3. Any properties that are marked should be scrubbed

    console.log(scrubbed.propertyToScrub); // logs the default scrubbed string '********' and not 'hello world'

Alternatively, you can provide your own scrubbing function to the decorator to override the default scrubbing methods:

  1. For a given class mark properties that you want scrubbed with the @scrub decorator

    export class SomeClass {
      @scrub({
        scrubFunction: () => 'spenser was not here'
      })
      propertyToScrub: string;
    
      constructor (message: string) {
        this.propertyToScrub = message;
      }
    }
  2. Scrub the object by calling scrubObject

    const scrubbed = scrubObject(new SomeClass('hello world'));
  3. Any properties that are marked should be scrubbed

    console.log(scrubbed.propertyToScrub); // logs the override's scrubbed string 'spenser was not here' and not 'hello world'

Readme

Keywords

Package Sidebar

Install

npm i @spenserca/scrub-a-dub-dub

Weekly Downloads

35

Version

1.2.2

License

MIT

Unpacked Size

16.5 kB

Total Files

22

Last publish

Collaborators

  • spenserca