hh-shipments 0.3.9 → 0.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/extract.js +12 -1
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "test": "node test/run-tests.js && node test/run-carriers-tests.js"
19
19
  },
20
20
  "type": "commonjs",
21
- "version": "0.3.9",
21
+ "version": "0.3.10",
22
22
  "bin": {
23
23
  "hh-shipments": "server.js"
24
24
  },
package/src/extract.js CHANGED
@@ -41,9 +41,20 @@
41
41
  function extractContext(text) {
42
42
  var out = { seller_name: null, device: null };
43
43
  if (!text) return out;
44
+ // A plausible person name: no digits (addresses have them), not ALL CAPS
45
+ // (shipping-label blocks are), proper name shape. Shipping labels like
46
+ // "ORANGE NJ 07050 DWT: 11,9,7" must never land in the seller field.
47
+ function looksLikeName(s) {
48
+ s = String(s).trim();
49
+ if (!s || s.length > 40) return false;
50
+ if (/\d/.test(s)) return false;
51
+ if (/^[A-Z\s.,'-]+$/.test(s)) return false;
52
+ if (!/^[A-Za-z][A-Za-z .,'-]*$/.test(s)) return false;
53
+ return true;
54
+ }
44
55
  // WhatsApp export style: "[10/12/26, 9:41 AM] John Smith: message"
45
56
  var m = text.match(/^\[?[^\]\n]*\]?\s*([^:\[\]\n]{2,40}):\s/m);
46
- if (m && !/^(you|me|http)/i.test(m[1].trim())) out.seller_name = m[1].trim();
57
+ if (m && !/^(you|me|http)/i.test(m[1].trim()) && looksLikeName(m[1])) out.seller_name = m[1].trim();
47
58
  // "from John", "seller: John"
48
59
  if (!out.seller_name) {
49
60
  var m2 = text.match(/(?:from|seller)\s*:\s*([A-Z][a-z]+(?:\s+[A-Z][a-z]+)?)/);