Skip to content

Instantly share code, notes, and snippets.

@hitmands

hitmands/parser.js

Created Oct 19, 2016
Embed
What would you like to do?
Pausa Pranzo - Regular Expressions - Level1
function urlStack(url) {
// null fields are nullable
return {
url, // the full input url
protocol: null,
port: null,
subdomain: null,
extension: null,
domain: null,
path: null,
fragment: null,
queries: {}
};
}
function urlParser(url) {
let stack = urlStack(url);
return stack;
}
var MOCK = ["//google.ru:3000/faucibus/orci/luctus/et/ultrices/posuere.jpg?leo=vel&odio=sem&porttitor=sed&id=sagittis&consequat=nam&in=congue&consequat=risus&ut=semper&nulla=porta&sed=volutpat&accumsan=quam&felis=pede&ut=lobortis&at=ligula&dolor=sit&quis=amet&odio=eleifend&consequat=pede&varius=libero&integer=quis&ac=orci&leo=nullam&pellentesque=molestie&ultrices=nibh&mattis=in&odio=lectus&donec=pellentesque&vitae=at&nisi=nulla&nam=suspendisse&ultrices=potenti&libero=cras&non=in&mattis=purus&pulvinar=eu&nulla=magna&pede=vulputate&ullamcorper=luctus&augue=cum&a=sociis&suscipit=natoque&nulla=penatibus&elit=et&ac=magnis&nulla=dis&sed=parturient&vel=montes&enim=nascetur&sit=ridiculus&amet=mus&nunc=vivamus&viverra=vestibulum&dapibus=sagittis&nulla=sapien&suscipit=cum&ligula=sociis&in=natoque&lacus=penatibus&curabitur=et&at=magnis&ipsum=dis&ac=parturient&tellus=montes&semper=nascetur&interdum=ridiculus&mauris=mus&ullamcorper=etiam&purus=vel&sit=augue&amet=vestibulum&nulla=rutrum&quisque=rutrum&arcu=neque&libero=aenean&rutrum=auctor","ws://mapy.cz/sit/amet.html?ut=pede&erat=libero&id=quis&mauris=orci&vulputate=nullam&elementum=molestie&nullam=nibh&varius=in&nulla=lectus&facilisi=pellentesque&cras=at&non=nulla&velit=suspendisse&nec=potenti&nisi=cras&vulputate=in&nonummy=purus&maecenas=eu&tincidunt=magna&lacus=vulputate&at=luctus&velit=cum&vivamus=sociis&vel=natoque&nulla=penatibus&eget=et&eros=magnis&elementum=dis&pellentesque=parturient&quisque=montes&porta=nascetur&volutpat=ridiculus&erat=mus&quisque=vivamus&erat=vestibulum&eros=sagittis&viverra=sapien&eget=cum&congue=sociis&eget=natoque&semper=penatibus&rutrum=et&nulla=magnis&nunc=dis&purus=parturient&phasellus=montes&in=nascetur&felis=ridiculus&donec=mus&semper=etiam&sapien=vel&a=augue&libero=vestibulum&nam=rutrum&dui=rutrum&proin=neque&leo=aenean&odio=auctor&porttitor=gravida&id=sem&consequat=praesent&in=id&consequat=massa&ut=id&nulla=nisl&sed=venenatis","http://whitehouse.gov/dui/luctus.aspx?quis=justo&libero=in&nullam=hac&sit=h…=vivamus&nec=vel&molestie=nulla&sed=eget&justo=eros&pellentesque=elementum","https://dedecms.com/condimentum/id/luctus.json?justo=erat&maecenas=quisque&…&non=suscipit&mauris=ligula&morbi=in&non=lacus&lectus=curabitur&aliquam=at","ftp://amazonaws.com:21/a/odio/in/hac/habitasse/platea/dictumst.jsp?malesuada=p…sapien&ac=in&enim=sapien&in=iaculis&tempor=congue&turpis=vivamus&nec=metus","//ucoz.ru/sit/amet.json?congue=odio&risus=cras&semper=mi&porta=pede&volutpat=malesuada&quam=in&pede=imperdiet&lobortis=et&ligula=commodo&sit=vulputate&amet=justo&eleifend=in&pede=blandit","/habitasse/platea.png?viverra=ipsum&eget=praesent&congue=blandit&eget=lacinia&semper=erat&rutrum=vestibulum&nulla=sed&nunc=magna&purus=at&phasellus=nunc&in=commodo&felis=placerat&donec=praesent&semper=blandit&sapien=nam&a=nulla&libero=integer&nam=pede&dui=justo&proin=lacinia&leo=eget&odio=tincidunt&porttitor=eget&id=tempus&consequat=vel&in=pede&consequat=morbi&ut=porttitor&nulla=lorem&sed=id&accumsan=ligula&felis=suspendisse&ut=ornare&at=consequat&dolor=lectus&quis=in&odio=est&consequat=risus&varius=auctor&integer=sed&ac=tristique","https://sample.china.com/leo.jsp?in=iaculis&faucibus=diam&orci=erat&luctus=…nte&morbi=vivamus&non=tortor&quam=duis&nec=mattis&dui=egestas&luctus=metus","/?vitae=potenti&consectetuer=in&eget=eleifend&rutrum=quam&at=a&lorem=odio&integer=in&tincidunt=hac&ante=habitasse&vel=platea&ipsum=dictumst&praesent=maecenas&blandit=ut&lacinia=massa&erat=quis&vestibulum=augue&sed=luctus&magna=tincidunt&at=nulla&nunc=mollis&commodo=molestie&placerat=lorem&praesent=quisque&blandit=ut&nam=erat&nulla=curabitur&integer=gravida&pede=nisi&justo=at&lacinia=nibh&eget=in&tincidunt=hac&eget=habitasse&tempus=platea&vel=dictumst&pede=aliquam","https://cbslocal.com/#!/rutrum/neque/aenean/auctor"];
console.clear();
console.time("Parse 10 Urls")
console.log(MOCK.map(urlParser));
console.timeEnd("Parse 10 Urls")
@hitmands

This comment has been minimized.

Copy link
Owner Author

@hitmands hitmands commented Oct 19, 2016

Just write the parser function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.