Skip to content

Commit 5d0bcc2

Browse files
committed
initial commit
0 parents  commit 5d0bcc2

File tree

8 files changed

+188
-0
lines changed

8 files changed

+188
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.nyc_output/

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"
4+
- "0.12"
5+
- "iojs"
6+
sudo: false

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Help.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# strip-passwords
2+
3+
[![Build Status](https://travis-ci.org/helpdotcom/strip-passwords.svg)](https://travis-ci.org/helpdotcom/strip-passwords)
4+
[![Coverage Status](https://coveralls.io/repos/helpdotcom/strip-passwords/badge.svg?branch=master&service=github)](https://coveralls.io/github/helpdotcom/strip-passwords?branch=master)
5+
6+
Strip passwords from an object
7+
8+
## Install
9+
10+
```bash
11+
$ npm install --save strip-passwords
12+
```
13+
14+
## Usage
15+
16+
```js
17+
var clean = require('strip-passwords')
18+
19+
clean({ password: 'test' })
20+
// => { password: '****' }
21+
```
22+
23+
## Author
24+
25+
Evan Lucas
26+
27+
## License
28+
29+
MIT (See `LICENSE` for more info)

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib')

lib/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
module.exports = clean
4+
5+
function clean(msg) {
6+
if (typeof msg !== 'object') {
7+
return msg
8+
}
9+
var keys = Object.keys(msg)
10+
for (var i = 0, len = keys.length; i < len; i++) {
11+
var key = keys[i]
12+
if (key === 'password') {
13+
msg[key] = '****'
14+
} else if (Array.isArray(msg[key])) {
15+
msg[key] = msg[key].map(function(item) {
16+
return clean(item)
17+
});
18+
} else if (typeof msg[key] === 'object') {
19+
msg[key] = clean(msg[key])
20+
}
21+
}
22+
23+
return msg
24+
}

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "strip-passwords",
3+
"version": "1.0.0",
4+
"description": "Strip passwords from an object",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "tap test/test.js --cov"
8+
},
9+
"dependencies": {},
10+
"devDependencies": {
11+
"tap": "~1.3.4"
12+
},
13+
"license": "MIT",
14+
"author": "Evan Lucas <[email protected]>",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/helpdotcom/strip-passwords"
18+
},
19+
"homepage": "https://github.com/helpdotcom/strip-passwords",
20+
"bugs": {
21+
"url": "https://github.com/helpdotcom/strip-passwords/issues"
22+
}
23+
}

test/test.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
var test = require('tap').test
4+
var clean = require('../')
5+
6+
var tests = [
7+
{
8+
name: 'should clean out passwords'
9+
, test: {
10+
meta: {}
11+
, data: {
12+
email: 'biscuits'
13+
, password: 'password'
14+
}
15+
}
16+
, expected: {
17+
meta: {}
18+
, data: {
19+
email: 'biscuits'
20+
, password: '****'
21+
}
22+
}
23+
}
24+
, {
25+
name: 'should work recursively'
26+
, test: {
27+
meta: {}
28+
, data: {
29+
meta: {}
30+
, data: {
31+
email: 'biscuits'
32+
, password: 'password'
33+
}
34+
}
35+
}
36+
, expected: {
37+
meta: {}
38+
, data: {
39+
meta: {}
40+
, data: {
41+
email: 'biscuits'
42+
, password: '****'
43+
}
44+
}
45+
}
46+
}
47+
, {
48+
name: 'should return msg if string'
49+
, test: 'str'
50+
, expected: 'str'
51+
}
52+
, {
53+
name: 'should return msg if bool'
54+
, test: true
55+
, expected: true
56+
}
57+
, {
58+
name: 'should work for arrays'
59+
, test: {
60+
data: [{
61+
meta: { password: '1234' }
62+
}
63+
, {
64+
meta: { password: '1234' }
65+
}]
66+
}
67+
, expected: {
68+
data: [{
69+
meta: { password: '****' }
70+
}
71+
, {
72+
meta: { password: '****' }
73+
}]
74+
}
75+
}
76+
]
77+
78+
tests.forEach(function(tester) {
79+
test(tester.name, function(t) {
80+
t.deepEqual(clean(tester.test), tester.expected)
81+
t.end()
82+
})
83+
})

0 commit comments

Comments
 (0)