Skip to content

Instantly share code, notes, and snippets.

@matthewhudson
Created December 17, 2013 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhudson/7999822 to your computer and use it in GitHub Desktop.
Save matthewhudson/7999822 to your computer and use it in GitHub Desktop.
Parse a Bitcoin URL in CoffeeScript
# 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