Skip to content

Instantly share code, notes, and snippets.

@ericnkatz
Forked from indatawetrust/serialize.js
Created March 11, 2017 19:16
Show Gist options
  • Save ericnkatz/bc5c60dcf07708d0998a7bff5b9226da to your computer and use it in GitHub Desktop.
Save ericnkatz/bc5c60dcf07708d0998a7bff5b9226da to your computer and use it in GitHub Desktop.
const serialize = uri => uri.split('&').map(uri => ({ [uri.split('=')[0]]: uri.split('=')[1] })).reduce((a,b) => Object.assign(a,b))
console.log(serialize("_id=58c43d995cb9191a2f676b25&index=0&guid=798ebd68-22d5-4465-9d34-d4717891901d&isActive=false&balance=$2,569.51&picture=http://placehold.it/32x32&age=33&eyeColor=green&name=Desiree Cervantes&gender=female&company=SYNKGEN&[email protected]&phone=+1 (975) 536-2019&address=855 Hendrickson Street, Libertytown, Marshall Islands, 5292&about=Elit anim occaecat proident consectetur veniam et deserunt irure. Sint aliquip fugiat aute tempor veniam eu duis mollit eiusmod aliquip ipsum enim do in. Pariatur nisi proident commodo duis nisi id ut commodo aute irure. Minim ut tempor in tempor dolor ex veniam fugiat. Sint cillum non qui elit amet deserunt ullamco. Commodo veniam reprehenderit est minim commodo qui ad occaecat nulla incididunt amet quis culpa. Fugiat consequat occaecat sint sunt et consequat anim.&registered=2016-06-27T04:02:43 -03:00&latitude=-5.114506&longitude=-67.527021&greeting=Hello, Desiree Cervantes! You have 4 unread messages.&favoriteFruit=apple"))
// log
Object {
"_id": "58c43d995cb9191a2f676b25",
"about": "Elit anim occaecat proident consectetur veniam et deserunt irure. Sint aliquip fugiat aute tempor veniam eu duis mollit eiusmod aliquip ipsum enim do in. Pariatur nisi proident commodo duis nisi id ut commodo aute irure. Minim ut tempor in tempor dolor ex veniam fugiat. Sint cillum non qui elit amet deserunt ullamco. Commodo veniam reprehenderit est minim commodo qui ad occaecat nulla incididunt amet quis culpa. Fugiat consequat occaecat sint sunt et consequat anim.",
"address": "855 Hendrickson Street, Libertytown, Marshall Islands, 5292",
"age": "33",
"balance": "$2,569.51",
"company": "SYNKGEN",
"email": "[email protected]",
"eyeColor": "green",
"favoriteFruit": "apple",
"gender": "female",
"greeting": "Hello, Desiree Cervantes! You have 4 unread messages.",
"guid": "798ebd68-22d5-4465-9d34-d4717891901d",
"index": "0",
"isActive": "false",
"latitude": "-5.114506",
"longitude": "-67.527021",
"name": "Desiree Cervantes",
"phone": "+1 (975) 536-2019",
"picture": "http://placehold.it/32x32",
"registered": "2016-06-27T04:02:43 -03:00"
}
@AbrahamWilton
Copy link

AbrahamWilton commented Jun 6, 2020

Hello
how to extract an item from the collection
example
var id = Object.id;
var about = Object.about;
you would help me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment