Skip to content

Commit

Permalink
added example, updated tests, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhea0 committed Sep 28, 2016
1 parent 96256df commit 02be873
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const arr = [
'https://foo.bar?some=params&over=here',
'https://foo.bar?some=test'
];
const file = 'sample.json';
const file = '_sample.json';

parser.convert(arr, file, (err, res) => {
if (!err) console.log('success!');
Expand Down
10 changes: 10 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const parser = require('./');
const arr = [
'https://foo.bar?some=params&over=here',
'https://foo.bar?some=test'
];
const file = '_sample.json';

parser.convert(arr, file, (err, res) => {
if (!err) console.log('success!');
});
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
const fs = require('fs');

function convert(arr, file, callback) {
if (!Array.isArray(arr)) {
callback(new Error('First argument must be an array'));
return false;
}
const data = {};
const final = arr.map((url) => {
const obj = parse(url);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-string-json",
"version": "0.0.2",
"version": "0.0.3",
"description": "Parse and convert URL query strings to JSON",
"author": "Michael Herman",
"license": "MIT",
Expand Down
15 changes: 15 additions & 0 deletions test/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
});
});
});
it('should return an error if the object is falsely', (done) => {
helpers.convert(null, '_sample.json', (err, res) => {
should.exist(err);
});
helpers.convert(undefined, '_sample.json', (err, res) => {
should.exist(err);
});
helpers.convert(false, '_sample.json', (err, res) => {
should.exist(err);
});
helpers.convert({}, '_sample.json', (err, res) => {
should.exist(err);
});
done();
});
});

}());

0 comments on commit 02be873

Please sign in to comment.