Skip to content

Commit

Permalink
utils.js simpleRandom()
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito authored Feb 9, 2022
1 parent 1aa4c77 commit a9ceb81
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions jwt-decode-openwrt/files/www/assets/utils.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
function getRequestQueryParams() {
const keyValPairs = location.search.substring(1, location.search.length).split('&')
const requestQueryParams = {}
let keyValPairs = location.search.substring(1, location.search.length).split('&')
let requestQueryParams = {}
keyValPairs.forEach(keyValPair => {
const keyAndVal = keyValPair.split('=')
const key = decodeURIComponent(keyAndVal[0])
let keyAndVal = keyValPair.split('=')
let key = decodeURIComponent(keyAndVal[0])
requestQueryParams[key] = decodeURIComponent(keyAndVal[1])
})
return requestQueryParams
}

/** Parse hash string */
function getRequestHashParams() {
var fragmentString = location.hash.substring(1);
var requestHashParams = {};
var regex = /([^&=]+)=([^&]*)/g, m;
let fragmentString = location.hash.substring(1)
let requestHashParams = {}
let regex = /([^&=]+)=([^&]*)/g
let m
while (m = regex.exec(fragmentString)) {
requestHashParams[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
requestHashParams[decodeURIComponent(m[1])] = decodeURIComponent(m[2])
}
return requestHashParams
}

function currentTimestamp() {
return (new Date()).getTime();
return (new Date()).getTime()
}

function simpleRandom() {
// just the float rand num as is but remove 0. prefix
return ("" + Math.random()).substring(2)
let buf = new Uint32Array(1)
window.crypto.getRandomValues(buf)
let b64encoded = btoa(buf)
return b64encoded.replace(/=/g, '')
}

0 comments on commit a9ceb81

Please sign in to comment.