strict-money-parse 1.0.2 → 1.0.3

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=["AED","AFN","ALL","AMD","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BHD","BIF","BMD","BND","BOB","BOV","BRL","BSD","BTN","BWP","BYN","BZD","CAD","CDF","CHE","CHF","CHW","CLF","CLP","CNY","COP","COU","CRC","CUP","CVE","CZK","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FJD","FKP","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HTG","HUF","IDR","ILS","INR","IQD","IRR","ISK","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRU","MUR","MVR","MWK","MXN","MXV","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SLE","SOS","SRD","SSP","STN","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","USN","UYI","UYU","UYW","UZS","VED","VES","VND","VUV","WST","XAD","XAF","XAG","XAU","XBA","XBB","XBC","XBD","XCD","XCG","XDR","XOF","XPD","XPF","XPT","XSU","XTS","XUA","XXX","YER","ZAR","ZMW","ZWG"],g={"€":"EUR","₴":"UAH","₸":"KZT","₼":"AZN","₾":"GEL","₪":"ILS","֏":"AMD","฿":"THB","₫":"VND","₱":"PHP","₲":"PYG","₡":"CRC","₮":"MNT","₦":"NGN","₩":"KRW","₺":"TRY","₹":"INR","₽":"RUB","৳":"BDT","៛":"KHR","₭":"LAK","₵":"GHS","د.ك":"KWD",Rp:"IDR",RM:"MYR",KSh:"KES",Kč:"CZK",zł:"PLN",Ft:"HUF",лв:"BGN","лв.":"BGN",грн:"UAH","грн.":"UAH",TL:"TRY",ALL:"ALL","ر.س.":"SAR","ر.س":"SAR",DH:"MAD",DA:"DZD",DT:"TND",KD:"KWD","GH₵":"GHS","so'm":"UZS","so m":"UZS",sum:"UZS",soʻm:"UZS",Q:"GTQ",RD$:"DOP","RD $":"DOP","S/":"PEN","S /":"PEN",$U:"UYU","$ U":"UYU",Bs:"BOB","Bs.":"BOB",K:"PGK",VT:"VUV",Rf:"MVR",FJD$:"FJD","FJD $":"FJD",BDS$:"BBD","BDS $":"BBD",US$:"USD","US $":"USD",CA$:"CAD","CA $":"CAD",AU$:"AUD","AU $":"AUD",A$:"AUD","A $":"AUD",NZ$:"NZD","NZ $":"NZD",S$:"SGD","S $":"SGD",HK$:"HKD","HK $":"HKD",NT$:"TWD","NT $":"TWD",EC$:"XCD","EC $":"XCD",R$:"BRL","R $":"BRL","E£":"EGP","E £":"EGP","£E":"EGP","£ E":"EGP","£S":"SYP","£ S":"SYP","S£":"SYP","S £":"SYP","JP¥":"JPY","JP ¥":"JPY","CN¥":"CNY","CN ¥":"CNY",円:"JPY"},N={$:["USD","CAD","AUD","NZD","SGD","HKD","MXN","ARS","CLP","COP","BBD","BMD","BND","BZD","FJD","GYD","KYD","LRD","NAD","SRD","TTD","XCD","BSD","JMD","SBD"],"¥":["JPY","CNY"],"¥":["JPY","CNY"],"£":["GBP","FKP","GIP","SHP","LBP","EGP","SYP","GGP","IMP","JEP"],kr:["DKK","NOK","SEK","ISK"],Lei:["RON","MDL"],Leu:["RON","MDL"],C$:["CAD","CRC"],R:["ZAR","ZWL"],"р.":["BYN","RUB"],р:["BYN","RUB"],Fr:["CHF","XAF","XOF","XPF","DJF"],"₨":["INR","PKR","LKR","NPR","SCR"],"Rs.":["PKR","INR","LKR","NPR","SCR","MUR"],Rs:["PKR","INR","LKR","NPR","SCR","MUR"]},B=new Set(Object.keys(N));function R(n){const t={iso4217:new Set(U),uniqueSymbols:{...g},ambiguousHints:{...N},ambiguousSymbols:new Set(B)};return n?{iso4217:n.iso4217??t.iso4217,uniqueSymbols:{...t.uniqueSymbols,...n.uniqueSymbols??{}},ambiguousHints:{...t.ambiguousHints,...n.ambiguousHints??{}},ambiguousSymbols:new Set(Object.keys({...t.ambiguousHints,...n.ambiguousHints??{}}))}:t}function C(n){return n.trim().replace(/[\u00A0\u2009]/g," ").replace(/['']/g," ").replace(/\s+/g," ")}function y(n){const e=/\d[\d\s,.'"_]*/g.exec(n);return e?{token:e[0].trim(),index:e.index}:null}function b(n,t){const e=n.lastIndexOf("."),s=n.lastIndexOf(",");let i=n;if(e!==-1&&s!==-1){const r=e>s?".":",",c=r==="."?",":".";i=i.replace(new RegExp(`[${c}\\s'"_]`,"g"),"").replace(r,".")}else if(e!==-1||s!==-1){const r=e!==-1?e:s,c=n.slice(r+1).replace(/\D/g,"").length;c<=t&&c>0?i=i.replace(/[\s'"_,.](?=.*[,.])/g,"").replace(",","."):i=i.replace(/[\s'"_,.]/g,"")}else i=i.replace(/[\s'"_]/g,"");const o=parseFloat(i);return isNaN(o)?null:o}function K(n,t,e){return!!(t.replace(/\D/g,"").length>=10||/\b\d{4}[-/]\d{1,2}[-/]\d{1,2}\b/.test(n)||/\b\d{1,2}[-/]\d{1,2}[-/]\d{2,4}\b/.test(n)||/^\s*(19|20)\d{2}\s*$/.test(n)||e&&/%/.test(n)||/\d+\s*[-–—]\s*\d+/.test(n)||/\d+\s*[x×]\s*\d+/i.test(n))}function M(n,t,e,s,i){const o=Math.max(0,t-i),r=Math.min(n.length,t+e+i),c=n.slice(o,t),a=n.slice(t+e,r),D=c+a,S=D.match(/\b([A-Z]{3})\b/);if(S&&s.iso4217.has(S[1]))return{status:"CONFIRMED",currency:S[1],symbol:null,hints:[]};const d=Object.keys(s.uniqueSymbols).sort((u,l)=>l.length-u.length);for(const u of d){const l=u.replace(/\s+/g,"");if(D.replace(/\s+/g,"").includes(l))return{status:"CONFIRMED",currency:s.uniqueSymbols[u],symbol:u,hints:[]}}const m=Array.from(s.ambiguousSymbols).sort((u,l)=>l.length-u.length);for(const u of m){const l=u.replace(/\s+/g,"");if(D.replace(/\s+/g,"").includes(l))return{status:"AMBIGUOUS",currency:null,symbol:u,hints:s.ambiguousHints[u]||[]}}return{status:"UNKNOWN",currency:null,symbol:null,hints:[]}}function P(n,t){const e={tables:t?.tables||R(),domain:t?.domain||"price",maxSymbolDistance:t?.maxSymbolDistance??6,ignorePercentages:t?.ignorePercentages??!0,maxFractionDigits:t?.maxFractionDigits},s=e.maxFractionDigits??(e.domain==="crypto"?8:e.domain==="fx"?4:2),i=C(n),o={matchedText:n,normalizedText:i},r=y(i);if(!r)return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:o};if(o.amountToken=r.token,K(i,r.token,e.ignorePercentages))return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:o};const c=b(r.token,s);if(c===null)return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:o};const a=M(i,r.index,r.token.length,e.tables,e.maxSymbolDistance);return a.currency&&(o.isoCodeFound=a.currency),a.symbol&&(o.symbolFound=a.symbol),{status:a.status,rawAmount:c,currency:a.currency,symbol:a.symbol,currencyHints:a.hints,evidence:o}}const f=["price","cost","total","subtotal","amount","sum","pay","payment"];function T(n,t,e){let s=0;n.rawAmount!==null&&(s+=10),n.status==="CONFIRMED"?s+=50:n.status==="AMBIGUOUS"&&(s+=20),n.evidence.isoCodeFound&&(s+=30);const i=Math.max(0,e-50),o=Math.min(t.length,e+100),r=t.slice(i,o).toLowerCase();for(const c of f)if(r.includes(c)){s+=10;break}return s}function G(n,t){const e={tables:t?.tables||R(),domain:t?.domain||"price",maxSymbolDistance:t?.maxSymbolDistance??6,ignorePercentages:t?.ignorePercentages??!0,maxFractionDigits:t?.maxFractionDigits,maxCandidates:t?.maxCandidates??10},s=[],i=/\d[\d\s,.'"_]*/g;let o;for(;(o=i.exec(n))!==null;){const r=o.index,c=o.index+o[0].length,a=Math.max(0,r-e.maxSymbolDistance),D=Math.min(n.length,c+e.maxSymbolDistance),S=n.slice(a,D),d=P(S,{tables:e.tables,domain:e.domain,maxSymbolDistance:e.maxSymbolDistance,ignorePercentages:e.ignorePercentages,maxFractionDigits:e.maxFractionDigits}),m={...d,score:0,indexStart:r,indexEnd:c};m.score=T(m,n,r),d.rawAmount!==null&&s.push(m)}return s.sort((r,c)=>c.score!==r.score?c.score-r.score:r.indexStart-c.indexStart),s.slice(0,e.maxCandidates)}exports.buildCurrencyTables=R;exports.parsePriceCandidates=G;exports.parsePriceString=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=["AED","AFN","ALL","AMD","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BHD","BIF","BMD","BND","BOB","BOV","BRL","BSD","BTN","BWP","BYN","BZD","CAD","CDF","CHE","CHF","CHW","CLF","CLP","CNY","COP","COU","CRC","CUP","CVE","CZK","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FJD","FKP","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HTG","HUF","IDR","ILS","INR","IQD","IRR","ISK","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRU","MUR","MVR","MWK","MXN","MXV","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SLE","SOS","SRD","SSP","STN","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","USN","UYI","UYU","UYW","UZS","VED","VES","VND","VUV","WST","XAD","XAF","XAG","XAU","XBA","XBB","XBC","XBD","XCD","XCG","XDR","XOF","XPD","XPF","XPT","XSU","XTS","XUA","XXX","YER","ZAR","ZMW","ZWG"],g={"€":"EUR","₴":"UAH","₸":"KZT","₼":"AZN","₾":"GEL","₪":"ILS","֏":"AMD","฿":"THB","₫":"VND","₱":"PHP","₲":"PYG","₡":"CRC","₮":"MNT","₦":"NGN","₩":"KRW","₺":"TRY","₹":"INR","₽":"RUB","৳":"BDT","៛":"KHR","₭":"LAK","₵":"GHS","د.ك":"KWD",Rp:"IDR",RM:"MYR",KSh:"KES",Kč:"CZK",zł:"PLN",Ft:"HUF",лв:"BGN","лв.":"BGN",грн:"UAH","грн.":"UAH",TL:"TRY",ALL:"ALL","ر.س.":"SAR","ر.س":"SAR",DH:"MAD",DA:"DZD",DT:"TND",KD:"KWD","GH₵":"GHS","so'm":"UZS","so m":"UZS",sum:"UZS",soʻm:"UZS",Q:"GTQ",RD$:"DOP","RD $":"DOP","S/":"PEN","S /":"PEN",$U:"UYU","$ U":"UYU",Bs:"BOB","Bs.":"BOB",K:"PGK",VT:"VUV",Rf:"MVR",FJD$:"FJD","FJD $":"FJD",BDS$:"BBD","BDS $":"BBD",US$:"USD","US $":"USD",CA$:"CAD","CA $":"CAD",AU$:"AUD","AU $":"AUD",A$:"AUD","A $":"AUD",NZ$:"NZD","NZ $":"NZD",S$:"SGD","S $":"SGD",HK$:"HKD","HK $":"HKD",NT$:"TWD","NT $":"TWD",EC$:"XCD","EC $":"XCD",R$:"BRL","R $":"BRL","E£":"EGP","E £":"EGP","£E":"EGP","£ E":"EGP","£S":"SYP","£ S":"SYP","S£":"SYP","S £":"SYP","JP¥":"JPY","JP ¥":"JPY","CN¥":"CNY","CN ¥":"CNY",円:"JPY"},N={$:["USD","CAD","AUD","NZD","SGD","HKD","MXN","ARS","CLP","COP","BBD","BMD","BND","BZD","FJD","GYD","KYD","LRD","NAD","SRD","TTD","XCD","BSD","JMD","SBD"],"¥":["JPY","CNY"],"¥":["JPY","CNY"],"£":["GBP","FKP","GIP","SHP","LBP","EGP","SYP","GGP","IMP","JEP"],kr:["DKK","NOK","SEK","ISK"],Lei:["RON","MDL"],Leu:["RON","MDL"],C$:["CAD","CRC"],R:["ZAR","ZWL"],"р.":["BYN","RUB"],р:["BYN","RUB"],Fr:["CHF","XAF","XOF","XPF","DJF"],"₨":["INR","PKR","LKR","NPR","SCR"],"Rs.":["PKR","INR","LKR","NPR","SCR","MUR"],Rs:["PKR","INR","LKR","NPR","SCR","MUR"]},y=new Set(Object.keys(N));function R(n){const t={iso4217:new Set(U),uniqueSymbols:{...g},ambiguousHints:{...N},ambiguousSymbols:new Set(y)};return n?{iso4217:n.iso4217??t.iso4217,uniqueSymbols:{...t.uniqueSymbols,...n.uniqueSymbols??{}},ambiguousHints:{...t.ambiguousHints,...n.ambiguousHints??{}},ambiguousSymbols:new Set(Object.keys({...t.ambiguousHints,...n.ambiguousHints??{}}))}:t}function B(n){return n.trim().replace(/[\u00A0\u2009]/g," ").replace(/['']/g," ").replace(/\s+/g," ")}function C(n){const e=/\d[\d\s,.'"_]*/g.exec(n);return e?{token:e[0].trim(),index:e.index}:null}function b(n,t){const e=n.lastIndexOf("."),s=n.lastIndexOf(",");let r=n;if(e!==-1&&s!==-1){const i=e>s?".":",",o=i==="."?",":".";r=r.replace(new RegExp(`[${o}\\s'"_]`,"g"),"").replace(i,".")}else if(e!==-1||s!==-1){const i=e!==-1?e:s,o=n.slice(i+1).replace(/\D/g,"").length;o>0&&(o<=t&&o!==3||o>3)?r=r.replace(/[\s'"_,.](?=.*[,.])/g,"").replace(",","."):r=r.replace(/[\s'"_,.]/g,"")}else r=r.replace(/[\s'"_]/g,"");const c=parseFloat(r);return isNaN(c)?null:c}function K(n,t,e){return!!(t.replace(/\D/g,"").length>=10||/\b\d{4}[-/]\d{1,2}[-/]\d{1,2}\b/.test(n)||/\b\d{1,2}[-/]\d{1,2}[-/]\d{2,4}\b/.test(n)||/^\s*(19|20)\d{2}\s*$/.test(n)||e&&/%/.test(n)||/\d+\s*[-–—]\s*\d+/.test(n)||/\d+\s*[x×]\s*\d+/i.test(n))}function M(n,t,e,s,r){const c=Math.max(0,t-r),i=Math.min(n.length,t+e+r),o=n.slice(c,t),a=n.slice(t+e,i),D=o+a,S=D.match(/\b([A-Z]{3})\b/);if(S&&s.iso4217.has(S[1]))return{status:"CONFIRMED",currency:S[1],symbol:null,hints:[]};const d=Object.keys(s.uniqueSymbols).sort((u,l)=>l.length-u.length);for(const u of d){const l=u.replace(/\s+/g,"");if(D.replace(/\s+/g,"").includes(l))return{status:"CONFIRMED",currency:s.uniqueSymbols[u],symbol:u,hints:[]}}const m=Array.from(s.ambiguousSymbols).sort((u,l)=>l.length-u.length);for(const u of m){const l=u.replace(/\s+/g,"");if(D.replace(/\s+/g,"").includes(l))return{status:"AMBIGUOUS",currency:null,symbol:u,hints:s.ambiguousHints[u]||[]}}return{status:"UNKNOWN",currency:null,symbol:null,hints:[]}}function P(n,t){const e={tables:t?.tables||R(),domain:t?.domain||"price",maxSymbolDistance:t?.maxSymbolDistance??6,ignorePercentages:t?.ignorePercentages??!0,maxFractionDigits:t?.maxFractionDigits},s=e.maxFractionDigits??(e.domain==="crypto"?8:e.domain==="fx"?4:2),r=B(n),c={matchedText:n,normalizedText:r},i=C(r);if(!i)return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:c};if(c.amountToken=i.token,K(r,i.token,e.ignorePercentages))return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:c};const o=b(i.token,s);if(o===null)return{status:"UNKNOWN",rawAmount:null,currency:null,symbol:null,currencyHints:[],evidence:c};const a=M(r,i.index,i.token.length,e.tables,e.maxSymbolDistance);return a.currency&&(c.isoCodeFound=a.currency),a.symbol&&(c.symbolFound=a.symbol),{status:a.status,rawAmount:o,currency:a.currency,symbol:a.symbol,currencyHints:a.hints,evidence:c}}const f=["price","cost","total","subtotal","amount","sum","pay","payment"];function T(n,t,e){let s=0;n.rawAmount!==null&&(s+=10),n.status==="CONFIRMED"?s+=50:n.status==="AMBIGUOUS"&&(s+=20),n.evidence.isoCodeFound&&(s+=30);const r=Math.max(0,e-50),c=Math.min(t.length,e+100),i=t.slice(r,c).toLowerCase();for(const o of f)if(i.includes(o)){s+=10;break}return s}function G(n,t){const e={tables:t?.tables||R(),domain:t?.domain||"price",maxSymbolDistance:t?.maxSymbolDistance??6,ignorePercentages:t?.ignorePercentages??!0,maxFractionDigits:t?.maxFractionDigits,maxCandidates:t?.maxCandidates??10},s=[],r=/\d[\d\s,.'"_]*/g;let c;for(;(c=r.exec(n))!==null;){const i=c.index,o=c.index+c[0].length,a=Math.max(0,i-e.maxSymbolDistance),D=Math.min(n.length,o+e.maxSymbolDistance),S=n.slice(a,D),d=P(S,{tables:e.tables,domain:e.domain,maxSymbolDistance:e.maxSymbolDistance,ignorePercentages:e.ignorePercentages,maxFractionDigits:e.maxFractionDigits}),m={...d,score:0,indexStart:i,indexEnd:o};m.score=T(m,n,i),d.rawAmount!==null&&s.push(m)}return s.sort((i,o)=>o.score!==i.score?o.score-i.score:i.indexStart-o.indexStart),s.slice(0,e.maxCandidates)}exports.buildCurrencyTables=R;exports.parsePriceCandidates=G;exports.parsePriceString=P;
package/dist/index.mjs CHANGED
@@ -364,32 +364,32 @@ function d(n) {
364
364
  function g(n) {
365
365
  return n.trim().replace(/[\u00A0\u2009]/g, " ").replace(/['']/g, " ").replace(/\s+/g, " ");
366
366
  }
367
- function C(n) {
367
+ function y(n) {
368
368
  const e = /\d[\d\s,.'"_]*/g.exec(n);
369
369
  return e ? {
370
370
  token: e[0].trim(),
371
371
  index: e.index
372
372
  } : null;
373
373
  }
374
- function y(n, t) {
374
+ function C(n, t) {
375
375
  const e = n.lastIndexOf("."), s = n.lastIndexOf(",");
376
- let i = n;
376
+ let r = n;
377
377
  if (e !== -1 && s !== -1) {
378
- const r = e > s ? "." : ",", c = r === "." ? "," : ".";
379
- i = i.replace(new RegExp(`[${c}\\s'"_]`, "g"), "").replace(r, ".");
378
+ const i = e > s ? "." : ",", o = i === "." ? "," : ".";
379
+ r = r.replace(new RegExp(`[${o}\\s'"_]`, "g"), "").replace(i, ".");
380
380
  } else if (e !== -1 || s !== -1) {
381
- const r = e !== -1 ? e : s, c = n.slice(r + 1).replace(/\D/g, "").length;
382
- c <= t && c > 0 ? i = i.replace(/[\s'"_,.](?=.*[,.])/g, "").replace(",", ".") : i = i.replace(/[\s'"_,.]/g, "");
381
+ const i = e !== -1 ? e : s, o = n.slice(i + 1).replace(/\D/g, "").length;
382
+ o > 0 && (o <= t && o !== 3 || o > 3) ? r = r.replace(/[\s'"_,.](?=.*[,.])/g, "").replace(",", ".") : r = r.replace(/[\s'"_,.]/g, "");
383
383
  } else
384
- i = i.replace(/[\s'"_]/g, "");
385
- const o = parseFloat(i);
386
- return isNaN(o) ? null : o;
384
+ r = r.replace(/[\s'"_]/g, "");
385
+ const c = parseFloat(r);
386
+ return isNaN(c) ? null : c;
387
387
  }
388
388
  function b(n, t, e) {
389
389
  return !!(t.replace(/\D/g, "").length >= 10 || /\b\d{4}[-/]\d{1,2}[-/]\d{1,2}\b/.test(n) || /\b\d{1,2}[-/]\d{1,2}[-/]\d{2,4}\b/.test(n) || /^\s*(19|20)\d{2}\s*$/.test(n) || e && /%/.test(n) || /\d+\s*[-–—]\s*\d+/.test(n) || /\d+\s*[x×]\s*\d+/i.test(n));
390
390
  }
391
- function K(n, t, e, s, i) {
392
- const o = Math.max(0, t - i), r = Math.min(n.length, t + e + i), c = n.slice(o, t), a = n.slice(t + e, r), D = c + a, S = D.match(/\b([A-Z]{3})\b/);
391
+ function K(n, t, e, s, r) {
392
+ const c = Math.max(0, t - r), i = Math.min(n.length, t + e + r), o = n.slice(c, t), a = n.slice(t + e, i), D = o + a, S = D.match(/\b([A-Z]{3})\b/);
393
393
  if (S && s.iso4217.has(S[1]))
394
394
  return {
395
395
  status: "CONFIRMED",
@@ -437,52 +437,52 @@ function M(n, t) {
437
437
  maxSymbolDistance: t?.maxSymbolDistance ?? 6,
438
438
  ignorePercentages: t?.ignorePercentages ?? !0,
439
439
  maxFractionDigits: t?.maxFractionDigits
440
- }, s = e.maxFractionDigits ?? (e.domain === "crypto" ? 8 : e.domain === "fx" ? 4 : 2), i = g(n), o = {
440
+ }, s = e.maxFractionDigits ?? (e.domain === "crypto" ? 8 : e.domain === "fx" ? 4 : 2), r = g(n), c = {
441
441
  matchedText: n,
442
- normalizedText: i
443
- }, r = C(i);
444
- if (!r)
442
+ normalizedText: r
443
+ }, i = y(r);
444
+ if (!i)
445
445
  return {
446
446
  status: "UNKNOWN",
447
447
  rawAmount: null,
448
448
  currency: null,
449
449
  symbol: null,
450
450
  currencyHints: [],
451
- evidence: o
451
+ evidence: c
452
452
  };
453
- if (o.amountToken = r.token, b(i, r.token, e.ignorePercentages))
453
+ if (c.amountToken = i.token, b(r, i.token, e.ignorePercentages))
454
454
  return {
455
455
  status: "UNKNOWN",
456
456
  rawAmount: null,
457
457
  currency: null,
458
458
  symbol: null,
459
459
  currencyHints: [],
460
- evidence: o
460
+ evidence: c
461
461
  };
462
- const c = y(r.token, s);
463
- if (c === null)
462
+ const o = C(i.token, s);
463
+ if (o === null)
464
464
  return {
465
465
  status: "UNKNOWN",
466
466
  rawAmount: null,
467
467
  currency: null,
468
468
  symbol: null,
469
469
  currencyHints: [],
470
- evidence: o
470
+ evidence: c
471
471
  };
472
472
  const a = K(
473
- i,
474
- r.index,
475
- r.token.length,
473
+ r,
474
+ i.index,
475
+ i.token.length,
476
476
  e.tables,
477
477
  e.maxSymbolDistance
478
478
  );
479
- return a.currency && (o.isoCodeFound = a.currency), a.symbol && (o.symbolFound = a.symbol), {
479
+ return a.currency && (c.isoCodeFound = a.currency), a.symbol && (c.symbolFound = a.symbol), {
480
480
  status: a.status,
481
- rawAmount: c,
481
+ rawAmount: o,
482
482
  currency: a.currency,
483
483
  symbol: a.symbol,
484
484
  currencyHints: a.hints,
485
- evidence: o
485
+ evidence: c
486
486
  };
487
487
  }
488
488
  const f = [
@@ -498,9 +498,9 @@ const f = [
498
498
  function G(n, t, e) {
499
499
  let s = 0;
500
500
  n.rawAmount !== null && (s += 10), n.status === "CONFIRMED" ? s += 50 : n.status === "AMBIGUOUS" && (s += 20), n.evidence.isoCodeFound && (s += 30);
501
- const i = Math.max(0, e - 50), o = Math.min(t.length, e + 100), r = t.slice(i, o).toLowerCase();
502
- for (const c of f)
503
- if (r.includes(c)) {
501
+ const r = Math.max(0, e - 50), c = Math.min(t.length, e + 100), i = t.slice(r, c).toLowerCase();
502
+ for (const o of f)
503
+ if (i.includes(o)) {
504
504
  s += 10;
505
505
  break;
506
506
  }
@@ -514,10 +514,10 @@ function T(n, t) {
514
514
  ignorePercentages: t?.ignorePercentages ?? !0,
515
515
  maxFractionDigits: t?.maxFractionDigits,
516
516
  maxCandidates: t?.maxCandidates ?? 10
517
- }, s = [], i = /\d[\d\s,.'"_]*/g;
518
- let o;
519
- for (; (o = i.exec(n)) !== null; ) {
520
- const r = o.index, c = o.index + o[0].length, a = Math.max(0, r - e.maxSymbolDistance), D = Math.min(n.length, c + e.maxSymbolDistance), S = n.slice(a, D), R = M(S, {
517
+ }, s = [], r = /\d[\d\s,.'"_]*/g;
518
+ let c;
519
+ for (; (c = r.exec(n)) !== null; ) {
520
+ const i = c.index, o = c.index + c[0].length, a = Math.max(0, i - e.maxSymbolDistance), D = Math.min(n.length, o + e.maxSymbolDistance), S = n.slice(a, D), R = M(S, {
521
521
  tables: e.tables,
522
522
  domain: e.domain,
523
523
  maxSymbolDistance: e.maxSymbolDistance,
@@ -526,12 +526,12 @@ function T(n, t) {
526
526
  }), m = {
527
527
  ...R,
528
528
  score: 0,
529
- indexStart: r,
530
- indexEnd: c
529
+ indexStart: i,
530
+ indexEnd: o
531
531
  };
532
- m.score = G(m, n, r), R.rawAmount !== null && s.push(m);
532
+ m.score = G(m, n, i), R.rawAmount !== null && s.push(m);
533
533
  }
534
- return s.sort((r, c) => c.score !== r.score ? c.score - r.score : r.indexStart - c.indexStart), s.slice(0, e.maxCandidates);
534
+ return s.sort((i, o) => o.score !== i.score ? o.score - i.score : i.indexStart - o.indexStart), s.slice(0, e.maxCandidates);
535
535
  }
536
536
  export {
537
537
  d as buildCurrencyTables,
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAIb,MAAM,SAAS,CAAC;AA+KjB,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,YAAY,GAClB,WAAW,CA0Fb"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAIb,MAAM,SAAS,CAAC;AAsLjB,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,YAAY,GAClB,WAAW,CA0Fb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strict-money-parse",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Strict TypeScript library for parsing monetary values from strings with evidence-based currency detection",
5
5
  "author": {
6
6
  "name": "Yurii Dejurin",