Created
December 17, 2013 03:55
-
-
Save matthewhudson/7999822 to your computer and use it in GitHub Desktop.
Parse a Bitcoin URL in CoffeeScript
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
# Parse bitcoin URL query keys. | |
parseBitcoinURL = (url) -> | |
r = /^bitcoin:([a-zA-Z0-9]{27,34})(?:\?(.*))?$/ | |
match = r.exec(url) | |
return null unless match | |
parsed = url: url | |
if match[2] | |
queries = match[2].split("&") | |
i = 0 | |
while i < queries.length | |
query = queries[i].split("=") | |
parsed[query[0]] = decodeURIComponent(query[1].replace(/\+/g, "%20")) if query.length is 2 | |
i++ | |
parsed.address = match[1] | |
parsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment