Skip to content

Commit

Permalink
🔨 Tweak preprocess function
Browse files Browse the repository at this point in the history
  • Loading branch information
gluons committed Oct 15, 2017
1 parent a688c6c commit bdc8582
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/lib/datasource-utils/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ function preprocess(data): AddressEntry[] {
let words = [];
let expanded = [];
let useLookup = false;
let t;

if (data.lookup && data.words) {
// compact with dictionary and lookup
useLookup = true;
lookup = data.lookup.split('|');
words = data.words.split('|');
data = data.data;
}

t = text => {
let t = text => {
function repl(m) {
let ch = m.charCodeAt(0);
return words[ch < 97 ? ch - 65 : 26 + ch - 97];
Expand All @@ -37,6 +27,14 @@ function preprocess(data): AddressEntry[] {
return text.replace(/[A-Z]/ig, repl);
};

if (data.lookup && data.words) {
// compact with dictionary and lookup
useLookup = true;
lookup = data.lookup.split('|');
words = data.words.split('|');
data = data.data;
}

if (!data[0].length) {
// non-compacted database
return data;
Expand Down

0 comments on commit bdc8582

Please sign in to comment.