highmark-markdown 0.0.451 → 0.0.453
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.
- package/example.js +95 -74
- package/lib/constants.js +17 -1
- package/lib/example/importer.js +2 -2
- package/lib/example/indexOptions.js +2 -2
- package/lib/utilities/index.js +81 -71
- package/package.json +2 -2
- package/src/constants.js +4 -0
- package/src/example/importer.js +0 -2
- package/src/example/indexOptions.js +1 -1
- package/src/utilities/index.js +124 -98
package/src/utilities/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import { arrayUtilities } from "necessary";
|
|
|
4
4
|
|
|
5
5
|
import IndexMatch from "../index/match";
|
|
6
6
|
|
|
7
|
-
import { EMPTY_STRING, SINGLE_SPACE } from "../constants";
|
|
8
7
|
import { forEach, mapKeys, mapValues } from "../utilities/object";
|
|
8
|
+
import { Y_STRING, S_STRING, IES_STRING, EMPTY_STRING, SINGLE_SPACE, PARENTHESISED_S_STRING } from "../constants";
|
|
9
9
|
|
|
10
10
|
const { compress } = arrayUtilities;
|
|
11
11
|
|
|
@@ -14,16 +14,16 @@ export function indexMapFromDivisionMarkdownNodes(divisionMarkdownNodes, context
|
|
|
14
14
|
|
|
15
15
|
removeIgnoredWords(indexMap, context);
|
|
16
16
|
|
|
17
|
-
adjustProperNouns(indexMap, context);
|
|
18
|
-
|
|
19
|
-
adjustAcronyms(indexMap, context);
|
|
20
|
-
|
|
21
17
|
adjustMixedPlurals(indexMap, context);
|
|
22
18
|
|
|
23
19
|
adjustPluralPlurals(indexMap, context);
|
|
24
20
|
|
|
25
21
|
adjustSingularPlurals(indexMap, context);
|
|
26
22
|
|
|
23
|
+
adjustProperNouns(indexMap, context);
|
|
24
|
+
|
|
25
|
+
adjustAcronyms(indexMap, context);
|
|
26
|
+
|
|
27
27
|
compressPageNumbers(indexMap);
|
|
28
28
|
|
|
29
29
|
return indexMap;
|
|
@@ -145,7 +145,7 @@ function adjustProperNouns(indexMap, context) {
|
|
|
145
145
|
function preparePlainText(plainText) {
|
|
146
146
|
plainText = plainText.toLowerCase(); ///
|
|
147
147
|
|
|
148
|
-
plainText = plainText.replace(/[^a-
|
|
148
|
+
plainText = plainText.replace(/[^a-z0-9 ]/g, SINGLE_SPACE);
|
|
149
149
|
|
|
150
150
|
plainText = plainText.replace(/\s+/g, SINGLE_SPACE);
|
|
151
151
|
|
|
@@ -184,31 +184,45 @@ function adjustAcronyms(indexMap, context) {
|
|
|
184
184
|
function adjustMixedPlurals(indexMap, context) {
|
|
185
185
|
const { indexOptions } = context,
|
|
186
186
|
{ plurals } = indexOptions,
|
|
187
|
-
mixedPlurals =
|
|
187
|
+
mixedPlurals = reducePlurals(plurals, isMixed),
|
|
188
|
+
pluralPlurals = mapPlurals(mixedPlurals, mixedToPlural),
|
|
189
|
+
singularPlurals = mapPlurals(mixedPlurals, mixedToSingular);
|
|
188
190
|
|
|
189
191
|
forEach(indexMap, (wordOrPhrase, pageNumbers) => {
|
|
190
|
-
const
|
|
192
|
+
const singularPluralsIncludesWordOrPhrase = singularPlurals.includes(wordOrPhrase);
|
|
191
193
|
|
|
192
|
-
if (
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
if (singularPluralsIncludesWordOrPhrase) {
|
|
195
|
+
const singularWordOrPhrase = wordOrPhrase, ///
|
|
196
|
+
singularPageNumbers = pageNumbers, ///
|
|
197
|
+
mixedWordOrPhrase = singularToMixed(singularWordOrPhrase),
|
|
198
|
+
mixedPageNumbers = indexMap[mixedWordOrPhrase] || [];
|
|
197
199
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
pageNumbers = [
|
|
201
|
+
...singularPageNumbers,
|
|
202
|
+
...mixedPageNumbers
|
|
203
|
+
];
|
|
201
204
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
delete indexMap[singularWordOrPhrase];
|
|
206
|
+
|
|
207
|
+
indexMap[mixedWordOrPhrase] = pageNumbers;
|
|
208
|
+
}
|
|
206
209
|
|
|
207
|
-
|
|
208
|
-
delete indexMap[singularEntry];
|
|
210
|
+
const pluralPluralsIncludesWordOrPhrase = pluralPlurals.includes(wordOrPhrase);
|
|
209
211
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
if (pluralPluralsIncludesWordOrPhrase) {
|
|
213
|
+
const pluralWordOrPhrase = wordOrPhrase, ///
|
|
214
|
+
pluralPageNumbers = pageNumbers, ///
|
|
215
|
+
mixedWordOrPhrase = pluralToMixed(pluralWordOrPhrase),
|
|
216
|
+
mixedPageNumbers = indexMap[mixedWordOrPhrase] || [];
|
|
217
|
+
|
|
218
|
+
pageNumbers = [
|
|
219
|
+
...pluralPageNumbers,
|
|
220
|
+
...mixedPageNumbers
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
delete indexMap[pluralWordOrPhrase];
|
|
224
|
+
|
|
225
|
+
indexMap[mixedWordOrPhrase] = pageNumbers;
|
|
212
226
|
}
|
|
213
227
|
});
|
|
214
228
|
}
|
|
@@ -216,29 +230,26 @@ function adjustMixedPlurals(indexMap, context) {
|
|
|
216
230
|
function adjustPluralPlurals(indexMap, context) {
|
|
217
231
|
const { indexOptions } = context,
|
|
218
232
|
{ plurals } = indexOptions,
|
|
219
|
-
pluralPlurals =
|
|
233
|
+
pluralPlurals = reducePlurals(plurals, isPlural),
|
|
234
|
+
singularPlurals = mapPlurals(pluralPlurals, pluralToSingular);
|
|
220
235
|
|
|
221
236
|
forEach(indexMap, (wordOrPhrase, pageNumbers) => {
|
|
222
|
-
const
|
|
237
|
+
const singularPluralsIncludesWordOrPhrase = singularPlurals.includes(wordOrPhrase);
|
|
223
238
|
|
|
224
|
-
if (
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
239
|
+
if (singularPluralsIncludesWordOrPhrase) {
|
|
240
|
+
const singularWordOrPhrase = wordOrPhrase, ///
|
|
241
|
+
singularPageNumbers = pageNumbers, ///
|
|
242
|
+
pluralWordOrPhrase = singularToPlural(wordOrPhrase),
|
|
243
|
+
pluralPageNumbers = indexMap[pluralWordOrPhrase] || [];
|
|
228
244
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
pageNumbers = [ ///
|
|
234
|
-
...pluralPageNumbers,
|
|
235
|
-
...singularPageNumbers
|
|
236
|
-
];
|
|
245
|
+
pageNumbers = [
|
|
246
|
+
...singularPageNumbers,
|
|
247
|
+
...pluralPageNumbers
|
|
248
|
+
];
|
|
237
249
|
|
|
238
|
-
|
|
250
|
+
delete indexMap[singularWordOrPhrase];
|
|
239
251
|
|
|
240
|
-
|
|
241
|
-
}
|
|
252
|
+
indexMap[pluralWordOrPhrase] = pageNumbers;
|
|
242
253
|
}
|
|
243
254
|
});
|
|
244
255
|
}
|
|
@@ -246,98 +257,113 @@ function adjustPluralPlurals(indexMap, context) {
|
|
|
246
257
|
function adjustSingularPlurals(indexMap, context) {
|
|
247
258
|
const { indexOptions } = context,
|
|
248
259
|
{ plurals } = indexOptions,
|
|
249
|
-
singularPlurals =
|
|
260
|
+
singularPlurals = reducePlurals(plurals, isSingular),
|
|
261
|
+
pluralPlurals = mapPlurals(singularPlurals, singularToPlural);
|
|
250
262
|
|
|
251
263
|
forEach(indexMap, (wordOrPhrase, pageNumbers) => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (entryPlural) {
|
|
255
|
-
const singularEntry = wordOrPhrase.replace(/s$/, EMPTY_STRING),
|
|
256
|
-
singularPluralsIncludesSingularEntry = singularPlurals.includes(singularEntry),
|
|
257
|
-
entrySingularPlural = singularPluralsIncludesSingularEntry; ///
|
|
264
|
+
const pluralPluralsIncludesWordOrPhrase = pluralPlurals.includes(wordOrPhrase);
|
|
258
265
|
|
|
259
|
-
if (
|
|
260
|
-
const
|
|
261
|
-
singularPageNumbers = indexMap[
|
|
266
|
+
if (pluralPluralsIncludesWordOrPhrase) {
|
|
267
|
+
const singularWordOrPhrase = pluralToSingular(wordOrPhrase),
|
|
268
|
+
singularPageNumbers = indexMap[singularWordOrPhrase] || [],
|
|
269
|
+
pluralWordOrPhrase = wordOrPhrase, ///
|
|
270
|
+
pluralPageNumbers = pageNumbers; ///
|
|
262
271
|
|
|
263
|
-
pageNumbers = [
|
|
264
|
-
...
|
|
265
|
-
...
|
|
272
|
+
pageNumbers = [
|
|
273
|
+
...singularPageNumbers,
|
|
274
|
+
...pluralPageNumbers
|
|
266
275
|
];
|
|
267
276
|
|
|
268
|
-
delete indexMap[
|
|
277
|
+
delete indexMap[pluralWordOrPhrase];
|
|
269
278
|
|
|
270
|
-
indexMap[
|
|
279
|
+
indexMap[singularWordOrPhrase] = pageNumbers;
|
|
271
280
|
}
|
|
272
|
-
}
|
|
273
281
|
});
|
|
274
282
|
}
|
|
275
283
|
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
const
|
|
284
|
+
function reducePlurals(plurals, callback) {
|
|
285
|
+
plurals = plurals.reduce((plurals, plural) => { ///
|
|
286
|
+
const result = callback(plural);
|
|
279
287
|
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
singularPlurals.push(singularPlural);
|
|
288
|
+
if (result) {
|
|
289
|
+
plurals.push(plural);
|
|
284
290
|
}
|
|
285
291
|
|
|
286
|
-
return
|
|
292
|
+
return plurals;
|
|
287
293
|
}, []);
|
|
288
294
|
|
|
289
|
-
return
|
|
295
|
+
return plurals;
|
|
290
296
|
}
|
|
291
297
|
|
|
292
|
-
function
|
|
293
|
-
|
|
294
|
-
|
|
298
|
+
function mapPlurals(plurals, callback) {
|
|
299
|
+
plurals = plurals.map((plural) => { ///
|
|
300
|
+
plural = callback(plural);
|
|
295
301
|
|
|
296
|
-
|
|
297
|
-
|
|
302
|
+
return plural;
|
|
303
|
+
});
|
|
298
304
|
|
|
299
|
-
|
|
300
|
-
|
|
305
|
+
return plurals;
|
|
306
|
+
}
|
|
301
307
|
|
|
302
|
-
|
|
303
|
-
|
|
308
|
+
function isSingular(text) {
|
|
309
|
+
const indexMatches = /[^s)]$/.test(text),
|
|
310
|
+
singular = indexMatches; ///
|
|
304
311
|
|
|
305
|
-
return
|
|
312
|
+
return singular;
|
|
306
313
|
}
|
|
307
314
|
|
|
308
|
-
function
|
|
309
|
-
const
|
|
310
|
-
|
|
315
|
+
function isPlural(text) {
|
|
316
|
+
const indexMatches = /(ies|s)$/.test(text),
|
|
317
|
+
plural = indexMatches; ///
|
|
311
318
|
|
|
312
|
-
|
|
313
|
-
|
|
319
|
+
return plural;
|
|
320
|
+
}
|
|
314
321
|
|
|
315
|
-
|
|
316
|
-
|
|
322
|
+
function isMixed(text) {
|
|
323
|
+
const indexMatches = /\(s\)$/.test(text),
|
|
324
|
+
mixed = indexMatches; ///
|
|
317
325
|
|
|
318
|
-
|
|
319
|
-
|
|
326
|
+
return mixed;
|
|
327
|
+
}
|
|
320
328
|
|
|
321
|
-
|
|
329
|
+
function mixedToPlural(text) {
|
|
330
|
+
text = text ///
|
|
331
|
+
.replace(/\(s\)$/, S_STRING);
|
|
332
|
+
|
|
333
|
+
return text;
|
|
322
334
|
}
|
|
323
335
|
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
336
|
+
function pluralToMixed(text) {
|
|
337
|
+
text = text ///
|
|
338
|
+
.replace(/s$/, PARENTHESISED_S_STRING)
|
|
327
339
|
|
|
328
|
-
return
|
|
340
|
+
return text;
|
|
329
341
|
}
|
|
330
342
|
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
|
|
343
|
+
function mixedToSingular(text) {
|
|
344
|
+
text = text ///
|
|
345
|
+
.replace(/\(s\)$/, EMPTY_STRING);
|
|
334
346
|
|
|
335
|
-
return
|
|
347
|
+
return text;
|
|
336
348
|
}
|
|
337
349
|
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
plural = indexMatches; ///
|
|
350
|
+
function singularToMixed(text) {
|
|
351
|
+
text = `${text}(s)`;
|
|
341
352
|
|
|
342
|
-
return
|
|
353
|
+
return text;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function singularToPlural(text) {
|
|
357
|
+
text = `${text}s` ///
|
|
358
|
+
.replace(/ys$/, IES_STRING);
|
|
359
|
+
|
|
360
|
+
return text;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function pluralToSingular(text) {
|
|
364
|
+
text = text ///
|
|
365
|
+
.replace(/ies$/, Y_STRING)
|
|
366
|
+
.replace(/s$/, EMPTY_STRING);
|
|
367
|
+
|
|
368
|
+
return text;
|
|
343
369
|
}
|