-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
55004ca
commit 9ddcbd0
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
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'}); | ||
const expected = 'key1=value1,key2=value2,key99=value99'; | ||
assert(actual === expected); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
function objectEntries(object) { | ||
const entries = []; | ||
for (const key of Object.keys(object)) { | ||
const value = object[key]; | ||
entries.push([key, value]); | ||
} | ||
return entries; | ||
} | ||
|
||
function convertObjectToList(object) { | ||
return objectEntries(object) | ||
.reduce((result, current) => result.concat(`${current[0]}=${current[1]}`), []) | ||
.join(','); | ||
} | ||
|
||
module.exports = { | ||
convertObjectToList | ||
}; |