2022-03-09 04:40:39 +00:00
|
|
|
export const getCrypto = () => {
|
|
|
|
//ie 11.x uses msCrypto
|
|
|
|
return (window.crypto || (window as any).msCrypto) as Crypto;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createRandomString = () => {
|
|
|
|
const charset =
|
|
|
|
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
|
|
|
|
let random = '';
|
|
|
|
const randomValues = Array.from(
|
2022-10-02 17:09:47 +00:00
|
|
|
getCrypto().getRandomValues(new Uint8Array(43)),
|
2022-03-09 04:40:39 +00:00
|
|
|
);
|
|
|
|
randomValues.forEach((v) => (random += charset[v % charset.length]));
|
|
|
|
return random;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createQueryParams = (params: any) => {
|
|
|
|
return Object.keys(params)
|
|
|
|
.filter((k) => typeof params[k] !== 'undefined')
|
|
|
|
.map((k) => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
|
|
|
.join('&');
|
|
|
|
};
|
2022-05-18 14:34:29 +00:00
|
|
|
|
|
|
|
export const hasWindow = (): boolean => typeof window !== 'undefined';
|