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

@tdreyno/pii

v1.8.0

Published

[![Test Coverage](https://api.codeclimate.com/v1/badges/1c788782dac545f74307/test_coverage)](https://codeclimate.com/github/tdreyno/pii/test_coverage) [![npm latest version](https://img.shields.io/npm/v/@tdreyno/pii/latest.svg)](https://www.npmjs.com/pack

Downloads

14

Readme

pii

Test Coverage npm latest version Minified Size

pii is library for wrapping Personally Identifying Information and providing ways to limit its spread.

Installation

Yarn

yarn add @tdreyno/pii

NPM

npm install --save @tdreyno/pii

Usage

The concept is simple. Wrap PII around any PII data as soon as it enters your system.

import { PII, unwrapObject } from "@tdreyno/pii"

const handlePost = (postBody: { name: string; phoneNumber: string }) =>
  createUser(PII(postBody.name), PII(postBody.phoneNumber))

const createUser = (name: PII<string>, phoneNumber: PII<string>) =>
  sendToThirdParty(unwrapObject({ name, phoneNumber }))

PII wraps any data and obscures the details. Attempts to coerce it to other types or convert to JSON will result in a string result of PII<REDACTED>. Once the PII has flowed through your system, use unwrap to get the data back out for posting to a third party. Or unwrapObject which will recursively unwrap PII inside a post body object.

Avoiding unsafe unwrapping and rewrapping

If you want to combine two pieces of PII, such as first and last name, you might want to unwrap, combine and then rewrap them. Once you start using unwrap everywhere, it becomes very hard to maintain safetly. Rather, use the built in methods of this library to mutate and combine PII while keeping the data inside the wrapper.

Modify PII

import { PII, map } from "@tdreyno/pii"

const name = PII("Thomas")
const lowercaseName = map(n => n.toLowerCase(), name) // PII<"thomas">

Combine two things

import { PII, zip2With } from "@tdreyno/pii"

const firstName = PII("Thomas")
const lastName = PII("Reynolds")
const fullName = zip2With(
  (first, last) => `${first} ${last}`,
  firstName,
  lastName,
) // PII<Thomas Reynolds>

Note: There are methods for up to 4 PII inputs: zip2With, zip3With, zip4With.

Reduce a list of PII

import { PII, fold } from "@tdreyno/pii"

const address1 = PII(ADDRESS_OBJECT_1)
const address2 = PII(ADDRESS_OBJECT_2)
const address2 = PII(ADDRESS_OBJECT_2)

const allAddresses = fold(
  (acc, address) => (acc.push(address), acc),
  [],
  [address1, address2, address3],
) // PII<[address1, address2, address3]>

Inspect or create side-effects using PII contents without unwrapping

import { PII, tap } from "@tdreyno/pii"

const name = PII("Thomas")
const lowercaseName = tap(n => console.log(n), name) // Logs "Thomas"

Detecting PII in Data

Recurses through a data structure and uses a callback to detect values that should become PII.

import { PII, detect } from "@tdreyno/pii"

const person = { name: "Thomas" }
const lowercaseName = detect(
  data => isObject(person) && Object.keys().some(k => k.includes(name)),
  person,
) // Returns PII({ name: "Thomas" })

Custom PII Redaction

import { PII, redact } from "@tdreyno/pii"

const name = PII("Thomas")
const lowercaseName = redact(() => "REDACTED", name) // Returns "REDACTED"

License

pii is licensed under the Hippocratic License. It is an Ethical Source license derived from the MIT License, amended to limit the impact of the unethical use of open source software.