Last active
July 14, 2017 19:29
-
-
Save rodrigorm/8c56d0fac23eaf0a97387113d1b2a695 to your computer and use it in GitHub Desktop.
neyjson
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
node_modules/ |
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
const Suite = require('benchmark').Suite; | |
const fs = require('fs'); | |
const main = require('./index'); | |
const suite = new Suite; | |
const json1 = fs.readFileSync('input1.json'); | |
const json2 = fs.readFileSync('input2.json'); | |
const json3 = fs.readFileSync('input3.json'); | |
suite | |
.add('input1.json', () => { | |
JSON.stringify(main(JSON.parse(json1))); | |
}) | |
.add('input2.json', () => { | |
JSON.stringify(main(JSON.parse(json2))); | |
}) | |
.add('input3.json', () => { | |
JSON.stringify(main(JSON.parse(json3))); | |
}) | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.run({ async: true }); |
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
const product = require('./product'); | |
const clean = item => item.value; | |
const format = value => ({ value }); | |
const main = (input) => input.map(clean).reduce(product).map(format); | |
module.exports = main; |
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
const assert = require('unit.js').assert; | |
const main = require('./index'); | |
(() => { | |
const input = [ | |
{ name: 'voltagem', value: [ {name: '110'}, {name: '220'} ] }, | |
{ name: 'color', value: [ {name: 'Amarelo'}, {name: 'Verde'}, {name: 'Azul'} ] } | |
]; | |
const expected = [ | |
{ value: [ {name: '110'}, {name: 'Amarelo'} ] }, | |
{ value: [ {name: '110'}, {name: 'Verde'} ] }, | |
{ value: [ {name: '110'}, {name: 'Azul'} ] }, | |
{ value: [ {name: '220'}, {name: 'Amarelo'} ] }, | |
{ value: [ {name: '220'}, {name: 'Verde'} ] }, | |
{ value: [ {name: '220'}, {name: 'Azul'} ] }, | |
]; | |
assert.deepEqual(main(input), expected); | |
})(); | |
(() => { | |
const input = [ | |
{ name: 'voltagem', value: [ {name: '110'}, {name: '220'} ] }, | |
{ name: 'color', value: [ {name: 'Amarelo'}, {name: 'Verde'}, {name: 'Azul'} ] }, | |
{ name: 'type', value: [ {name: 'Brick'}, {name: 'House'} ] }, | |
]; | |
const expected = [ | |
{ value: [ {name: '110'}, {name: 'Amarelo'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '110'}, {name: 'Amarelo'}, {name: 'House'} ] }, | |
{ value: [ {name: '110'}, {name: 'Verde'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '110'}, {name: 'Verde'}, {name: 'House'} ] }, | |
{ value: [ {name: '110'}, {name: 'Azul'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '110'}, {name: 'Azul'}, {name: 'House'} ] }, | |
{ value: [ {name: '220'}, {name: 'Amarelo'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '220'}, {name: 'Amarelo'}, {name: 'House'} ] }, | |
{ value: [ {name: '220'}, {name: 'Verde'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '220'}, {name: 'Verde'}, {name: 'House'} ] }, | |
{ value: [ {name: '220'}, {name: 'Azul'}, {name: 'Brick'} ] }, | |
{ value: [ {name: '220'}, {name: 'Azul'}, {name: 'House'} ] }, | |
]; | |
assert.deepEqual(main(input), expected); | |
})(); |
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
[ | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]} | |
] |
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
[ | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]} | |
] |
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
[ | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]}, | |
{"name":"color","value":[{"name":"Amarelo"},{"name":"Verde"},{"name":"Azul"}]}, | |
{"name":"voltagem","value":[{"name":"110"},{"name":"220"}]} | |
] |
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
{ | |
"name": "neyjson", | |
"version": "1.0.0", | |
"main": "index.js", | |
"author": "Rodrigo Moyle <[email protected]>", | |
"license": "MIT", | |
"devDependencies": { | |
"benchmark": "^2.1.4", | |
"unit.js": "^2.0.0" | |
}, | |
"scripts": { | |
"test": "node test.js", | |
"benchmark": "node benchmark.js" | |
} | |
} |
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
const product = (i, j) => ( | |
i.map(i1 => ( | |
j.map(j1 => ( | |
Array.prototype.concat.apply([], [i1, j1]) | |
)) | |
)).reduce((a, b) => a.concat(b), []) | |
); | |
module.exports = product; |
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
const assert = require('unit.js').assert; | |
const product = require('./product'); | |
(() => { | |
const input = [ | |
['1', '2'], | |
['a', 'b'] | |
]; | |
const expected = [ | |
['1', 'a'], | |
['1', 'b'], | |
['2', 'a'], | |
['2', 'b'] | |
]; | |
assert.deepEqual(input.reduce(product), expected); | |
})(); | |
(() => { | |
const input = [ | |
['1', '2'], | |
['a', 'b', 'c'] | |
]; | |
const expected = [ | |
['1', 'a'], | |
['1', 'b'], | |
['1', 'c'], | |
['2', 'a'], | |
['2', 'b'], | |
['2', 'c'] | |
]; | |
assert.deepEqual(input.reduce(product), expected); | |
})(); | |
(() => { | |
const input = [ | |
['1', '2'], | |
['a', 'b', 'c'], | |
['I', 'II'] | |
]; | |
const expected = [ | |
['1', 'a', 'I' ], | |
['1', 'a', 'II'], | |
['1', 'b', 'I' ], | |
['1', 'b', 'II'], | |
['1', 'c', 'I' ], | |
['1', 'c', 'II'], | |
['2', 'a', 'I' ], | |
['2', 'a', 'II'], | |
['2', 'b', 'I' ], | |
['2', 'b', 'II'], | |
['2', 'c', 'I' ], | |
['2', 'c', 'II'], | |
]; | |
assert.deepEqual(input.reduce(product), expected); | |
})(); |
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
require('./index.test'); | |
require('./product.test'); |
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 IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | |
# yarn lockfile v1 | |
async@~0.9.0: | |
version "0.9.2" | |
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d" | |
benchmark@^2.1.4: | |
version "2.1.4" | |
resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629" | |
dependencies: | |
lodash "^4.17.4" | |
platform "^1.3.3" | |
bluebird@^2.9.9: | |
version "2.11.0" | |
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1" | |
combined-stream@~0.0.4: | |
version "0.0.7" | |
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-0.0.7.tgz#0137e657baa5a7541c57ac37ac5fc07d73b4dc1f" | |
dependencies: | |
delayed-stream "0.0.5" | |
[email protected]: | |
version "1.1.2" | |
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.1.2.tgz#296594f2753daa63996d2af08d15a95116c9aec3" | |
[email protected]: | |
version "2.0.1" | |
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.0.1.tgz#3d12752f6adf68a892f332433492bd5812bb668f" | |
core-util-is@~1.0.0: | |
version "1.0.2" | |
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" | |
debug@2: | |
version "2.6.8" | |
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" | |
dependencies: | |
ms "2.0.0" | |
[email protected]: | |
version "0.0.5" | |
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-0.0.5.tgz#d4b1f43a93e8296dfe02694f4680bc37a313c73f" | |
extend@~1.2.1: | |
version "1.2.1" | |
resolved "https://registry.yarnpkg.com/extend/-/extend-1.2.1.tgz#a0f5fd6cfc83a5fe49ef698d60ec8a624dd4576c" | |
[email protected]: | |
version "0.1.3" | |
resolved "https://registry.yarnpkg.com/form-data/-/form-data-0.1.3.tgz#4ee4346e6eb5362e8344a02075bd8dbd8c7373ea" | |
dependencies: | |
async "~0.9.0" | |
combined-stream "~0.0.4" | |
mime "~1.2.11" | |
[email protected]: | |
version "1.1.1" | |
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9" | |
dependencies: | |
samsam "~1.1" | |
[email protected]: | |
version "1.0.14" | |
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.14.tgz#2b3f4c411cbb5fdd695c44843e2a23514a43231a" | |
[email protected]: | |
version "2.0.1" | |
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" | |
inherits@~2.0.1: | |
version "2.0.3" | |
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" | |
[email protected]: | |
version "0.0.1" | |
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" | |
"kindof@>= 1.0.0 < 2": | |
version "1.0.0" | |
resolved "https://registry.yarnpkg.com/kindof/-/kindof-1.0.0.tgz#131899a8527537a94da2edcd5cc49fc609606560" | |
lodash@^3.7.0: | |
version "3.10.1" | |
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" | |
lodash@^4.17.4: | |
version "4.17.4" | |
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" | |
[email protected]: | |
version "1.3.2" | |
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31" | |
[email protected]: | |
version "1.0.1" | |
resolved "https://registry.yarnpkg.com/methods/-/methods-1.0.1.tgz#75bc91943dffd7da037cf3eeb0ed73a0037cd14b" | |
[email protected]: | |
version "1.1.2" | |
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" | |
[email protected], mime@~1.2.11: | |
version "1.2.11" | |
resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10" | |
[email protected]: | |
version "2.0.0" | |
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" | |
must@^0.12.0: | |
version "0.12.0" | |
resolved "https://registry.yarnpkg.com/must/-/must-0.12.0.tgz#5741e729bedbc8b0fe2bc8c5006459415383d05d" | |
dependencies: | |
kindof ">= 1.0.0 < 2" | |
"noder.io@>= 1.0.0 < 2.0.0": | |
version "1.2.0" | |
resolved "https://registry.yarnpkg.com/noder.io/-/noder.io-1.2.0.tgz#ad2bc6c6c3f9465891edbc6dbf5e84dcae2fa9e6" | |
platform@^1.3.3: | |
version "1.3.4" | |
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.4.tgz#6f0fb17edaaa48f21442b3a975c063130f1c3ebd" | |
[email protected]: | |
version "1.2.0" | |
resolved "https://registry.yarnpkg.com/qs/-/qs-1.2.0.tgz#ed079be28682147e6fd9a34cc2b0c1e0ec6453ee" | |
[email protected]: | |
version "1.0.27-1" | |
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.27-1.tgz#6b67983c20357cefd07f0165001a16d710d91078" | |
dependencies: | |
core-util-is "~1.0.0" | |
inherits "~2.0.1" | |
isarray "0.0.1" | |
string_decoder "~0.10.x" | |
[email protected]: | |
version "1.0.1" | |
resolved "https://registry.yarnpkg.com/reduce-component/-/reduce-component-1.0.1.tgz#e0c93542c574521bea13df0f9488ed82ab77c5da" | |
[email protected]: | |
version "1.1.2" | |
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567" | |
samsam@~1.1: | |
version "1.1.3" | |
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.3.tgz#9f5087419b4d091f232571e7fa52e90b0f552621" | |
[email protected]: | |
version "0.3.1" | |
resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-0.3.1.tgz#bd8ea97a6748e39fad476a3be6fd72ebc2e72bf0" | |
dependencies: | |
should-type "0.0.4" | |
[email protected]: | |
version "0.0.7" | |
resolved "https://registry.yarnpkg.com/should-format/-/should-format-0.0.7.tgz#1e2ef86bd91da9c2e0412335b56ababd9a2fde12" | |
dependencies: | |
should-type "0.0.4" | |
[email protected]: | |
version "0.0.4" | |
resolved "https://registry.yarnpkg.com/should-type/-/should-type-0.0.4.tgz#0132a05417a6126866426acf116f1ed5623a5cd0" | |
should@^6.0.1: | |
version "6.0.3" | |
resolved "https://registry.yarnpkg.com/should/-/should-6.0.3.tgz#daee30786a557662fbc774c008d7c58791edb1d9" | |
dependencies: | |
should-equal "0.3.1" | |
should-format "0.0.7" | |
should-type "0.0.4" | |
"sinon@>= 1.14.1 < 2.0.0": | |
version "1.17.7" | |
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf" | |
dependencies: | |
formatio "1.1.1" | |
lolex "1.3.2" | |
samsam "1.1.2" | |
util ">=0.10.3 <1" | |
string_decoder@~0.10.x: | |
version "0.10.31" | |
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" | |
superagent@~0.21.0: | |
version "0.21.0" | |
resolved "https://registry.yarnpkg.com/superagent/-/superagent-0.21.0.tgz#fb15027984751ee7152200e6cd21cd6e19a5de87" | |
dependencies: | |
component-emitter "1.1.2" | |
cookiejar "2.0.1" | |
debug "2" | |
extend "~1.2.1" | |
form-data "0.1.3" | |
formidable "1.0.14" | |
methods "1.0.1" | |
mime "1.2.11" | |
qs "1.2.0" | |
readable-stream "1.0.27-1" | |
reduce-component "1.0.1" | |
"supertest@>= 0.15.0 < 1.0.0": | |
version "0.15.0" | |
resolved "https://registry.yarnpkg.com/supertest/-/supertest-0.15.0.tgz#86118695de4be58869b3ee94c45e1d084ca7fac5" | |
dependencies: | |
methods "1.x" | |
superagent "~0.21.0" | |
unit.js@^2.0.0: | |
version "2.0.0" | |
resolved "https://registry.yarnpkg.com/unit.js/-/unit.js-2.0.0.tgz#e91b56abc50c530dba03cdbfe0e1df2a3ee3aa32" | |
dependencies: | |
bluebird "^2.9.9" | |
lodash "^3.7.0" | |
must "^0.12.0" | |
noder.io ">= 1.0.0 < 2.0.0" | |
should "^6.0.1" | |
sinon ">= 1.14.1 < 2.0.0" | |
supertest ">= 0.15.0 < 1.0.0" | |
"util@>=0.10.3 <1": | |
version "0.10.3" | |
resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" | |
dependencies: | |
inherits "2.0.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment