@whiteslove/parsing-lexicon 0.2.9 → 0.2.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whiteslove/parsing-lexicon",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Shared deterministic multilingual parsing lexicon for Whiteslove housing and hiring services",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,13 @@ import { maskPhoneLikeSpans } from './contact.js';
12
12
  const PRICE_KEYWORD = '(?:цена|ціна|нарх(?:и)?|narx|price|стоимост[ьи]|аренд(?:а|ная\\s+плата)?|rent)';
13
13
  // moneyCurrencyPattern() includes short codes (cad, ron, aed...) with no
14
14
  // boundary of its own, so "100 cadastru" would otherwise read "cad" off an
15
- // unrelated word as the Canadian dollar.
16
- const PRICE_CURRENCY = `(?:(?<![\\p{L}\\p{N}_])(?:${moneyCurrencyPattern()})(?![\\p{L}\\p{N}_]))`;
15
+ // unrelated word as the Canadian dollar. Only the side facing away from the
16
+ // paired number gets a boundary: the side facing the number is legitimately
17
+ // adjacent to a digit with no separator ("350$", "$100"), so guarding it
18
+ // too would reject those ordinary forms.
19
+ const CURRENCY_ALT = `(?:${moneyCurrencyPattern()})`;
20
+ const PRICE_CURRENCY_AFTER_NUMBER = `(?:${CURRENCY_ALT}(?![\\p{L}\\p{N}_]))`;
21
+ const PRICE_CURRENCY_BEFORE_NUMBER = `(?:(?<![\\p{L}\\p{N}_])${CURRENCY_ALT})`;
17
22
 
18
23
  function escapeRegex(value) {
19
24
  return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -54,11 +59,11 @@ export function parseHousingPrice(value, fallbackCurrency = '') {
54
59
 
55
60
  if (price == null) {
56
61
  let tagged = null;
57
- // 'u' is required for PRICE_CURRENCY's \p{L}/\p{N} boundary escapes to work
58
- // as Unicode property classes — without it they silently match nothing,
62
+ // 'u' is required for the \p{L}/\p{N} boundary escapes to work as
63
+ // Unicode property classes — without it they silently match nothing,
59
64
  // which had made the boundary guard a no-op.
60
- const reNumSym = new RegExp(`(${MONEY_NUMBER_PATTERN})\\s*${PRICE_CURRENCY}`, 'igu');
61
- const reSymNum = new RegExp(`${PRICE_CURRENCY}\\s*(${MONEY_NUMBER_PATTERN})`, 'igu');
65
+ const reNumSym = new RegExp(`(${MONEY_NUMBER_PATTERN})\\s*${PRICE_CURRENCY_AFTER_NUMBER}`, 'igu');
66
+ const reSymNum = new RegExp(`${PRICE_CURRENCY_BEFORE_NUMBER}\\s*(${MONEY_NUMBER_PATTERN})`, 'igu');
62
67
  for (const regex of [reNumSym, reSymNum]) {
63
68
  let match;
64
69
  while ((match = regex.exec(text)) !== null) {