scripture-guide 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,7 +157,10 @@ module.exports = {
157
157
  i = i.replace(/([\u3131-\uD79D]) *([0-9]+)/ig, "$1 $2장 ");
158
158
  i = i.replace(/([0-9]+):([0-9]+)-([0-9]+)/g, "$1장 $2~$3절");
159
159
  i = i.replace(/[–-]+/g,"~");
160
- i = i.replace(/\s*:\s*([0-9~]+)/g, "$1절");
160
+ i = i.replace(/\s*:\s*([0-9~]+)/g, ":$1절");
161
+ i = i.replace(/([0-9]+):([0-9]+)/g, "$1장$2");
162
+ i = i.replace(/장:([0-9]+)/g, "장 $1");
163
+
161
164
  i = i.replace(/;/g, "; ").replace(/\s+/g, " ").trim();
162
165
  i = i.replace(/제\s*([3-4])장\s*니파이/g, "제$1니파이");
163
166
  i = i.replace(/([0-9]+)장\s*([0-9]+)/g, "$1장 $2");
@@ -169,6 +172,11 @@ module.exports = {
169
172
  i = i.replace(/(\d+) *장/g, "$1");
170
173
  i = i.replace(/(\d+) *절/g, "$1");
171
174
  i = i.replace(/([\u3131-\uD79D]) *(\d+)/ig, "$1 $2");
175
+ i = i.replace(/제 ([3-4])/g, "제$1");
176
+ i = i.replace(/조셉 스미스[—-]/g, "조셉 스미스—");
177
+ //replace commas with semicolons, unless a digit is on both sides of the comma
178
+ i = i.replace(/, *([^0-9])/g, "; $1");
179
+ console.log(i);
172
180
  return i;
173
181
  }
174
182
  }
