Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#

Fork of ecoji-js

Temporarily, you can install using `npm install o-ecoji-js`

We created this repo to make specific changes to our npm repo more quickly.

See below readme for dimabory, main author of this library

# ecoji-js | 1️⃣0️⃣2️⃣4️⃣ 👨‍💻🔥#️⃣🌎🛫🕶️

[![npm version](https://badge.fury.io/js/ecoji-js.svg)](https://www.npmjs.com/package/ecoji-js)
Expand Down
45 changes: 32 additions & 13 deletions lib/src/Ecoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ export default class Ecoji {
}

public encode(input: string): string {
let output = ''

const bufferIterator = Buffer.from(input.encode(), 'binary')
return this.encodeType(input,'binary');
}
public encodeType(input: string, encoding:string){
let output = ''
const bufferIterator = Buffer.from(input.encode(), encoding)
const values = bufferIterator.values()

if(encoding=="hex" && input.length % 2 > 0){
console.warn("Warning: Only hex strings with an even number of characters will be encoded properly. Please add another character to your string to ignore this message. Also, please only use characters from a-f and 0-9");
input=input.toLowerCase();
}
let length = bufferIterator.length

while (length > 0) {
Expand Down Expand Up @@ -62,6 +67,7 @@ export default class Ecoji {
case 1:
output += this.mapping.getPadding41()
break

case 2:
output += this.mapping.getPadding42()
break
Expand All @@ -88,10 +94,13 @@ export default class Ecoji {
return output
}

public decode(input: string): string {
public decode(input: string){
return this.decodeType(input,'binary');
}
public decodeType(input: string, decodeTo: string): string {

let output = ''

let outputArray: number[] = [];
const emojis = input.replace(/(?:\r\n|\r|\n)/g, '').decode().mb_split()

while (emojis.length) {
Expand Down Expand Up @@ -120,7 +129,7 @@ export default class Ecoji {
bits[3] = this.mapping.getId(runes[3])
break
}

let out = [
bits[0] >> 2,
((bits[0] & 0x3) << 6) | (bits[1] >> 4),
Expand All @@ -143,14 +152,24 @@ export default class Ecoji {
].indexOf(runes[3]) !== -1) {
out = out.slice(0, 4)
}

output += out.reduce((result, item) => {
result += String.fromCharCode(item)
return result
}, '')
if(decodeTo!="hex"){
output += out.reduce((result, item) => {
result += String.fromCharCode(item)
return result
}, '')
}else{
output += out.reduce((result, item) => {
outputArray.push(item);
return result;
},'');
}

}

if(decodeTo=="hex"){
var newString = Buffer.from(outputArray);
output=newString.toString("hex");
//output=newString
}
return output.decode()
}

Expand Down
Loading