Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 27, 2017
1 parent 9ddcbd0 commit 4ac3c98
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@ const through = require('through2');
const npmRunPath = require('npm-run-path');
const utils = require('./utils');

const convertObjectToList = utils.convertObjectToList;

const HUNDRED_MEGABYTES = 1000 * 1000 * 100;

// Mocha options that can be specified multiple times
const MULTIPLE_OPTS = [
const MULTIPLE_OPTS = new Set([
'require'
];
]);

module.exports = opts => {
opts = Object.assign({
colors: true,
suppress: false
}, opts);

// Convert arrays into comma separated lists
for (const key of Object.keys(opts)) {
const val = opts[key];

if (MULTIPLE_OPTS.indexOf(key) > 0 && Array.isArray(val)) {
opts[key] = val.join(',');

// Convert an object into comma separated list.
if (Array.isArray(val)) {
if (!MULTIPLE_OPTS.has(key)) {
// Convert arrays into comma separated lists
opts[key] = val.join(',');
}
} else if (typeof val === 'object') {
opts[key] = convertObjectToList(val);
// Convert an object into comma separated list
opts[key] = utils.convertObjectToList(val);
}
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test": "xo && mocha"
},
"files": [
"index.js"
"index.js",
"utils.js"
],
"keywords": [
"gulpplugin",
Expand Down
9 changes: 3 additions & 6 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
const assert = require('assert');
const utils = require('../utils');

const convertObjectToList = utils.convertObjectToList;

describe('Utils', () => {
describe('convertObjectToList', () => {
it('produces a comma separated string of k=v', done => {
const actual = convertObjectToList({key1: 'value1', key2: 'value2', key99: 'value99'});
it('produces a comma separated string of k=v', () => {
const actual = utils.convertObjectToList({key1: 'value1', key2: 'value2', key99: 'value99'});
const expected = 'key1=value1,key2=value2,key99=value99';
assert(actual === expected);
done();
assert.strictEqual(actual, expected);
});
});
});
2 changes: 2 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

function objectEntries(object) {
const entries = [];

for (const key of Object.keys(object)) {
const value = object[key];
entries.push([key, value]);
}

return entries;
}

Expand Down

0 comments on commit 4ac3c98

Please sign in to comment.