@@ -96,12 +96,12 @@ module.exports = {
96
96
  ["d(?:octrine)*\\.* *(?:&|&|and)* *c(?:ovenants)*(?:\\s*\\bSec(?:tion)*)*\\.*", "Doctrine and Covenants"],
97
97
  ["dee and see", "Doctrine and Covenants"],
98
98
 
99
- ["Moses", "Moses"],
99
+ ["moses", "Moses"],
100
100
  ["Abra*\\.*(?:ham)*", "Abraham"],
101
101
  ["Jos(?:eph)*\\.* Smith(?:[–—\\- ]+Matthew)", "Joseph Smith\u2014Matthew"],
102
102
  ["Jos(?:eph)*\\.* Smith(?:[–—\\- ]+History)", "Joseph Smith\u2014History"],
103
- ["JS[—\\-]*\\s*[H]", "Joseph Smith History"],
104
- ["JS[—\\-]*\\s*[M]", "Joseph Smith Matthew"],
103
+ ["JS[—\\-]*\\s*[H]", "Joseph Smith\u2014History"],
104
+ ["JS[—\\-]*\\s*[M]", "Joseph Smith\u2014Matthew"],
105
105
  ["a(?:rticles)*[ _-]*o[ _-f]*f(?:aith)*", "Articles of Faith"],
106
106
 
107
107
  [",* *jst", "JST"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scripture-guide",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "A utility for biblical and scripture reference parsing that enables structured queries based on strings of traditional scripture references (e.g. John 3:16). ",
5
5
  "main": "scriptures-compiled.js",
6
6
  "scripts": {
@@ -113,13 +113,14 @@ var lookupReference = function lookupReference(query) {
113
113
  return {
114
114
  "query": query,
115
115
  "ref": ref,
116
- //"gen": generateReference(verse_ids),
116
+ "gen": generateReference(verse_ids),
117
117
  "verse_ids": verse_ids
118
118
  };
119
119
  };
120
120
  var lookupSingleRef = function lookupSingleRef(ref) {
121
+ var booksWithDashRegex = /^(joseph|조셉)/i; // TODO: get from lang config
121
122
  //todo: better handling of multi-book ranges for unicode
122
- if (ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
123
+ if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
123
124
  var book = getBook(ref);
124
125
  if (!book) return [];
125
126
  var ranges = getRanges(ref, book);
@@ -184,14 +185,14 @@ var strToHash = function strToHash(str) {
184
185
  //max 32
185
186
  if (hash > 2147483647) hash = hash % 2147483647;
186
187
  }
187
- return "::".concat(hash, "::");
188
+ return "==".concat(hash, "==");
188
189
  };
189
190
  var cleanReference = function cleanReference(messyReference) {
190
191
  var ref = messyReference.replace(/[\s]+/g, " ").trim();
191
192
  var hasNoAlpha = !/[A-Za-z]/.test(ref);
192
193
  if (hasNoAlpha) wordBreak = "";
193
194
  ref = preProcess(ref);
194
-
195
+ var buffer = wordBreak ? "" : " ";
195
196
  //Build Regex rules
196
197
  var regex = raw_regex.pre_rules;
197
198
  for (var i in regex) {
@@ -199,9 +200,9 @@ var cleanReference = function cleanReference(messyReference) {
199
200
  ref = ref.replace(re, regex[i][1]);
200
201
  }
201
202
  var srcbooks = raw_regex.books;
202
- var dstbooks = raw_regex.books.map(function (i) {
203
+ var dstbooks = buffer ? raw_regex.books.map(function (i) {
203
204
  return [i[1], i[1]];
204
- });
205
+ }) : [];
205
206
  var bookMatchList = [].concat(_toConsumableArray(dstbooks), _toConsumableArray(srcbooks)).sort(function (a, b) {
206
207
  return b[0].length - a[0].length;
207
208
  });
@@ -213,7 +214,6 @@ var cleanReference = function cleanReference(messyReference) {
213
214
  var hash = strToHash(book);
214
215
  hashCypher[book] = hash;
215
216
  }
216
- var buffer = wordBreak ? "" : " ";
217
217
  for (var _i2 in regex) {
218
218
  var re = new RegExp(wordBreak + buffer + regex[_i2][0] + buffer + "\\.*" + wordBreak, "ig");
219
219
  var replacement = hashCypher[regex[_i2][1]] || regex[_i2][1];
@@ -250,6 +250,7 @@ var splitReferences = function splitReferences(compoundReference) {
250
250
  };
251
251
  var getBook = function getBook(ref) {
252
252
  var book = ref.replace(/([ 0-9:,-]+)$/, '').trim();
253
+ book = book.replace(/-/g, "—");
253
254
  if (bookExists(book)) return book;
254
255
  return false;
255
256
  };
@@ -545,9 +546,6 @@ var detectReferences = function detectReferences(content, callBack) {
545
546
  matches = matches.filter(function (i) {
546
547
  return i.length <= 1000;
547
548
  });
548
- console.log({
549
- matches: matches
550
- });
551
549
 
552
550
  // split by matches
553
551
  var pieces;
package/scriptures.js CHANGED
@@ -81,15 +81,16 @@ const lookupReference = function(query) {
81
81
  return {
82
82
  "query": query,
83
83
  "ref": ref,
84
- //"gen": generateReference(verse_ids),
84
+ "gen": generateReference(verse_ids),
85
85
  "verse_ids": verse_ids
86
86
  };
87
87
  }
88
88
 
89
89
  const lookupSingleRef = function(ref) {
90
90
 
91
+ const booksWithDashRegex = /^(joseph|조셉)/i; // TODO: get from lang config
91
92
  //todo: better handling of multi-book ranges for unicode
92
- if (ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
93
+ if (!booksWithDashRegex.test(ref) && ref.match(/[—-](\d\s)*[A-Za-z\u3131-\uD79D]/ig)) return lookupMultiBookRange(ref);
93
94
  let book = getBook(ref);
94
95
  if (!book) return [];
95
96
  let ranges = getRanges(ref, book);
@@ -162,7 +163,7 @@ const strToHash = function(str) {
162
163
  //max 32
163
164
  if (hash > 2147483647) hash = hash % 2147483647;
164
165
  }
165
- return `::${hash}::`;
166
+ return `==${hash}==`;
166
167
  }
167
168
 
168
169
 
@@ -175,7 +176,7 @@ const cleanReference = function(messyReference) {
175
176
 
176
177
  ref = preProcess(ref);
177
178
 
178
-
179
+ const buffer = wordBreak ? "" : " ";
179
180
  //Build Regex rules
180
181
  let regex = raw_regex.pre_rules;
181
182
  for (let i in regex) {
@@ -183,7 +184,7 @@ const cleanReference = function(messyReference) {
183
184
  ref = ref.replace(re, regex[i][1]);
184
185
  }
185
186
  let srcbooks = raw_regex.books;
186
- let dstbooks = raw_regex.books.map(i => [i[1], i[1]]);
187
+ let dstbooks = buffer ? raw_regex.books.map(i => [i[1], i[1]]) : [];
187
188
  let bookMatchList = [...dstbooks, ...srcbooks].sort((a, b) => b[0].length - a[0].length);
188
189
  regex = bookMatchList;
189
190
  let hashCypher = {};
@@ -192,7 +193,6 @@ const cleanReference = function(messyReference) {
192
193
  const hash = strToHash(book);
193
194
  hashCypher[book] = hash;
194
195
  }
195
- const buffer = wordBreak ? "" : " ";
196
196
  for (let i in regex) {
197
197
  var re = new RegExp( wordBreak + buffer + regex[i][0] + buffer + "\\.*"+wordBreak, "ig");
198
198
  let replacement = hashCypher[regex[i][1]] || regex[i][1];
@@ -205,7 +205,6 @@ const cleanReference = function(messyReference) {
205
205
  return bookValue + " ";
206
206
  }
207
207
  );
208
-
209
208
  regex = raw_regex.post_rules;
210
209
  for (let i in regex) {
211
210
  var re = new RegExp(regex[i][0], "ig");
@@ -232,6 +231,7 @@ const splitReferences = function(compoundReference) {
232
231
  }
233
232
  const getBook = function(ref) {
234
233
  let book = ref.replace(/([ 0-9:,-]+)$/, '').trim();
234
+ book = book.replace(/-/g, "—");
235
235
  if (bookExists(book)) return book;
236
236
  return false;
237
237
  }
@@ -525,8 +525,6 @@ const detectReferences = (content,callBack,wordBreak="\\b") => {
525
525
  matches = matches.map(trimExternalMatchStrings)
526
526
  matches = matches.filter(i => i.length <= 1000);
527
527
 
528
- console.log({matches});
529
-
530
528
  // split by matches
531
529
  let pieces;
532
530
  try {
package/test-lang.js CHANGED
@@ -1,27 +1,30 @@
1
1
  const {lookup, generateReference, setLanguage, detectReferences}= require("./scriptures.js");
2
2
 
3
- console.log(lookup("Alma 5:3"));
4
- setLanguage("ko");
5
- console.log(lookup("니파이후서 1장 4절"));
6
- setLanguage();
7
- console.log(lookup("Helaman 6:26"));
3
+
8
4
  setLanguage("ko");
9
5
  //korean tests
10
6
  const lookUpTests = [
11
7
  "이더서 13장 18절",
12
8
  "니전5.2",
9
+ "제3니파이 2장 8절",
10
+ "제3니파이 23장 7절",
11
+ "조셉 스미스—역사 1장 30절",
12
+ "이더서 1장 32~35절, 이더서 7장 26절, 이더서 9장 23절",
13
13
 
14
- ]
14
+ ];
15
15
 
16
16
  lookUpTests.forEach(t=>{
17
17
  const result = lookup(t);
18
18
  console.log({result});
19
19
  });
20
-
20
+ process.exit();
21
21
  setLanguage();
22
- //korean tests
22
+ //english tests
23
23
  const lookUpTests2 = [
24
- "Alma 5:3",
24
+ "Moses 1:1",
25
+ "3 Nephi 9:3",
26
+ "Joseph Smith—History 1:20",
27
+
25
28
  ]
26
29
 
27
30
  lookUpTests2.forEach(t=>{