Skip to content

Commit

Permalink
feat(ORBIT-CODESPACE): ✨ FIRING UP THE ENGINE
Browse files Browse the repository at this point in the history
All the Modules Are Done and tested
  • Loading branch information
orbitturner committed Apr 12, 2022
1 parent e84968e commit 1ddc9be
Show file tree
Hide file tree
Showing 12 changed files with 4,999 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode
node_modules
lib
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
core
tsconfig.json
tslint.json
.prettierrc
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Issues Status](https://img.shields.io/github/issues/orbitturner/ORBIT-ENCODER)](https://github.com/orbitturner/ORBIT-ENCODER)
[![npm version](https://img.shields.io/npm/v/ORBIT-ENCODER.svg)](https://github.com/orbitturner/ORBIT-ENCODER) [![license](https://img.shields.io/npm/l/ORBIT-ENCODER.svg)](https://github.com/orbitturner/ORBIT-ENCODER)

**ORBIT-ENCODER** is an utility library for Data Compression and Encoding. It can take whatever object you gave him as argument and returns a compressed encoded string. It provides a decoding method too. It uses a modified version of for UTF16 Compression [*LZString*](https://www.npmjs.com/package/lz-string).
**ORBIT-ENCODER** is an utility library for Data Compression and Encoding. It can take whatever object you give him as argument and returns a compressed encoded string. It provides a decoding method too. It uses a modified version of [*LZString*](https://www.npmjs.com/package/lz-string) for UTF16 Compression.

<p align="center">
<a href="http://orbitturner.com/"><img src="./.repo-assets/images/GITHUB REPOS COVER.gif" width="auto" alt="ORBIT-ENCODER COVER"/></a>
Expand Down
56 changes: 56 additions & 0 deletions core/OrbitEncoder.ts
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');
}
}
}
21 changes: 21 additions & 0 deletions core/__test__/OrbitEncoder.test.ts
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);
});
Loading

0 comments on commit 1ddc9be

Please sign in to comment.