-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
368828d
commit b1a3b1f
Showing
6 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @description This is utility function for decoding from base 64 to utf8 | ||
* @version v1.0.0 | ||
*/ | ||
|
||
/** | ||
* @param {string} str base64 | ||
* @returns {string} utf8 | ||
*/ | ||
function b64DecodeUnicode(str) { | ||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent(atob(str).split('').map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}).join('')); | ||
} | ||
|
||
/** | ||
* @param {string} value | ||
* @return {string} | ||
*/ | ||
function decode(data = "") { | ||
data = data.endsWith("..") ? data.substr(0, data.length - 2) : data; | ||
return b64DecodeUnicode(data); | ||
} | ||
|
||
export default decode |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @description This is utility function for crc32 algorithm | ||
* @version v1.0.0 | ||
*/ | ||
|
||
/** | ||
* @description generate crc table | ||
* @params none | ||
* @returns arrray of CRC table | ||
*/ | ||
|
||
const makeCRCTable = function () { | ||
const crcTable = [] | ||
let c | ||
for (var n = 0; n < 256; n++) { | ||
c = n | ||
for (var k = 0; k < 8; k++) { | ||
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1 | ||
} | ||
crcTable[n] = c | ||
} | ||
return crcTable | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param {string} str | ||
* @returns {Bystream} crc32 | ||
*/ | ||
const crc32 = function (str) { | ||
const crcTable = makeCRCTable() | ||
let crc = 0 ^ -1 | ||
|
||
for (let i = 0; i < str.length; i++) { | ||
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xff] | ||
} | ||
|
||
return (crc ^ -1) >>> 0 | ||
} | ||
|
||
export default crc32 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @description An interface to fetch user device details. | ||
* @version v1.0.0 | ||
*/ | ||
|
||
const USER_INTERFACE = { | ||
/** | ||
* @param {*} req | ||
* @returns {string} user language | ||
*/ | ||
getUserLanguage: () => navigator && navigator.language, | ||
|
||
/** | ||
* @param {*} req | ||
* @returns {string} userAgent | ||
*/ | ||
getUserAgent: () => navigator && navigator.userAgent | ||
} | ||
|
||
export default USER_INTERFACE; |