Last active
March 20, 2018 11:45
-
-
Save matthewhudson/7999278 to your computer and use it in GitHub Desktop.
Parse Bitcoin URL in JavaScript
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. */ | |
function parseBitcoinURL(url) { | |
var r = /^bitcoin:([a-zA-Z0-9]{27,34})(?:\?(.*))?$/; | |
var match = r.exec(url); | |
if (!match) return null; | |
var parsed = { url: url } | |
if (match[2]) { | |
var queries = match[2].split('&'); | |
for (var i = 0; i < queries.length; i++) { | |
var query = queries[i].split('='); | |
if (query.length == 2) { | |
parsed[query[0]] = decodeURIComponent(query[1].replace(/\+/g, '%20')); | |
} | |
} | |
} | |
parsed.address = match[1]; | |
return parsed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool. Why not just do:
instead of:
? I mean... is there a realistic scenario with query params that have
+
? BIP 21 doesn't mention anything about converting them to spaces. So I must be missing something.