@nofrills/scrubs
v11.0.1
Published
Scrubs an object of sensitive data.
Downloads
189
Readme
@nofrills/scrubs
No frills data scrubbing to help remove sensitive data from object properties and strings.
Install
npm install --save @nofrills/scrubs
Quick Start
Javascript
const scrubs = require('@nofrills/scrubs')
const data = {
password: 'password123'
}
const scrubbed = scrubs.scrub(data)
// -> should return { password: "<secured>" }
Typescript
import { scrub } from '@nofrills/scrubs'
const data = {
password: 'password123'
}
const scrubbed = scrub(data)
// -> should return { password: "<secured>" }
NOTE: From here on, we'll use Javascript in examples.
Options
You can also use an options object to inject some customizations and extensions.
{
properties: ['apikey', 'api_key', 'password'],
text: '<secured>'
}
Once you've created your options, you can pass it to the Scrubs
class.
const Scrubs = require('@nofrills/scrubs').Scrubs
const scrubber = new Scrubs({
secured: {
properties: ['apikey', 'api_key', 'password'],
text: '<password>'
}
scrubber.scrub({ password: "password123" })
// -> will replace password with "<password>"
})
Properties
Properties are an array of strings representing the properties on an object that require securing. By default, apikey
, api_key
, and password
are secured.
Extensibility
You can extend how scrubs
works by registering custom handlers to scrub a provided value.
In Typescript parlance, we define a callback via the Scrubber<T>
type.
type Scrubber<T> = (value: T, options: ScrubsOptions, instance: Scrubs) => T
Simply create your handler and register it before scrubbing, like so:
Javascript
const R = require('@nofrills/scrubs').Registry
const Handler = (value, options, scrubs) => {
// TODO: Something super fantastic that scrubs
// the value of sensitive data.
return value
}
R.register('string', Handler)
License
Copyright 2018 NativeCode Development [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.