-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ORBIT-CODESPACE): ✨ FIRING UP THE ENGINE
All the Modules Are Done and tested
- Loading branch information
1 parent
e84968e
commit 1ddc9be
Showing
12 changed files
with
4,999 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.vscode | ||
node_modules | ||
lib |
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,4 @@ | ||
core | ||
tsconfig.json | ||
tslint.json | ||
.prettierrc |
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,5 @@ | ||
{ | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
} |
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,56 @@ | ||
import { LZString } from './workers/lz-string'; | ||
|
||
// 🟢💻 WELCOME TO ANOTHER SPACESHIP - DEVELOPED BY 💻🟢 | ||
// ██████╗ ██████╗ ██████╗ ██╗████████╗ ████████╗██╗ ██╗██████╗ ███╗ ██╗███████╗██████╗ | ||
// ██╔═══██╗██╔══██╗██╔══██╗██║╚══██╔══╝ ╚══██╔══╝██║ ██║██╔══██╗████╗ ██║██╔════╝██╔══██╗ | ||
// ██║ ██║██████╔╝██████╔╝██║ ██║ ██║ ██║ ██║██████╔╝██╔██╗ ██║█████╗ ██████╔╝ | ||
// ██║ ██║██╔══██╗██╔══██╗██║ ██║ ██║ ██║ ██║██╔══██╗██║╚██╗██║██╔══╝ ██╔══██╗ | ||
// ╚██████╔╝██║ ██║██████╔╝██║ ██║ ██║ ╚██████╔╝██║ ██║██║ ╚████║███████╗██║ ██║ | ||
// ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ | ||
// 💚🔰 KEEP GOING FURTHER 🔰💚 | ||
/** | ||
* 💨 Project Name : Orbit-Encoder | ||
* 💨 Project Repo : https://github.com/orbitturner/orbit-encoder | ||
* 💨 My GitHub : https://github.com/orbitturner | ||
* 💨 My LinkedIn : https://linkedin.com/in/orbitturner | ||
* 💨 My Twitter : https://twitter.com/orbitturner | ||
*/ | ||
|
||
export class OrbitEncoder { | ||
/** | ||
* ENCODING OBJECT TO BASE64. | ||
* | ||
* Since everything is an object in Javascript this will | ||
* encode whatever you give it in Base64 then Compress it to an UTF16 String. | ||
* | ||
* btoa(): creates a Base64-encoded ASCII string from a "string" of binary data ("btoa" should be read as "binary to ASCII"). | ||
* @see: https://developer.mozilla.org/en-US/docs/Glossary/Base64 | ||
*/ | ||
public static encode(obj: any): any { | ||
if (typeof obj !== 'object' && !Array.isArray(obj)) { | ||
// OLD DEPRECATED : return LZString.compressToUTF16(btoa(unescape(encodeURIComponent(obj)))); | ||
return LZString.compressToUTF16(Buffer.from(obj, 'binary').toString('base64')); | ||
|
||
|
||
} | ||
return LZString.compressToUTF16(Buffer.from(JSON.stringify(obj), 'binary').toString('base64')); | ||
} | ||
|
||
/** | ||
* DECODING BASE64. | ||
* | ||
* Since everything is an object in Javascript this will | ||
* decode whatever in Base64 you give it. | ||
* | ||
* @see: https://developer.mozilla.org/en-US/docs/Glossary/Base64 | ||
*/ | ||
public static decode(obj: any): any { | ||
try { | ||
return JSON.parse(Buffer.from(LZString.decompressFromUTF16(obj), 'base64').toString('binary')); | ||
// * atob(): decodes a Base64-encoded string("atob" should be read as "ASCII to binary"). | ||
// DEPRECATED : return JSON.parse(decodeURIComponent(escape(atob(LZString.decompressFromUTF16(obj))))); | ||
} catch { | ||
return Buffer.from(LZString.decompressFromUTF16(obj), 'base64').toString('binary'); | ||
} | ||
} | ||
} |
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,21 @@ | ||
import { OrbitEncoder } from '../OrbitEncoder'; | ||
|
||
const User = { | ||
"name": "Orbit", | ||
"age": 21, | ||
"planet": { | ||
"id": 4, | ||
"codename" : "Shadow-Coders", | ||
"galaxyName" : "Turner" | ||
} | ||
}; | ||
|
||
test('Trying to Encode Some Data with Encode Method', () => { | ||
const result = OrbitEncoder.encode(User); | ||
expect(typeof OrbitEncoder.encode(User)).toBe('string'); | ||
}); | ||
|
||
test('Decoding Some Data', () => { | ||
const result = OrbitEncoder.encode(User); | ||
expect(OrbitEncoder.decode(result)).toEqual(User); | ||
}); |
Oops, something went wrong.