Skip to content
This repository has been archived by the owner on Jan 9, 2022. It is now read-only.

Commit

Permalink
Fixed the babel to ES5 transpiling.
Browse files Browse the repository at this point in the history
Main problem encountered: pdfkit (version 0.8.0 and above) was not ES5 compliant
  • Loading branch information
FlorianCassayre committed Sep 7, 2019
1 parent d605d03 commit 0680bd4
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 76 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion assets/scripts/main.js
Expand Up @@ -11,5 +11,4 @@ import './vendor/panzoom'
import './vendor/seedrandom'
import './vendor/parse-gedcom'

import './fan'
import './ui'
40 changes: 37 additions & 3 deletions assets/scripts/parse.js
Expand Up @@ -265,8 +265,9 @@ function buildHierarchy(json, config) {
}

function toJson(data) {
const decoder = new TextDecoder("utf-8");
const text = decoder.decode(data);

const view = new Uint8Array(data);
const text = Utf8ArrayToStr(view);
const parsed = parseGedcom.parse(text);

const isAnsi = getFirst(parsed.filter(byTag(TAG_HEAD)).flatMap(a => a.tree.filter(byTag(TAG_ENCODING)).map(a => a.data)), null) === TAG_ANSI;
Expand All @@ -277,7 +278,6 @@ function toJson(data) {
const builder = [];
const mask = 0x80;

const view = new Uint8Array(data);
for(let i = 0; i < view.length; i++) {
const charCode = view[i];
builder.push((charCode & mask) === 0 ? String.fromCharCode(charCode) : extendedAsciiTable.charAt(charCode ^ mask));
Expand All @@ -296,6 +296,40 @@ function getIndividualsList(json) {
);
}

// http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt
function Utf8ArrayToStr(array) {
let out, i, len, c;
let char2, char3;

out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += String.fromCharCode(c);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = array[i++];
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
}

module.exports = {
buildIndividual: buildIndividual,
toJson: toJson,
Expand Down

0 comments on commit 0680bd4

Please sign in to comment.