arqam 2.0.1 → 2.0.2

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.
@@ -1,2 +1,2 @@
1
- /*! arqamWordsToNumbers v1.02 — Arabic number words back to numbers, by Mohsen Alyafei. ES module, self-contained: no dependencies, no network. MIT licence. Built from arqamWordsToNumbers.js. Readable source: https://github.com/MohsenAlyafei/arqam. */
2
- import{arqamAR as e}from"./arqamAR.mjs";const t=function(){function eng(){const t=void 0!==e?e:null;if(!t||"function"!=typeof t.toWords||"function"!=typeof t.removeTashkeel||"function"!=typeof t.createArqam||!t.currencies||!t.version||!t.utils||t.version.split(".").map(Number).reduce((e,t,n)=>e+t/(n?1e3:1),0)<1.064)throw new Error("arqamWordsToNumbers needs the Arqam library (arqamAR 1.64 or later): load arqamAR.js before arqamWordsToNumbers.js, or import it");return t}let t=null,n=null;function words(){const e=eng();return n!==e&&(n=e,t=e.createArqam()),t}const s=["تيريليونات",3,"تيريليونان",2,"تيريليونين",2,"تيريليونا",1,"تيريليوني",2,"تيريليونى",2,"تيريليون",0,"تريليونات",3,"تريليونان",2,"تريليونين",2,"تريليونا",1,"تريليوني",2,"تريليونى",2,"تريليون",0,"ترليونات",3,"ترليونان",2,"ترليونين",2,"ترليونا",1,"ترليوني",2,"ترليونى",2,"ترليون",0,"تريلونات",3,"تريلونان",2,"تريلونين",2,"تريلونا",1,"تريلوني",2,"تريلونى",2,"تريلون",0,"ترلونات",3,"ترلونان",2,"ترلونين",2,"ترلونا",1,"ترلوني",2,"ترلونى",2,"ترلون",0,"تيرليونات",3,"تيرليونان",2,"تيرليونين",2,"تيرليونا",1,"تيرليوني",2,"تيرليونى",2,"تيرليون",0,"تيريلونات",3,"تيريلونان",2,"تيريلونين",2,"تيريلونا",1,"تيريلوني",2,"تيريلونى",2,"تيريلون",0,"تيرلونات",3,"تيرلونان",2,"تيرلونين",2,"تيرلونا",1,"تيرلوني",2,"تيرلونى",2,"تيرلون",0],r=["ملياراي",2,"ملياراى",2,"ملاراي",2,"ملاراى",2,"ملايير",3,"مليارات",3,"مليارين",2,"ملياران",2,"ملياري",2,"مليارى",2,"مليارا",1,"مليار",0,"ميلايير",3,"ملارات",3,"ملارين",2,"ملاران",2,"ملاري",2,"ملارى",2,"ملارا",1,"ملار",0,"ملرات",3,"ملرين",2,"ملران",2,"ملري",2,"ملرى",2,"ملر",0,"مليارت",3,"مليارن",2,"ملير",0,"ميليارات",3,"ميليارين",2,"ميلياران",2,"ميلياري",2,"ميليارى",2,"ميليارا",1,"ميليار",0,"ميلارات",3,"ميلارين",2,"ميلاران",2,"ميلاري",2,"ميلارى",2,"ميلارا",1,"ميلار",0,"ميلرات",3,"ميلرين",2,"ميلران",2,"ميلري",2,"ميلرى",2,"ميلرا",1,"ميلر",0,"ميليارت",3,"ماليارن",2,"مالير",0,"ماليارات",3,"ماليارين",2,"مالياران",2,"مالياري",2,"ماليارى",2,"ماليارا",1,"ماليار",0,"مالارات",3,"مالارين",2,"مالرات",3,"مالرين",2,"مالران",2,"ماليارت",3,"بلايين",3,"بليونين",2,"بليونان",2,"بليونات",3,"بليونا",1,"بليوني",2,"بليونى",2,"بليون",0,"بلاين",3,"بلونين",2,"بلونان",2,"بلونا",1,"بلوني",2,"بلونى",2,"بلون",0,"بليونن",2,"بالايين",3,"باليونين",2,"باليونان",2,"باليونا",1,"باليوني",2,"باليونى",2,"باليون",0,"بالاين",3,"بالونين",2,"بالونان",2,"بالونا",1,"بالوني",2,"بالونى",2,"بالون",0,"باليونات",3,"باليونن",2,"بوليونان",2,"بوليونا",1,"بوليوني",2,"بوليونى",2,"بوليون",0,"بوليونات",3,"بوليونين",2,"بولونان",2,"بولونا",1,"بولوني",2,"بولونى",2,"بولون",0,"بولونين",2,"بوليونن",2],o=["مليونين",2,"ميليونين",2,"ملونين",2,"ميلونين",2,"مليونان",2,"ميليونان",2,"ملونان",2,"ميلونان",2,"مليونات",3,"مليونا",1,"ميليونا",1,"ملونا",1,"ميلونا",1,"مليوني",2,"مليونى",2,"ميليوني",2,"ميليونى",2,"ملوني",2,"ملونى",2,"ميلوني",2,"ميلونى",2,"مليون",0,"ميليون",0,"ملون",0,"ميلون",0,"ملايين",3,"ميلايين",3,"ملاين",3,"ميلاين",3],l=["الفان",2,"الفين",2,"الفي",2,"الفى",2,"الفات",3,"الفا",1,"الف",0,"الاف",3,"الوفات",3,"الوف",3,"الافات",3,"الافت",3],i=["عشره","عشرا","عسره","اعشر","اعسر","عشر","عسر","تيعشاره","تيعساره","تيعشار","تيعسار","تيعشره","تيعسره","تيعشر","تيعسر","تيشار","تيسار","تيشره","تيسره","تيشر","تيسر","تيشه","تيش","تعشاره","تعساره","تعشار","تعسار","تعشره","تعسره","تعشر","تعسر","تعيشه","تعيش","تعشه","تعسه","تعش","تعس","تاعشره","تاعسره","تاعشر","تاعسر","تاشره","تاسره","تاشر","تاسر","تاشه","تاسه","تاش","تاس","طيعشاره","طيعساره","طيعشار","طيعسار","طيعشره","طيعسره","طيعشر","طيعسر","طيشار","طيسار","طيشره","طيسره","طيشر","طيسر","طيشه","طيش","طيس","طعشاره","طعساره","طعشار","طعسار","طعشره","طعسره","طعشر","طعسر","طعيشه","طعيسه","طعيش","طعيس","طعشه","طعسه","طعش","طعس","طاعشره","طاعسره","طاعشر","طاعسر","طاشره","طاسره","طاشر","طاسر","طاشه","طاش","طاس","طاسه","تشره","تشر","طشره","طشر","طسره","طسر","يشره","يشر","يسره","يسر","اشره","اشر","اسره","اسر","عش","عس","تش","طش","طس","اش","يش","شر","ش"],a=["رون","رين","رن","ون","ين"],c=["عشره","عشرا","عسره","عسرا","عشر","عسر","اشر","اسر","يشر","يسر"],u=["مئتان","مئتا","مئتين","مئتي","مئتن","مئيتان","مئيتين","مئيتي","مئيتا","مئيتن","مائتين","مائتي","مائتى","مئتى","مائتان","مائتا","مائيتين","مائيتي","مائيتان","مائيتا","مايتين","مايئتين","مايتي","مايئتي","مايتان","مايئتان","مايتا","مايئتا","ميئتين","ميئتي","ميئتن","ميئتان","ميئتا","ميتين","ميتي","ميتن","ميتان","ميتا","ماتان","ماتئان","ماتين","ماتئين","ماتي","ماتئي","متين","متئين","متان","متئان","متي","متا","مائيه","مائه","مائا","مايئه","ماياه","مايا","مايه","ميئاه","ميئه","مياه","مييه","مئيا","مئيه","ميه","ميا","مئه"],f=new Set(u.slice(0,u.indexOf("مائيه"))),d=["واحده",1,"واحدا",1,"واهده",1,"واهدا",1,"واحدن",101,"واهدن",1,"واحد",1,"واهد",1,"وحده",1,"وهده",1,"وحدا",101,"وهدا",101,"وحد",101,"وهد",101,"احدى",101,"اهدى",101,"احدن",101,"اهدن",101,"احدا",101,"اهدا",101,"احد",101,"اهد",101,"حدا",101,"هدا",101,"حدى",101,"هدى",101,"حد",101,"هد",101,"ثنتينا",2,"ثانتينا",2,"تنتينا",2,"تانتينا",2,"اثنتينه",2,"اتنتينه",2,"ثنتينه",2,"ثانتينه",2,"تنتينه",2,"تانتينه",2,"ثنتانه",2,"ثانتانه",2,"تنتانه",2,"تلنتانه",2,"ثنتانا",2,"ثانتانا",2,"تنتانا",2,"تانتانا",2,"اثنتين",2,"اتنتين",2,"ثنتين",2,"ثانتين",2,"تنتين",2,"تانتين",2,"ثنتان",2,"ثانتان",2,"تنتان",2,"تانتان",2,"اثنتانا",2,"اتنتانا",2,"اثنتان",2,"اتنتان",2,"اثنتا",102,"اتنتا",102,"اثنتي",102,"اتنتي",102,"اثنتى",102,"اتنتى",102,"اثنينا",2,"اتنينا",2,"اثنينه",2,"اتنينه",2,"ثنينه",2,"ثانينه",2,"تنينه",2,"تانينه",2,"ثنينا",2,"ثانينا",2,"تنينا",2,"تانينا",2,"ثنانه",2,"ثانانه",2,"تنانه",2,"تانانه",2,"ثنانا",2,"ثانانا",2,"تنانا",2,"تانانا",2,"اثنين",2,"اتنين",2,"ثنين",2,"ثانين",2,"تنين",2,"تانين",2,"ثنان",2,"ثانان",2,"تنان",2,"تانان",2,"اثنانا",2,"اتنانا",2,"اثنان",2,"اتنان",2,"اثنا",102,"اتنا",102,"اثنيا",102,"اتنيا",102,"اثني",102,"اتني",102,"اثنى",102,"اتنى",102,"ثنتن",2,"تنتن",2,"ثنن",2,"تنن",2,"ثنتي",102,"تنتي",102,"ثنتى",102,"تنتى",102,"ثنتا",102,"تنتا",102,"ثني",102,"ثنى",102,"ثنا",102,"تني",102,"تنى",102,"تنا",102,"تن",102,"ثن",102,"طن",102,"ثلاثه",3,"تلاته",3,"ثلاته",3,"تلاثه",3,"ثلاثا",3,"تلاثا",3,"تلاتا",3,"ثلاتا",3,"ثلاطا",3,"تلاطا",3,"طلاتا",3,"طلاثا",3,"ثلاث",3,"تلات",3,"تلاث",3,"ثلات",3,"ثلاط",103,"تلاط",103,"طلات",103,"طلاث",103,"ثالاثه",3,"تالاته",3,"تالاثه",3,"ثالاته",3,"ثالاطه",3,"تالاطه",3,"طالاته",3,"طالاثه",3,"ثالاثا",3,"تالاتا",3,"تالاثا",3,"ثالاتا",3,"طالاتا",3,"طالاثا",3,"ثالاث",3,"تالات",3,"تالاث",3,"ثالات",3,"طالات",3,"طالاث",3,"ثالثا",103,"تالتا",103,"تالثا",103,"ثالتا",103,"طالتا",103,"طالثا",103,"ثالث",103,"تالت",103,"تالث",103,"ثالت",103,"ثالط",103,"طالت",103,"ثلثا",103,"تلتا",103,"تلثا",103,"ثلتا",103,"طلتا",103,"طلثا",103,"ثليثا",103,"تليتا",103,"تليثا",103,"ثليتا",103,"طليتا",103,"طليثا",103,"ثليث",103,"تليت",103,"تليث",103,"ثليت",103,"طليت",103,"طليث",103,"ثلث",103,"تلتون",30,"تلتو",103,"تلت",103,"تلث",103,"ثلت",103,"طلث",103,"طلت",103,"تولتون",30,"تولتو",103,"تولت",103,"ثولتون",30,"ثولتو",103,"ثولثون",30,"ثولثو",103,"تولثون",30,"تولثو",103,"ثولث",103,"تل",103,"ثل",103,"طل",103,"ثولثا",103,"تولتا",103,"طولتا",103,"طولتون",30,"طولتو",103,"طولت",103,"اربعه",4,"ارباعه",4,"اربعا",4,"ارباعا",4,"اربع",4,"ربعا",104,"رباعا",104,"ربعه",4,"رباعه",104,"رباع",104,"ربوع",104,"ربعون",40,"ربعو",104,"ربع",104,"روبعون",40,"روبعو",104,"روبع",104,"خمسه",5,"خامسه",105,"خمسا",5,"خامسا",105,"خمسون",50,"خمسو",105,"خمس",5,"خامس",105,"خومسون",50,"خومسو",105,"خومس",105,"ستا",6,"سته",6,"سوته",106,"سوتا",106,"سوتون",60,"سوتو",106,"سوت",106,"ستون",60,"ستو",106,"سيته",6,"سيتا",106,"سيت",106,"ست",6,"سودس",106,"سبعه",7,"سابعه",107,"سبعا",7,"سابعا",107,"سباه",107,"ساباه",107,"سبا",107,"سابا",107,"سوبعه",7,"سوبعا",7,"سوبا",107,"سوبعون",70,"سوبعو",107,"سوبع",107,"سبعون",70,"سبعو",107,"سبع",7,"سبيع",107,"سابع",107,"سابيع",107,"سابييع",107,"سبه",107,"سبيه",107,"سابه",107,"سب",107,"صوبعون",70,"صوبعو",107,"صوبع",107,"صبعا",107,"صبعون",70,"صبعو",107,"صبع",107,"صبا",107,"صوبا",107,"صبو",107,"ثمانيه",8,"تمانيه",8,"ثمانيا",8,"تمانيا",8,"ثمانين",80,"تمانين",80,"ثماني",8,"تماني",8,"ثمانى",8,"تمانى",8,"ثمانه",8,"تمانه",8,"ثمانا",8,"تمانا",8,"ثمان",8,"تمان",8,"ثمينا",8,"تمينا",8,"ثمينين",80,"تمينين",80,"ثميني",8,"تميني",8,"ثمينه",8,"تمينه",8,"ثمينى",8,"تمينى",8,"ثمنيا",8,"تمنيا",8,"ثمنيه",8,"تمنيه",8,"ثمنين",80,"تمنين",80,"ثمني",108,"ثمنى",108,"تمني",108,"تمنى",108,"ثمنا",108,"ثمنو",108,"تمنو",108,"ثيمانيه",8,"تيمانيه",8,"ثيمانيا",8,"تيمانيا",8,"ثيمانين",80,"تيمانين",80,"ثيماني",8,"تيماني",8,"ثيمانى",8,"تيمانى",8,"ثيمانه",8,"تيمانه",8,"ثيمانا",8,"تيمانا",8,"ثيمان",8,"تيمان",8,"ثيمنيا",8,"تيمنيا",8,"ثيمنيه",8,"تيمنيه",8,"ثيمنين",80,"تيمنين",80,"ثيمني",8,"تيمني",8,"ثيمنى",108,"تيمنى",108,"ثيمنا",108,"تيمنا",108,"ثيمن",108,"تيمن",108,"ثيمينا",8,"تيمينا",8,"ثيمينه",8,"تيمينه",8,"ثيمينين",80,"تيمينين",80,"ثيميني",8,"تيميني",8,"ثيمينى",8,"تيمينى",8,"ثيمين",108,"تيمين",108,"ثامانيه",8,"تامانيه",8,"ثامانيا",8,"تامانيا",8,"ثامانين",80,"تامانين",80,"ثاماني",8,"تاماني",8,"ثامانى",8,"تامانى",8,"ثامانه",8,"تامانه",8,"ثامانا",8,"تامانا",8,"ثامان",8,"تامان",8,"ثامينا",8,"تامينا",8,"ثامينه",8,"تامينه",8,"ثامينين",80,"تامينين",80,"ثاميني",8,"تاميني",8,"ثامينى",8,"تامينى",8,"ثامين",108,"تامين",108,"ثامنيه",8,"تامنيه",8,"ثامنيا",8,"تامنيا",8,"ثامني",108,"ثامنى",108,"تامني",108,"تامنى",108,"تمنا",108,"ثمن",108,"ثيمن",108,"ثامن",108,"تمن",108,"تيمن",108,"تامن",108,"تومنون",80,"تومنو",108,"تومن",108,"ثومنون",80,"ثومنو",108,"ثومن",108,"تسعه",9,"تيسعه",9,"تسعا",9,"تسعون",90,"تسعو",109,"تيسعا",9,"تيسعون",90,"تيسعو",109,"تسا",109,"تسه",109,"تيسا",109,"تسع",9,"تيسع",9,"تيس",109,"تس",109,"توسعون",90,"توسعو",109,"توسع",109].concat(["جوج",2,"زوج",2,"تسعود",9,"سطاش",16,"اتن",102,"اثن",102,"سط",106]),g=new Set(["تلت","ثلت","تمن","ربع"]),h=u.concat(["مياتين","مياتيين","اميه","اميا"]);for(const e of["مياتين","مياتيين"])f.add(e);const m=new Set(["مياه","متين","متي","متى","متا","زوج","وحده","وحدا","وحد","ثمينه","ثمين","تنين","ثلثين","تلتين"]),p={كوادرليون:["كوادريليون"],كوينتليون:["كوينتيليون"],سكستليون:["سكستيليون"],سيبتليون:["سبتليون","سيبتيليون"],وكتليون:["اوكتليون","اوكتيليون"],نونليون:["نونيليون"],ديسيليون:["ديسليون"]},w=[["ات",3],["ان",2],["ين",2],["ي",2],["ى",2],["ا",1],["",0]],k={short:null,long:null},v=/[\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06ED\u08D3-\u08E1\u08E3-\u08FF\uFE70-\uFE72\uFE74\uFE76-\uFE7F\u0640]/,S=new RegExp(v.source,"g"),y=/[\u0621-\u063A\u0641-\u064A\u0671-\u06D3]/;function norm(e){return e.replace(/[آأإٱٲٳٵ]/g,"ا").replace(/ؤ/g,"و").replace(/ة/g,"ه")}const x=/[\s،(«]/;function*matchesAfter(e,t,n=x){e.lastIndex=0;for(let s;s=e.exec(t);)0===s.index||n.test(t[s.index-1])?(yield s,s[0]||e.lastIndex++):e.lastIndex=s.index+1}const b=new WeakMap,W=new WeakMap;function scalesNorm(e){let t=b.get(e);return t||(t=e.map(([e,t,n])=>[e,t,n,norm(e)]),b.set(e,t)),t}function at(e,t,n){let s=0;for(;s<n.length;){for(;t<e.length&&v.test(e[t]);)t++;if(e[t]!==n[s])return-1;t++,s++}for(;t<e.length&&v.test(e[t]);)t++;return t}function skipSpaces(e,t){for(;t<e.length&&(" "===e[t]||" "===e[t]||"\t"===e[t]||v.test(e[t]));)t++;return t}const isLetterAt=(e,t)=>t<e.length&&y.test(e[t]);function atomsAt(e,t,n,s,r=0){s.memoS===e&&s.memoO===t||(s.memoS=e,s.memoO=t,s.memo=new Map);const o=8*n+r;if(s.memo.has(o))return s.memo.get(o).slice();const l=function atomsAtOnce(e,t,n,s,r){const o=[],tryFrom=(n,r)=>{{let t=n;for(;t<e.length&&v.test(e[t]);)t++;if(!function firstLetters(e){let t=W.get(e);if(t)return t;t=new Set(["ص"]);const add=e=>{const n=norm(String(e)).replace(S,"");n&&t.add(n[0])};for(let n=0;n<d.length;n+=2)add(d[n]);for(const n of h)add(n);for(const n of c)add(n);for(const n of i)add(n);for(const n of a)add(n);for(const n of scalesNorm(e))add(n[3]);return W.set(e,t),t}(s.scales).has(e[t]))return}for(const t of h){const s=at(e,n,t);s>=0&&o.push({kind:"h",v:f.has(t)?200:100,end:s,wa:r,word:t})}for(const s of function unitsAt(e,t){for(;t<e.length&&v.test(e[t]);)t++;if(!$){$=new Map;for(let e=0;e<d.length;e+=2){const t=d[e][0];$.has(t)||$.set(t,[]),$.get(t).push(e)}}return $.get(e[t])||[]}(e,n)){const l=d[s],c=at(e,n,l);if(c<0)continue;let u=d[s+1];const g=u>100;if(g&&(u-=100),u>10){o.push({kind:"t",v:u,end:c,wa:r,word:l});continue}for(const t of a){const n=at(e,skipSpaces(e,c),t);n>=0&&u>=3&&o.push({kind:"t",v:10*u,end:n,wa:r,word:l+t})}const p=skipSpaces(e,c);for(const t of i){const n=at(e,p,t);n>=0&&!a.some(t=>at(e,n,t)===n+t.length&&!isLetterAt(e,n+t.length))&&o.push({kind:"u",v:u+10,end:n,wa:r,word:l+" "+t})}if(u<=9)for(const t of h)if(!(f.has(t)||m.has(t)&&p>c)){const n=at(e,p,t);n>=0&&o.push({kind:"h",v:100*u,end:n,wa:r,word:l+t})}o.push({kind:"u",v:u,end:c,wa:r,word:l,only:g,tanween:/\u064B/.test(t.slice(n,c+1))})}for(const t of c){const s=at(e,n,t);if(s<0)continue;let l=!1;for(const n of a){const i=at(e,skipSpaces(e,s),n);i>=0&&(o.push({kind:"t",v:20,end:i,wa:r,word:t+n}),l=!0)}o.push({kind:"u",v:10,end:s,wa:r,word:t})}for(const[l,i,a,c]of scalesNorm(s.scales)){const s=at(e,n,c);s>=0&&o.push({kind:"s",v:i,type:a,end:s,wa:r,word:l,tanween:/\u064B/.test(t.slice(n,s+1))})}if(s.zero){let t=at(e,n,"صفرا");t<0&&(t=at(e,n,"صفر")),t>=0&&o.push({kind:"z",v:0,end:t,wa:r,word:"صفر"})}};tryFrom(n,!1),"و"===e[n]&&tryFrom(skipSpaces(e,n+1),!0);const l=o.filter(n=>!isLetterAt(e,n.end)||r<4&&atomsAt(e,t,n.end,s,r+1).length>0).filter(n=>!(n.only||!n.wa&&!s.ambiguous&&m.has(n.word))||r<4&&atomsAt(e,t,skipSpaces(e,n.end),s,r+1).some(t=>"t"===t.kind&&t.wa||n.only&&g.has(n.word)&&"s"===t.kind&&!t.wa&&(/^تا?لاف$/.test(t.word)||"لاف"===t.word&&/ت$/.test(n.word)&&t.end>n.end&&!/\s/.test(e.slice(n.end,t.end-3))))),u=new Set;return l.filter(e=>{const t=e.kind+e.end+"|"+e.v+"|"+e.wa+"|"+e.type;return!u.has(t)&&(u.add(t),!0)}).sort((e,t)=>t.end-e.end||e.wa-t.wa)}(e,t,n,s,r);return s.memo.set(o,l),l.slice()}let $=null;function readLarge(e){const t=[];let n=0;for(;n<e.length;){let s=0n,r=0n,o=0,l=null,i=n,a=0,c=n-1,u=0n,f=!1,d=!1,g=!1,h=!1;const close=()=>{c=i,u=s+r,g=d};for(;i<e.length;i++){const t=e[i],c=i===n,u=!c&&(o>0||f);if("s"===t.kind){const n=10n**BigInt(t.v),a=null!==l&&n===l&&h&&r<100n;if(null!==l&&n>=l&&!a)break;if(h=!a&&1===o&&!t.wa,!t.wa&&o>0&&!c){if(2===t.type)break;if(3===t.type&&!(r%100n>=3n&&r%100n<=10n||2n===r))break;s+=r*n}else{if(!c&&!t.wa)break;{if(3===t.type)break;let l=2===t.type?2n:1n;if(1===t.type&&!t.tanween&&i+1>=e.length&&t.nounAfter&&(l=2n),1===o&&t.wa)s+=(r+l)*n,d=!0;else{if(0!==o)break;s+=l*n}}}r=0n,o=0,l=a?n-1n:n,f=!0,close();continue}if(u&&!t.wa)break;if("z"===t.kind){if(!c)break;r=0n,o=9,close(),i++;break}if("h"===t.kind){if(0!==o)break;r=BigInt(t.v),o=1}else if("u"===t.kind){if(o>1)break;if(r+=BigInt(t.v),a=t.v,o=t.v>=10?3:2,t.only)continue}else if("t"===t.kind){if(3===o||2===o&&(a>9||!t.wa))break;r+=BigInt(t.v),o=3}close()}c<n?(t.push(null),n++):(t.push({from:n,to:c,value:u,legalOff:g}),n=c+1)}return t}function readSmall(e){const t=[];let n=0;for(;n<e.length;){let s=0n,r=0n,o="",l=null,i=n,a=n-1,c=0n,u=0,f=!1;const key=(e,t)=>2n*e+BigInt(t),endPart=e=>{const t=key(e,"h"===o?1:0);return!(null!==l&&t<=l||(l=t,s+=r*e,r=0n,o="",f=!1,0))};for(;i<e.length;i++){const t=e[i],d=i===n;if(!(d||t.wa||"s"===t.kind&&f))break;if("s"===t.kind){const n=10n**BigInt(t.v);if(f&&!t.wa){if(2===t.type)break;if(3===t.type&&!(r%100n>=3n&&r%100n<=10n||2n===r))break;if(!endPart(n))break}else{if(f&&!endPart(1n))break;if(3===t.type)break;let s=2===t.type?2n:1n;if(1===t.type&&!t.tanween&&i+1>=e.length&&(d||t.nounAfter)&&(s=2n),r=s,o="u",!endPart(n))break}a=i,c=s;continue}if("z"===t.kind){if(!d)break;a=i,c=0n,i++;break}const g="t"===t.kind&&f&&"u"===o&&u<=9&&t.wa&&!t.comma&&r<10n;if(!g){if(f&&!endPart(1n))break;r=0n,o="h"===t.kind?"h":"u",f=!0}if(r+=BigInt(t.v),"u"===t.kind&&(u=t.v),"t"!==t.kind||g||(u=99),"u"===t.kind&&t.only)continue;const h=[s,r,l],m=key(1n,"h"===o?1:0);(null===l||m>l)&&(a=i,c=s+r),[s,r,l]=h}a<n?(t.push(null),n++):(t.push({from:n,to:a,value:c}),n=a+1)}return t}function aloneAt(e,t,n,s,r){let o=skipSpaces(e,n);if(s){if("،"===e[o]&&(o=skipSpaces(e,o+1)),"و"!==t[o])return null;for(o++;v.test(e[o]);)o++}const l=currencyAt(e,t,o);if(!l||l.start!==skipSpaces(e,o))return null;if(/(^|\s)صفرا?\s*$/.test(e.slice(0,l.start).replace(/[\u064B-\u0652\u0670]/g,"")))return null;if(/[0-9٠-٩]\s*$/.test(e.slice(0,l.start)))return null;const i=l.list.filter(e=>!!e.minor==!!r&&!e.def&&e.count),a=[...new Set(i.map(e=>e.count))],c=[...new Set(i.map(e=>e.code))];if(!i.length||1!==a.length||2!==a[0]&&!i.some(e=>e.adj)&&!s&&e.slice(0,l.start).trim())return null;if(r&&!s&&!i.some(e=>e.adj)&&1!==c.length)return null;const u=nextWord(e,t,l.end),f=u&&/^(واحد[اةه]?|اثن(ان|ين|تان|تين|ا|تا))$/.test(u.w.replace(/[\u064B-\u0652\u0670]/g,""))&&!(()=>{const n=nextWord(e,t,u.end);return n&&/^عشر[هة]?$/.test(n.w)})();return f&&!r?null:{m:{...l,list:i},count:a[0],code:1===c.length?c[0]:null,end:f?u.end:l.end}}function findCore(e,t,n){const s=[];for(const r of function runs(e,t){const n=e,s=norm(e),r=[];let o=0;for(;o<s.length;){if(!isLetterAt(s,o)||o>0&&isLetterAt(s,o-1)&&!t.joined.has(o)){o++;continue}let e=o,l=atomsAt(s,n,o,t);if(!l.length&&"بفكل".includes(s[o])){let r=o+1;for(;r<s.length&&v.test(s[r]);)r++;l=atomsAt(s,n,r,t).filter(e=>!e.wa),l.length&&(e=r)}if(!l.length){for(;o<s.length&&(isLetterAt(s,o)||v.test(s[o]));)o++;continue}const i=[];let a=e,c=l;for(;c.length;){const e=c[0];i.push({...e,start:a});let r=skipSpaces(s,e.end),o=!1;"،"!==s[r]&&","!==s[r]||(o=!0,r=skipSpaces(s,r+1)),isLetterAt(s,e.end)&&(t.joined.add(e.end),r=e.end);const l=r<s.length?atomsAt(s,n,r,t):[],u=l.find(e=>e.wa||!o&&"s"===e.kind);if(!u||o&&!u.wa)break;const f=l.filter(e=>e.wa===u.wa);o&&f.forEach(e=>{e.comma=!0}),a=r,c=f}let u=i.length;for(let t=1;t<i.length;t++)if(i[t].comma&&"s"!==i[t-1].kind&&!i.slice(t).some(e=>"s"===e.kind)){u=t;break}{const e=i.slice(0,u),o=e[e.length-1],l=skipSpaces(s,o.end),a=s.slice(l).replace(S,"").match(/^\S+/),c="و"===s[l]&&!atomsAt(s,n,l+1,t).length&&(()=>{try{const e=currencyAt(n,s,l);return!!e&&e.start===l}catch(e){return!1}})();o.nounAfter=isLetterAt(s,l)&&("و"!==s[l]||c)&&!(a&&/^(فاصله|بالمائه|بالمئه|بالميه|في|الا|جزء)/.test(a[0])),r.push(e)}o=u<i.length?i[u-1].end:i[i.length-1].end}return r}(e,n)){const o=r[r.length-1],l=norm(e.slice(skipSpaces(e,o.end))).replace(S,""),i=/^[،,\s]*و?(جز[ءاي]|اجزاء)|^من\s/.test(l.replace(/^[،,\s]*و?\s*[0-9٠-٩][0-9٠-٩,٬]*\s*/,"")),a=/فاصل[هة][\u064B-\u0652]*[\s،]*$/.test(e.slice(Math.max(0,r[0].start-12),r[0].start));let c="small"!==t.order||a?readLarge(r):null,u="large"===t.order||a?null:readSmall(r);const f=/^[،,\s]*و[\u064B-\u0652]?\s*[0-9٠-٩]/.test(l);if(i&&f&&/^[،,\s]*و[\u064B-\u0652]?\s*[0-9٠-٩,٬]+\s*(جزء|اجزاء)/.test(l)){let e=r.length-1;for(;e>0&&!r[e].comma;)e--;const t=e>0?readLarge(r.slice(e)):null;if(t&&1===t.length&&t[0]&&t[0].value%1000n==0n&&t[0].value<1000000n){const n={...t[0],from:e,to:r.length-1},s=u?readSmall(r.slice(0,e)):null,o=c?readLarge(r.slice(0,e)):null;s&&1===s.length&&s[0]&&(u=[s[0],n]),o&&1===o.length&&o[0]&&(c=[o[0],n])}}const d=/^\s*[،,]\s*و\s*جز[ءاي]/.test(l);if(i&&!f&&!d){const one=e=>1===e.length&&e[0],e=l.match(/من\s+ال\s*ـ?\s*([0-9٠-٩][0-9٠-٩,٬]*)|من\s+(\S+(?:\s+\S+)?)/);let t=null;if(e&&e[1])t=BigInt(westDigits(e[1]));else if(e&&e[2])for(const s of[e[2],e[2].replace(/^ال/,"")]){const e=arqamWordsToNumbers.find(s,{order:"large",currency:"off"});if(e.length&&0===e[0].start){t=BigInt(e[0].value.split(".")[0]);break}}const n=one(readLarge(r));if(n&&(!t||n.value<t))c=[n],u=null;else for(let s=1;s<r.length;s++)if(r[s].comma){const e=one(readLarge(r.slice(s)));if(!e||t&&e.value>=t)continue;const n={...e,from:s,to:r.length-1},o=u?one(readSmall(r.slice(0,s))):null,l=c?one(readLarge(r.slice(0,s))):null;if(o||l){u=o?[o,n]:null,c=l?[l,n]:null;break}}}const count=e=>1e3*e.filter(Boolean).length+e.filter(e=>!e).length,g=r.some((e,t)=>t>0&&"h"===e.kind&&e.wa&&("u"===r[t-1].kind||"t"===r[t-1].kind)&&r.slice(t+1).some(e=>"s"===e.kind)),h=r.some((e,t)=>t>0&&e.comma&&"s"!==r[t-1].kind&&r.slice(t).some(e=>"s"===e.kind)),p=u?c?count(u)<count(c)||count(u)===count(c)&&(g||h)?u:c:u:c;for(const t of p){if(!t)continue;const o=r[t.from],l=r[t.to];if(t.from===t.to&&!n.ambiguous&&m.has(o.word))continue;let i=o.start;o.wa&&(i=skipSpaces(e,at(norm(e),o.start,"و"))),s.push({start:i,end:l.end,value:t.value,unit:"s"===l.kind?10n**BigInt(l.v):1n,wa:o.wa,waAt:o.start})}}return s}const frac=(e,t=1n)=>{const n=((e,t)=>{for(e=e<0n?-e:e;t;)[e,t]=[t,e%t];return e})(e,t)||1n;return{n:e/n,d:t/n}},fadd=(e,t)=>frac(e.n*t.d+t.n*e.d,e.d*t.d),fmul=(e,t)=>frac(e.n*t.n,e.d*t.d);function fracText(e,t){let{n,d:s}=e;const r=n<0n;r&&(n=-n);let o,l=s;for(;l%2n==0n;)l/=2n;for(;l%5n==0n;)l/=5n;if(1n===l){let e=0;for(;10n**BigInt(e)%s;)e++;void 0!==t&&t>e&&(e=t);const r=(n*10n**BigInt(e)/s).toString().padStart(e+1,"0");o=e?r.slice(0,-e)+"."+r.slice(-e):r}else{const e=n/s;o=(e?e+" ":"")+n%s+"/"+s}return(r?"-":"")+o}function nextWord(e,t,n){const s=skipSpaces(e,n);if(s>=e.length)return null;if("،"===e[s]||","===e[s])return{w:"،",start:s,end:s+1};if("%"===e[s]||"٪"===e[s])return{w:"%",start:s,end:s+1};if(/[0-9٠-٩]/.test(e[s])){let t=s;for(;t<e.length&&/[0-9٠-٩.,٫٬]/.test(e[t]);)t++;for(;/[.,٫٬]/.test(e[t-1]);)t--;return{w:e.slice(s,t),start:s,end:t,digits:!0}}if(!isLetterAt(t,s)&&"ـ"!==e[s])return null;let r=s;for(;r<e.length&&(isLetterAt(t,r)||v.test(e[r]));)r++;return{w:t.slice(s,r).replace(S,""),start:s,end:r}}const westDigits=e=>eng().utils.digits(e).replace(/[٫]/g,".").replace(/[,٬]/g,"");function decimalFrac(e){e=westDigits(e);const[t,n=""]=e.split(".");return frac(BigInt(t+n||"0"),10n**BigInt(n.length))}const T={نصف:[1n,2n],نص:[1n,2n],ربع:[1n,4n],ثلث:[1n,3n],تلت:[1n,3n],ثلثين:[2n,3n],ثلثان:[2n,3n],تلتين:[2n,3n],خمس:[1n,5n],سدس:[1n,6n],سبع:[1n,7n],ثمن:[1n,8n],تسع:[1n,9n],عشر:[1n,10n]},B=[["بالمائه"],["بالمئه"],["بالميه"],["في","المائه"],["في","المئه"],["في","الميه"],["بالمايه"]],A=/^(جزء|جزءا|جزءان|جزءين|جزاين|جزان|جزئين|اجزاء)$/,j=/^(جزءان|جزءين|جزاين|جزان|جزئين)$/;let I,q=null,N=new Map,M=null,E=new Set,z=new Map;const F=new Map;function nounWords(e,t,n,s,r){const o=words();let l=o.toWords(t,{currency:e,tashkeel:"n",prefix:"",suffix:"",brackets:"",emphasisOneTwo:"on",...n}),i=t;if(s){const e=l.lastIndexOf("،");if(e<0)return[];l=l.slice(e+1),i=String(+t.split(".")[1])}else/^0\./.test(t)&&(i=String(+t.split(".")[1]));if(!F.has(i)){const e=new Set;for(const t of["r","n","j"])for(const n of["",1])for(const s of r(o.toWords(i,{tashkeel:"n",ierab:t,majorGender:n})))e.add(s);F.set(i,e)}const a=F.get(i),c=r(l).filter(e=>!(a.has(e)||e.startsWith("و")&&a.has(e.slice(1))));return s&&c.length&&c[0].startsWith("و")&&(c[0]=c[0].slice(1)),c}function currencyForms(e){if(E.has(e))return;E.add(e);const t=eng().currencies[e],n=+t[0]||0,plainWords=e=>norm(eng().removeTashkeel(e)).replace(/،/g," ").split(/\s+/).filter(Boolean),s=[new Set,new Set,new Set,new Set],r=new Map;for(const o of["1","2","3","11","100"])for(const l of["r","n","j"]){const i=nounWords(e,o,{ierab:l},!1,plainWords).join(" "),a=nounWords(e,o,{ierab:l,ignoreCountry:"on"},!1,plainWords).join(" ");if(s[0].add(i),s[1].add(a),"1"===o||"2"===o)for(const e of[i,a])r.set("M"+e,+o);if(n>0&&!t[21])for(const t of["1","2","3","11"]){const o="."+t.padStart(n,"0").slice(-n),i=nounWords(e,"0"+o,{ierab:l},!1,plainWords).join(" ");s[2].add(i),"1"!==t&&"2"!==t||r.set("m"+i,+t);const a=nounWords(e,"1"+o,{ierab:l},!0,plainWords).join(" "),c=nounWords(e,"1"+o,{ierab:l,ignoreCountry:"on"},!0,plainWords).join(" ");if(s[2].add(a),s[3].add(c),"1"===t||"2"===t)for(const e of[a,c])r.set("m"+e,+t)}}s.forEach((t,s)=>{for(const o of t)if(o&&!/[0-9]/.test(o)&&!/^(من|جزء)(\s|$)/.test(o))for(const t of[o,o.split(" ").map(e=>"ال"+e).join(" "),...o.includes(" ")?["ال"+o]:[]]){const l=t.replace(/ى/g,"ي");N.has(l)||N.set(l,[]);const i=N.get(l);i.some(t=>t.code===e&&t.minor===s>=2)||i.push({code:e,minor:s>=2,adj:s%2==0&&o.includes(" "),dec:n,def:t!==o,count:r.get((s>=2?"m":"M")+o)||0})}})}function currencyAt(e,t,n){!function currencySync(){const e=eng()[Symbol.for("arqam.tablesChanged")];if(M&&void 0!==e&&e===I)return;const t=eng().currencies,n=Object.keys(t);let s=M&&n.length===z.size;if(s)for(const r of n)if(z.get(r)!==t[r]){s=!1;break}if(I=e,s)return;N=new Map,E=new Set,z=new Map,M=new Map;const plainWords=e=>norm(eng().removeTashkeel(e)).replace(/،/g," ").split(/\s+/).filter(Boolean);for(const r of n){z.set(r,t[r]);const e=t[r],n=+e[0]||0,s=["1","3"].concat(n>0&&!e[21]?["1."+"1".padStart(n,"0"),"1."+"3".padStart(n,"0")]:[]);for(const t of s)for(const e of nounWords(r,t,{ignoreCountry:"on"},t.includes("."),plainWords)){const t=e.replace(/^ال/,"").slice(0,2);M.has(t)||M.set(t,new Set),M.get(t).add(r)}}}();const s=nextWord(e,t,n);if(!s||s.digits)return null;const r=s.w.replace(/^ال/,"").slice(0,2),o=M.get(r);if(!o)return null;for(const u of o)currencyForms(u);const l=N;let i=[],a=n,c=null;for(let u=0;u<6;u++){const s=nextWord(e,t,a);if(!s||s.digits||"،"===s.w||"%"===s.w)break;i.push(s.w),a=s.end;const r=i.join(" ").replace(/ى/g,"ي"),o=r.replace(/ا(?=\s|$)/g,""),u=l.get(r)||l.get(o);u&&(c={end:a,list:u,start:skipSpaces(e,n)})}return c}function phrases(e,t,n){const s=e,r=norm(e),o=findCore(e,t,n);n.alone||(q={text:e,core:o});for(let i,a=/[0-9٠-٩]+(?:[.٫][0-9٠-٩]+)?/g;i=a.exec(s);){if(i.index>0&&/[0-9٠-٩.٫]/.test(s[i.index-1]))continue;const c=skipSpaces(r,i.index+i[0].length),u=(c>i.index+i[0].length||isLetterAt(r,c)?atomsAt(r,s,c,n).filter(e=>"s"===e.kind&&!e.wa):[]).find(e=>2!==e.type&&(3!==e.type||/(^|0)[3-9]$|(^|\d)10$/.test(westDigits(i[0]).replace(/^0+(?=\d)/,""))));if(u&&!o.some(e=>e.start<=c&&c<e.end&&e.start<i.index)){const f=10n**BigInt(u.v),d=fmul(decimalFrac(i[0]),frac(f));for(let g=o.length-1;g>=0;g--)o[g].start>=c&&o[g].start<u.end&&o.splice(g,1);o.push({start:i.index,end:u.end,value:null,f:d,unit:f,digitsScale:!0})}}for(let h,m=/(^|[^\u0621-\u064A])(فاصل[ةه])/g;h=m.exec(s);){const p=h.index+h[1].length,w=o.filter(e=>e.end<=p).pop();w&&/^[\s،,]*$/.test(s.slice(w.end,p))||o.push({start:p,end:p,value:0n,unit:1n,zeroFaslah:!0})}o.sort((e,t)=>e.start-t.start||e.end-t.end);const l=[];for(let k=0;k<o.length;k++){const y=o[k];if(l.length&&y.start<l[l.length-1].end)continue;if(y.zeroFaslah&&!/^فاصل/.test(norm(s.slice(y.start,y.start+6))))continue;let x=y.f||frac(y.value),b=y.start,W=y.end,$={},I=null;if(!("off"===t.currency||y.digitsScale||1n!==y.value&&2n!==y.value||y.wa)){const M=l.length?l[l.length-1].end:0,E=[];for(let R=b-1;R>=M&&E.length<6;R--)!isLetterAt(r,R)||0!==R&&(isLetterAt(r,R-1)||v.test(s[R-1]))||E.push(R);for(const D of E.reverse()){let O=currencyAt(s,r,D),C=!1;if(!O&&"و"===r[D]){let P=D+1;for(;v.test(s[P]);)P++;O=currencyAt(s,r,P),C=!0}if(O&&skipSpaces(s,O.end)===b){I=O,I.waAt=C?D:-1;break}}I&&(b=I.start);const z=l[l.length-1],F=z&&(skipSpaces(s,z.end)===I?.waAt||/^\s*[،,]\s*$/.test(s.slice(z.end,I?.waAt))&&1n===z.f.d&&0n!==z.f.n&&z.f.n%1000n==0n);I&&I.waAt>=0&&F&&void 0===z.currency&&!z.percent&&(l.pop(),x=fadd(z.negative?frac(-z.f.n,z.f.d):z.f,frac(y.value)),b=z.start,z.negative&&($.negative=!0))}const juz=e=>{let o=nextWord(s,r,e),l=0n;if(o&&/^و/.test(o.w)&&A.test(o.w.slice(1))&&"واجزاء"!==o.w&&(l=j.test(o.w.slice(1))?2n:1n,o={...o,w:o.w.slice(1)}),!(o&&A.test(o.w)||o&&"من"===o.w))return null;let i="من"===o.w?o.start:o.end,a=nextWord(s,r,i);if(a&&/^(واحد[اه]?|اثنان|اثنين)$/.test(a.w)&&(i=a.end,a=nextWord(s,r,i)),!a||"من"!==a.w)return null;const c=nextWord(s,r,a.end);if(!c)return null;let u=null,f=null;if(c.digits)u=BigInt(westDigits(c.w).replace(/\..*/,"")),f=c.end;else{const e=atomsAt(r,s,c.start,n).some(e=>e.end>=c.end&&!e.wa),o=c.start+(e?0:(r.slice(c.start).match(/^ال\u0652?[ـ]?/)||[""])[0].length);if(/^الـ?[0-9٠-٩]/.test(s.slice(c.start))){const e=nextWord(s,r,c.start+s.slice(c.start).search(/[0-9٠-٩]/));u=BigInt(westDigits(e.w)),f=e.end}else{const e=findCore(s.slice(o,o+90),{...t,order:"large"},{...n,joined:new Set});e.length&&0===e[0].start&&(u=e[0].value,f=o+e[0].end)}}return!u||u<=0n?null:{den:u,end:f,extra:l}},waNext=(e,t)=>e&&/^[\s،,]*(?:و[\u064B-\u0652]*\s*)?$/.test(s.slice(t,e.start))&&(e.wa||"و"===r[e.start]);{const L=s.slice(0,b).match(/(سالب|سَالِبُ|سَالِبَ|سَالِبِ|سالبُ|سالبَ|سالبِ)\s*$/);L&&(b-=L[0].length,$.negative=!0)}let N=nextWord(s,r,W);const readNum=(e,t)=>{let n=0n,l=k,i=0,a=null,c=null;for(;o[l+1]&&o[l+1].start<e;)l++;for(;;){const u=s.slice(e).match(i||!t?/^[\s،,]*و[\u064B-\u0652]?\s*/:/^\s*/);if(!u)break;const f=e+u[0].length,d=o[l+1],g=d&&(d.start===f||d.start>=e&&d.start<f&&"و"===r[d.start])?d:null,h=/و/.test(u[0])||t&&!i?nextWord(s,r,f):null;if(h&&A.test(h.w)&&!/^اجزاء$/.test(h.w)){n+=j.test(h.w)?2n:1n,e=h.end;const t=o[l+1];!t||t.start!==skipSpaces(s,e)||1n!==t.value&&2n!==t.value||(e=t.end,l++),i++;break}if(g){n+=null!==g.value?g.value:g.f.n/g.f.d,e=g.end,l++,i++;continue}const m=s.slice(f).match(/^[0-9٠-٩][0-9٠-٩,٬]*(?:[.٫][0-9٠-٩]+)?/);if(m){if(/[.٫]/.test(m[0])&&!i){c=decimalFrac(m[0]),e=f+m[0].length;break}n+=BigInt(westDigits(m[0])),e=f+m[0].length,i++;const t=s.slice(e).match(/^\s*\/\s*([0-9٠-٩][0-9٠-٩,٬]*)/);if(t){a=BigInt(westDigits(t[1])),e+=t[0].length;break}continue}break}return{num:n,q:e,k:l,parts:i,slash:a,dec:c}};if(N&&"،"===N.w){const U=nextWord(s,r,N.end);U&&"فاصله"===U.w&&(N=U)}if(N&&"فاصله"===N.w){let Z=N.end,G=0,Q="",H=!1;{let K=Z,V="",X=k,Y=0,_=0;for(;;){const ee=nextWord(s,r,K);if(!ee)break;let te=null,ne=ee.end;if(/^صفرا?$/.test(ee.w))te="0";else{const re=o[X+1];re&&re.start===ee.start&&null!==re.value&&re.value<=9n&&!re.wa&&(te=re.value.toString(),ne=re.end,X++)}if(null===te)break;V+=te,K=ne,Y++;const se=nextWord(s,r,K);if(se&&"،"===se.w){const oe=nextWord(s,r,se.end);if(oe&&(/^صفرا?$/.test(oe.w)||o[X+1]&&o[X+1].start===oe.start&&o[X+1].value<=9n)){K=se.end,_++;continue}}break}Y>=2&&_===Y-1&&(x=fadd(x,frac(BigInt(V),10n**BigInt(V.length))),W=K,k=X,H="sw")}if(!H)for(;;){const le=nextWord(s,r,Z);if(!le||!/^صفرا?$/.test(le.w))break;{G++,Z=le.end;const ie=nextWord(s,r,Z);ie&&"،"===ie.w&&(Z=ie.end)}}const J=o[k+1];if(H);else if(!J||J.start!==skipSpaces(s,Z)||J.wa){const ae=nextWord(s,r,Z);!ae||!ae.digits||/[.٫]/.test(ae.w)||juz(ae.end)||J&&J.digitsScale&&J.start===ae.start||(Q=westDigits(ae.w),Z=ae.end,H=!0);const ce=H?{parts:0}:readNum(Z,!0);if(ce.parts){const ue=juz(ce.q);ue?(x=fadd(x,frac(ce.num,ue.den)),W=ue.end,k=ce.k,H="juz"):ce.slash?(x=fadd(x,frac(ce.num,ce.slash)),W=ce.q,k=ce.k,H="juz"):(Q=ce.num.toString(),Z=ce.q,k=ce.k,H=!0)}else(G||H)&&(H=!0)}else if(J&&J.start===skipSpaces(s,Z)&&!J.wa){let fe=[J],de=k+1;for(;de+1<o.length;){const ge=nextWord(s,r,o[de].end);if(!ge||"،"!==ge.w||o[de+1].start!==skipSpaces(s,ge.end)||o[de+1].wa)break;if(o[de].value>9n||o[de+1].value>9n)break;fe.push(o[++de])}if(fe.length>1&&fe.every(e=>e.value<=9n))Q=fe.map(e=>e.value.toString()).join(""),Z=fe[fe.length-1].end,k=de,H=!0;else{const he=readNum(Z,!0),me=juz(he.q);me?(x=fadd(x,frac(he.num,me.den)),W=me.end,k=he.k,H="juz"):(Q=he.num.toString(),Z=he.q,k=he.k,H=!0)}}if(!0===H&&(x=fadd(x,frac(BigInt(Q||"0"),10n**BigInt(G+Q.length))),W=Z),!H&&y.zeroFaslah)continue;H&&(N=nextWord(s,r,W))}{let pe=W,we=!1;const ke=nextWord(s,r,pe);ke&&"،"===ke.w&&(we=!0,pe=ke.end),o[k+1];const ve=W===y.end?juz(W):null;if(ve&&!y.digitsScale&&(x=frac(y.value+ve.extra,ve.den),W=ve.end),!ve||y.digitsScale||1n!==y.value&&2n!==y.value){if(!ve||y.digitsScale){const{num:Se,q:ye,k:xe,parts:be,slash:We,dec:$e}=readNum(pe,!1);let Te=!1;if($e)x=fadd(x,$e),W=ye,Te=!0;else if(We)x=fadd(x,frac(Se,We)),W=ye,k=xe,Te=!0;else if(be){const Be=juz(ye);Be&&(x=fadd(x,frac(Se,Be.den)),W=Be.end,k=xe,I&&(W=ofCurrency(W)),Te=!0)}if(!Te){const Ae=s.slice(pe).match(/^\s*و[\u064B-\u0652]?\s*/),je=nextWord(s,r,Ae?pe+Ae[0].length:pe),Ie=!Ae&&je&&"الا"===je.w,qe=Ie?nextWord(s,r,je.end):je,Ne=qe&&nextWord(s,r,qe.end),Me=Ne&&(/^و./.test(Ne.w)&&(()=>{let e=Ne.start+1;for(;v.test(s[e]);)e++;return atomsAt(r,s,e,n).length>0})()||/^(عشر|عشره)$/.test(Ne.w)||"off"!==t.currency&&(()=>{const e=currencyAt(s,r,Ne.start);return e&&e.start===Ne.start})());if(qe&&(Ae||Ie)&&T[qe.w.replace(/^ال/,"")]&&!qe.digits&&!Me){const[Ee,ze]=T[qe.w.replace(/^ال/,"")],Fe=fmul(frac(Ee,ze),frac(y.unit));x=fadd(x,Ie?frac(-Fe.n,Fe.d):Fe),W=qe.end}}}}else{let Re=b;for(;Re>0&&/\s/.test(s[Re-1]);)Re--;let De=Re;for(;De>0&&/[\u0621-\u064A\u064B-\u0652]/.test(s[De-1]);)De--;const Oe=norm(s.slice(De,Re)).replace(S,"").replace(/[ئأ]/g,"ء");De<Re&&A.test(Oe)&&!(l.length&&l[l.length-1].end>De)&&(b=De)}}function ofCurrency(e){const t=nextWord(s,r,e);if(!t||"من"!==t.w)return e;const n=currencyAt(s,r,t.end);return n&&n.start===skipSpaces(s,t.end)?n.end:e}if(!I&&"off"!==t.currency){const Ce=nextWord(s,r,W);if(Ce&&"من"===Ce.w){const Pe=currencyAt(s,r,Ce.end);Pe&&Pe.start===skipSpaces(s,Ce.end)&&Pe.list.every(e=>e.def)&&(I={...Pe,after:!0})}}if("off"!==t.currency){let Le=I||currencyAt(s,r,W),Ue=null,Ze=null,Ge=null,Qe=I||(Le&&Le.start===skipSpaces(s,W)?Le:null);if(!Qe){const He=aloneAt(s,r,W,!0)||aloneAt(s,r,W,!0,!0);He&&(x=fadd(x,frac(BigInt(He.count))),Qe=Le=He.m,He.end>He.m.end&&(W=Math.max(W,He.end)))}if(Qe){const Je=Qe.list.filter(e=>!e.minor),Ke=Qe.list.filter(e=>e.minor),Ve=new Set(Je.map(e=>e.code)),Xe=Je.length?Je:Ke,Ye=[...new Set(Xe.map(e=>e.code))];1===Ye.length&&(Ue=Ye[0]);const _e=[...new Set(Xe.map(e=>e.dec))];if(Ge=1===_e.length?_e[0]:null,Ze=s.slice(Qe.start,Qe.end),I&&!I.after||(W=Qe.end),Je.length||null===Ge){for(;o[k+1]&&o[k+1].start<W;)k++;const et=o[k+1];if(waNext(et,W)){const tt=currencyAt(s,r,et.end);if(tt&&tt.start===skipSpaces(s,et.end)){const nt=tt.list.filter(e=>e.minor&&(Ue?e.code===Ue:Ve.has(e.code))),st=[...new Set(nt.map(e=>e.dec))];if(nt.length&&1===st.length&&(x=fadd(x,frac(et.value,10n**BigInt(st[0]))),W=tt.end,k++,Ge=st[0],!Ue)){const rt=[...new Set(nt.map(e=>e.code))];1===rt.length&&(Ue=rt[0])}}else{const ot=aloneAt(s,r,et.end,!0,!0),lt=ot?ot.m.list.filter(e=>e.minor&&e.count&&(Ue?e.code===Ue:Ve.has(e.code))):[];if(lt.length&&1===[...new Set(lt.map(e=>e.dec))].length){for(x=fadd(x,frac(et.value+BigInt(ot.count),10n**BigInt(lt[0].dec))),W=ot.end,k++,Ge=lt[0].dec;o[k+1]&&o[k+1].start<W;)k++;if(!Ue){const it=[...new Set(lt.map(e=>e.code))];1===it.length&&(Ue=it[0])}}else{const ct=juz(et.end);ct&&(x=fadd(x,frac(et.value+ct.extra,ct.den)),W=ct.end,k++,W=ofCurrency(W))}}}if(W===Qe.end){const ut=readNum(W,!1),ft=ut.parts?juz(ut.q):null;ft&&(x=fadd(x,frac(ut.num+ft.extra,ft.den)),W=ofCurrency(ft.end),k=ut.k)}if(W===Qe.end||I){let dt=W;const gt=nextWord(s,r,dt);gt&&"،"===gt.w&&(dt=gt.end);const ht=skipSpaces(s,dt);if("و"===r[ht]){let mt=ht+1;for(;v.test(s[mt]);)mt++;mt=skipSpaces(s,mt);const pt=nextWord(s,r,mt);if(pt&&pt.digits&&pt.start===mt&&/^[0-9٠-٩]+$/.test(pt.w)){const wt=currencyAt(s,r,pt.end);if(wt&&wt.start===skipSpaces(s,pt.end)){const kt=wt.list.filter(e=>e.minor&&(Ue?e.code===Ue:Ve.has(e.code))),vt=[...new Set(kt.map(e=>e.dec))];if(kt.length&&1===vt.length){for(x=fadd(x,frac(BigInt(westDigits(pt.w)),10n**BigInt(vt[0]))),W=wt.end,Ge=vt[0];o[k+1]&&o[k+1].start<W;)k++;if(!Ue){const St=[...new Set(kt.map(e=>e.code))];1===St.length&&(Ue=St[0])}}}}}}if(W===Qe.end||I){let yt=W;const xt=nextWord(s,r,yt);xt&&"،"===xt.w&&(yt=xt.end);const bt=skipSpaces(s,yt);if("و"===r[bt]){let Wt=bt+1;for(;v.test(s[Wt]);)Wt++;const $t=currencyAt(s,r,Wt),Tt=o[k+1];if(!$t||!Tt||Tt.wa||1n!==Tt.value&&2n!==Tt.value||Tt.start!==skipSpaces(s,$t.end)){if($t&&$t.start===skipSpaces(s,Wt)&&(!Tt||Tt.start!==skipSpaces(s,$t.end))){const Bt=$t.list.filter(e=>e.minor&&e.count&&(Ue?e.code===Ue:Ve.has(e.code))),At=[...new Set(Bt.map(e=>e.dec))],jt=[...new Set(Bt.map(e=>e.count))];if(Bt.length&&1===At.length&&1===jt.length&&(x=fadd(x,frac(BigInt(jt[0]),10n**BigInt(At[0]))),W=$t.end,Ge=At[0],!Ue)){const It=[...new Set(Bt.map(e=>e.code))];1===It.length&&(Ue=It[0])}}}else{const qt=$t.list.filter(e=>e.minor&&(Ue?e.code===Ue:Ve.has(e.code))),Nt=[...new Set(qt.map(e=>e.dec))];if(qt.length&&1===Nt.length&&(x=fadd(x,frac(Tt.value,10n**BigInt(Nt[0]))),W=Tt.end,k++,Ge=Nt[0],!Ue)){const Mt=[...new Set(qt.map(e=>e.code))];1===Mt.length&&(Ue=Mt[0])}}}}}else x=fmul(x,frac(1n,10n**BigInt(Ge)));$.currency=Ue,$.noun=Ze.replace(S,""),null!==Ge&&($.places=Ge)}}{const Et=nextWord(s,r,W);if(Et&&"%"===Et.w)W=Et.end,$.percent=!0;else for(const zt of B){let Ft=W,Rt=!0,Dt=W;for(const Ot of zt){const Ct=nextWord(s,r,Ft);if(!Ct||Ct.w!==Ot){Rt=!1;break}Ft=Dt=Ct.end}if(Rt){W=Dt,$.percent=!0;break}}}$.negative&&(x=frac(-x.n,x.d)),W<=b||l.push({start:b,end:W,text:s.slice(b,W),value:fracText(x),...$,f:x})}if(!("off"===t.currency||n&&n.alone)){const inside=e=>l.some(t=>e>=t.start&&e<t.end);for(let Pt=0;Pt<s.length;){const Lt=nextWord(s,r,Pt);if(!Lt)break;const Ut=inside(Lt.start)?null:aloneAt(s,r,Lt.start,!1)||aloneAt(s,r,Lt.start,!1,!0);if(!Ut){Pt=Lt.end;continue}const Zt=/^\s+و/.test(s.slice(Ut.m.end)),Gt=" "+(1===Ut.count?"واحد":"اثنان")+(Zt?"،":""),Qt=phrases(s.slice(0,Ut.m.end)+Gt+s.slice(Ut.m.end),t,{...n||{},alone:!0}).find(e=>e.start<=Ut.m.start&&e.end>=Ut.m.end+Gt.length);if(!Qt){Pt=Ut.m.end;continue}const Ht=Qt.end-Gt.length,Jt=Math.min(Qt.start,Ut.m.start);for(let Kt=l.length-1;Kt>=0;Kt--)l[Kt].start>=Jt&&l[Kt].start<Ht&&l.splice(Kt,1);l.push({...Qt,start:Jt,end:Ht,text:s.slice(Jt,Ht)}),Pt=Ht}l.sort((e,t)=>e.start-t.start)}for(let Vt=l.length-2;Vt>=0;Vt--){const Xt=l[Vt],Yt=l[Vt+1];Xt.currency&&Xt.noun&&!Yt.currency&&/^\s+$/.test(s.slice(Xt.end,Yt.start))&&/^(1|2)$/.test(String(Yt.value))&&/^(واحد[اةه]?|اثن(ان|ين|تان|تين))$/.test(norm(eng().removeTashkeel(Yt.text)).trim())&&l.splice(Vt,2,{...Xt,end:Yt.end,text:s.slice(Xt.start,Yt.end)})}return l}let R=null;function ordWords(){if(R)return R;R={};const add=(e,t)=>{const n=norm(eng().removeTashkeel(e)).replace(/^ال/,"");R[n]=t,R[n.replace(/ى$/,"ي")]=t};for(let e=1;e<=10;e++)for(const t of["m","f"])add(words().toWords(String(e),{ordinal:t,tashkeel:"n"}),e);for(const e of["m","f"])add(words().toWords("11",{ordinal:e,tashkeel:"n"}).split(" ")[0],1);return R}const D=["order","scale","zero","ambiguous","arabicNumbers","currency","ordinals","dates","times"];function options(e){if(null===e||"object"!=typeof e)throw new TypeError("arqamWordsToNumbers: the options must be an object");const t={order:"auto",scale:"short",zero:"off",ambiguous:"off",currency:"words",ordinals:"off",dates:"on",times:"on",...e};for(const n in e)if(!D.includes(n))throw new TypeError('arqamWordsToNumbers: unknown option "'+n+'"; use: '+D.join(", "));if(!["auto","large","small"].includes(t.order))throw new TypeError('arqamWordsToNumbers: order is "auto", "large" or "small"');if(!["short","long"].includes(t.scale))throw new TypeError('arqamWordsToNumbers: scale is "short" or "long"');if(!["words","code","off"].includes(t.currency))throw new TypeError('arqamWordsToNumbers: currency is "words", "code" or "off"');for(const n of["zero","ambiguous","ordinals","arabicNumbers","dates","times"])if(n in e&&!["on","off"].includes(t[n]))throw new TypeError("arqamWordsToNumbers: "+n+' is "on" or "off"');return k[t.scale]||(k[t.scale]=function scaleTables(e){const t=[],add=(e,n,s)=>t.push([e,n,s]),name=(e,t)=>norm(words().toWords("1"+"000".repeat(e),{scale:t,tashkeel:"n"}));for(const[i,a]of[[s,12],[r,9],[o,6],[l.concat(["تلاف",3,"تالاف",3,"لاف",3]),3]])for(let e=0;e<i.length;e+=2)add(i[e],a,i[e+1]);const n=[];for(let s=5;s<=11;s++){const e=name(s,"short");n.push([e,3*s]);for(const t of p[e]||[])n.push([norm(t),3*s])}for(const[s,r]of n)for(const[e,t]of w)add(s+e,r,t);if(e){for(const e of t)e[1]>=9&&!/^م/.test(norm(e[0]))&&(e[1]=2*e[1]-6);for(let e=3;e<=11;e++){const t=name(e,"long");if(/يار$/.test(t)&&!/^م/.test(t))for(const[n,s]of w)add(t+n,3*e,s)}}return t.sort((e,t)=>t[0].length-e[0].length)}("long"===t.scale)),t}function find(e,t={}){if("string"!=typeof e)throw new TypeError("arqamWordsToNumbers: the text must be a string");const n=options(t),s={scales:k[n.scale],zero:"on"===n.zero,ambiguous:"on"===n.ambiguous,joined:new Set};let r=phrases(e,n,s).map(({f:e,...t})=>t);{const t=function ordinals(e,t,n,s){const r=e,o=norm(e),l=[],definiteAt=e=>{let s="",l=[],i=e;const a=Math.min(r.length,e+200);for(;i<a;){if(i===e||/\s/.test(r[i-1])){const t=o.slice(i).match(/^(و[ً-ْ]?)?ال/);let a=i;for(;a<r.length&&(isLetterAt(o,a)||v.test(r[a]));)a++;const c=atomsAt(o,r,i+(t&&t[1]?t[1].length:0),n).some(e=>e.end===a&&!e.wa);if(t&&!c){if(t[1]&&i!==e)for(let e=0;e<t[1].length;e++)s+=r[i+e],l.push(i+e);i+=t[0].length;continue}}s+=r[i],l.push(i),i++}const c=findCore(s,{...t,order:"large"},{...n,joined:new Set});return c.length&&c[0].start===skipSpaces(s,0)&&!c[0].wa?{value:c[0].value,end:l[c[0].end-1]+1}:null};for(let a,c=/(^|[^ء-ي])(ال)/g;a=c.exec(o);){const e=a.index+a[1].length;if(s.some(t=>e>=t.start&&e<t.end)||l.some(t=>e>=t.start&&e<t.end))continue;const t=nextWord(r,o,e);if(!t)continue;const i=t.w.replace(/^ال/,"");if(void 0===ordWords()[i]&&!atomsAt(o,r,e+2,n).length)continue;if(atomsAt(o,r,e,n).some(e=>e.end===t.end&&!e.wa))continue;let c=null,u=t.end,f=!1,d=e;if(void 0!==ordWords()[i]){c=BigInt(ordWords()[i]),f=i.startsWith("حادي");const e=nextWord(r,o,u);if(e&&/^(عشر|عشره)$/.test(e.w)&&c<10n)c+=10n,u=e.end,f=!1;else{const e=nextWord(r,o,u);if(e&&/^وال/.test(e.w)&&c<10n){const t=definiteAt(e.start);t&&t.value>=20n&&t.value<=90n&&t.value%10n==0n&&(c+=t.value,u=t.end,f=!1)}}}else{const s=definiteAt(e);s&&s.value%10n==0n&&s.value>=20n&&(c=s.value,u=s.end);let a=e;for(;a>0&&/\s/.test(r[a-1]);)a--;let f=a;for(;f>0&&(isLetterAt(o,f-1)||v.test(r[f-1]));)f--;if(f<a&&/^(الف|الاف|مليون|ملايين|مليار|مليارات)/.test(i)&&!/^ال/.test(o.slice(f))&&atomsAt(o,r,f,n).length&&!l.some(e=>f>=e.start&&f<e.end)){const e=definiteAt(f);e&&e.end>=t.end&&e.value>=1000n&&(c=e.value,u=e.end,d=f)}}if(null===c)continue;const g=nextWord(r,o,u);if(g&&"بعد"===g.w){const e=definiteAt(skipSpaces(r,g.end));e&&(c+=e.value,u=e.end,f=!1)}f||l.push({start:d,end:u,text:r.slice(d,u),value:c.toString(),ordinal:!0})}const i={ثان:2,حاد:1};for(let a,c=/(^|[^ء-ي])([ء-ي])/g;a=c.exec(o);){const e=a.index+a[1].length;if(/^ال/.test(o.slice(e)))continue;if(s.some(t=>e>t.start&&e<t.end)||l.some(t=>e>=t.start&&e<t.end))continue;const t=nextWord(r,o,e);if(!t||t.start!==e)continue;let n=void 0===ordWords()[t.w]||/^ال/.test(t.w)?i[t.w]:ordWords()[t.w],c=!1;if(void 0===n){const s=nextWord(r,o,t.end);if(!s||"بعد"!==s.w)continue;const l=definiteAt(e);if(!l||l.end!==t.end||l.value<20n||l.value>90n||l.value%10n)continue;n=Number(l.value),c=!0}let u=BigInt(n),f=t.end,d=!1;const g=c?null:nextWord(r,o,f);if(g&&/^(عشر|عشره)$/.test(g.w)&&u<10n&&!/^حاد$/.test(t.w))u+=10n,f=g.end,d=!0;else if(g&&/^و./.test(g.w)&&u<10n){let e=g.start+1;for(;e<r.length&&v.test(r[e]);)e++;const t=definiteAt(e);t&&t.value>=20n&&t.value<=90n&&t.value%10n==0n&&(u+=t.value,f=t.end,d=!0)}const h=nextWord(r,o,f);if(h&&"بعد"===h.w){const e=definiteAt(skipSpaces(r,h.end));e&&(u+=e.value,f=e.end,d=!0)}!d||c&&u<100n||l.push({start:e,end:f,text:r.slice(e,f),value:u.toString(),ordinal:!0})}return l.sort((e,t)=>e.start-t.start)}(e,n,{...s,joined:new Set},r);r=r.filter(e=>!t.some(t=>e.start<t.end&&t.start<e.end)).concat("on"===n.ordinals?t:[])}if("on"===n.dates||"on"===n.times){const t=function datesTimes(e,t){const{n,at:s}=dtNorm(e),r=[],o=[],free=(e,t)=>!o.some(([n,s])=>e<s&&n<t),item=(t,n,l)=>{const i=s[t],a=s[n];o.push([t,n]),r.push({start:i,end:a,text:e.slice(i,a),...l})},orig=(t,n)=>e.slice(s[t],s[n]),l=eng(),i=l.utils;if("on"===t.dates&&/شهر|[0-9]/.test(n)){const tryMonth=e=>{const t=n.slice(e).match(/^\s*((?:[^\s،,.؛0-9]+)(?:\s*\/\s*[^\s،,.؛0-9]+)?(?:\s+[^\s،,.؛0-9]+){0,2})/);if(!t)return null;const s=t[1].split(/\s+/);for(let n=s.length;n>=1;n--){const o=s.slice(0,n).join(" "),l=e+t[0].length-t[1].length,a=l+o.length,c=orig(l,a);let u=!1;try{i.parseDate("1 "+c+" 2000"),u=!0}catch(r){}if(!u&&!/\//.test(c))try{i.parseDate("1 "+c+" 1440",{input:"h"}),u=!0}catch(r){}if(u)return{a:l,b:a,name:c}}return null},tryYear=t=>{let r=n.slice(t).match(/^\s+(?:(لعام|لسنه|سنه|عام)\s+)?/);if(!r)return null;let o=t+r[0].length;const l=n.slice(o).match(/^([0-9]{1,4})(?![0-9])/);let i,a;if(l)i=+l[1],a=o+l[0].length;else{const t=find(e.slice(s[o],s[Math.min(n.length,o+140)]),{dates:"off",times:"off",currency:"off"});if(!t.length||0!==t[0].start||!/^[0-9]+$/.test(t[0].value))return null;i=+t[0].value,a=dtNorm(e.slice(0,s[o]+t[0].end)).n.length}if(i<1||i>9999)return null;const c=n.slice(a).match(H),u=c?/هجر|^ه/.test(c[1])?"h":"g":"";return{y:i,end:c?a+c[0].length:a,cal:u}},add=(e,t,n,s,r)=>{if(!free(e,r.end))return;const o="h"===r.cal?"هـ":"g"===r.cal?"م":"";let l,a=!1;const c=String(r.y).padStart(4,"0");try{l=i.parseDate(`${n} ${s.name} ${c}${o}`)}catch(d){return}try{i.parseDate(`${n} ${s.name} ${c}${o}`,{input:"g"})}catch(d){a=!0}const pad=e=>String(e).padStart(2,"0"),u=`${String(l.year).padStart(4,"0")}-${pad(l.month)}-${pad(l.day)}`,f=a?`${l.hijri.day}/${l.hijri.month}/${l.hijri.year}هـ`:`${l.day}/${l.month}/${l.year}م`;item(e,r.end,{value:f,kind:"date",calendar:a?"h":"g",iso:u})};for(const e of matchesAfter(/(?:(غره)\s+|من\s+)شهر\s+/g,n)){let t,s;if(e[1])t=e.index,s=1;else{const r=n.slice(0,e.index).replace(/\s+$/,""),o=r.split(/(\s+)/);for(let e=Math.min(7,o.length);e>=1;e-=2){const n=o.slice(o.length-e).join(""),l=dtDays().get(n.replace(/\s+/g," "));if(l){s=l,t=r.length-n.length;break}}if(!s)continue}const r=tryMonth(e.index+e[0].length);if(!r)continue;const o=tryYear(r.b);o&&add(t,null,s,r,o)}for(const e of matchesAfter(/([0-9]{1,2})\s+(?=[^\s0-9])/g,n)){if(!free(e.index,e.index+e[0].length))continue;const t=tryMonth(e.index+e[1].length);if(!t)continue;const s=tryYear(t.b);s&&/^\s+(?:(?:لعام|لسنه|سنه|عام)\s+)?[0-9]/.test(n.slice(t.b))&&add(e.index,null,+e[1],t,s)}}if("on"===t.times&&/ساع|دقيق|دقائق|منتصف|ثاني|ثوان|صباحا|ظهرا|عصرا|مساء|ليلا|فجرا/.test(n)){const pad=e=>String(e).padStart(2,"0"),t=[...n.matchAll(/[^\s،,.؛()«»]+/g)];for(let r=0;r<t.length;r++){const o=t[r].index;if(!free(o,o+1))continue;let i=null;for(let e=Math.min(12,t.length-r);e>=1&&!i;e--){const s=t[r+e-1].index+t[r+e-1][0].length,l=n.slice(o,s).replace(/\s+/g," ");if(/[،,.؛]/.test(l))continue;const a=dtTime(l),c=a?null:dtDur(l);a?i={kind:"time",b:s,key:l,vals:a,k:e}:c&&(i={kind:"duration",b:s,key:l,value:c,k:e})}if(!i)continue;let a=i.b;if("duration"===i.kind){item(o,a,{value:i.value,kind:"duration"}),r+=i.k-1;continue}let c="";const u=n.slice(a).match(/^\s+و\s*((?:[^\s،,.؛]+\s+){0,6}?)(ثانيه|ثوان|ثانيتان|ثانيتين)(?![\u0621-\u064A])/);if(u){let t=null;if(u[1].trim()){const n=find(e.slice(s[a+u[0].indexOf(u[1])],s[a+u[0].indexOf(u[1])+u[1].trimEnd().length]),{dates:"off",times:"off"});1===n.length&&/^[0-9]+$/.test(n[0].value)&&(t=+n[0].value)}else t=/ثانيتان|ثانيتين/.test(u[2])?2:1;null!==t&&t<60&&(c=":"+pad(t),a+=u[0].length)}const f=n.slice(a).match(Q);if(!/^الساعه /.test(i.key)&&"منتصف الليل"!==i.key&&!f&&!/(دقيقه|دقائق|دقيقتان|دقيقتين|النصف|الربع|الثلث)$/.test(i.key))continue;let d,g=i.vals,h=!1;if(f){const e=dtKey(f[1]),t=g.filter(([t,n])=>dtKey(l.toTime(t,{...n,tashkeel:"n"})).endsWith(e));t.length?g=t:"بعد منتصف الليل"===e&&(g=g.map(([e,t])=>[pad(+e.split(":")[0]%12)+":"+e.split(":")[1],t])),a+=f[0].length}const m=[...new Set(g.map(e=>e[0]))];if(1===m.length)d=m[0]+c;else{const[e,t]=m[0].split(":");d=`${+e%12||12}:${t}`+c,h=!0}for(item(o,a,{value:d,kind:"time",...h?{hour12:!0}:{}});r+1<t.length&&t[r+1].index<a;)r++}}return r}(e,n);t.length&&(r=r.filter(e=>!t.some(t=>e.start<t.end&&t.start<e.end)).concat(t))}return r=function approxFind(e,t){for(const s of t){const t=e.slice(0,s.start);for(const[e,n]of K){const r=t.match(n);if(r){s.approx=e,s.approxText=r[1],s.approxStart=t.length-r[0].length+r[0].indexOf(r[1]);break}}}const bare=e=>e.replace(/[\u064B-\u0652\u0670\u0640]/g,"").replace(/[أإآ]/g,"ا"),scaleOf=e=>{if(!e)return 1n;const t=bare(e),n=X.find(([e])=>bare(e)===t);return n?n[1]:1n},tensOf=e=>V[bare(e).replace(/^و/,"").replace(/(ون|ين)$/,"")]||0,add=(n,s,r,o,l)=>{const i={start:n,end:s,text:e.slice(n,s),value:null,approx:r,min:String(o),max:String(l)};t=t.filter(e=>!(e.start<s&&n<e.end)).concat(i)},n=e.replace(/[\u064B-\u0652\u0670\u0640]/g,"");if(/بضع/.test(n))for(const s of matchesAfter(ee,e)){const e=scaleOf(s[5]);let t=3n,n=9n;if(s[2])t=13n,n=19n;else if(s[3]){const e=BigInt(tensOf(s[3]));t=e+3n,n=e+9n}add(s.index,s.index+s[0].length,"few",t*e,n*e)}if(/ن[يى]ف/.test(n))for(const s of e.matchAll(te)){const n=BigInt(tensOf(s[2])),r=scaleOf(s[4]);let o=s.index,l=0n;if(s[1]){const n=t.find(t=>null!==t.value&&t.end<=s.index&&!e.slice(t.end,s.index).trim());n&&/^\d+$/.test(n.value)&&(l=BigInt(n.value),o=n.start)}add(o,s.index+s[0].length,"plus",l+(n+1n)*r,l+(n+9n)*r)}if(/ن[يى]ف/.test(n))for(const s of e.matchAll(ne)){const n=t.find(t=>null!==t.value&&t.end<=s.index&&!e.slice(t.end,s.index).trim()&&/^\d+$/.test(t.value));if(n){const r=BigInt(n.value),o={...n,start:n.start,end:s.index+s[0].length,text:e.slice(n.start,s.index+s[0].length),value:null,approx:"plus",min:String(r+1n),max:String(r+9n)};t=t.filter(e=>e!==n).concat(o)}}return t}(e,r),r.sort((e,t)=>e.start-t.start)}const O=/[\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06ED\u0640]/;function dtNorm(e){let t="",n=[];for(let s=0;s<e.length;s++){const r=e[s];if(O.test(r))continue;let o="أإآٱ".includes(r)?"ا":"ة"===r?"ه":"ى"===r?"ي":r;const l="٠١٢٣٤٥٦٧٨٩".indexOf(o),i="۰۱۲۳۴۵۶۷۸۹".indexOf(o);l>=0?o=String(l):i>=0&&(o=String(i)),t+=o,n.push(s)}return n.push(e.length),{n:t,at:n}}const dtKey=e=>dtNorm(eng().removeTashkeel(e)).n.replace(/\s+/g," ").trim();let C=null;function dtDays(){if(C)return C;C=new Map;for(let e=1;e<=31;e++)for(const t of["r","n","j"])C.set(dtKey(eng().toWords(String(e),{ordinal:"m",ierab:t,tashkeel:"n"})),e);return C.set("غره",1),C}const P={timeStyle:"common",timeParts:"on"};function timePhrases(e,t,n,s,r,o){const l=new Map,i=new Map,add=(e,t,n,s)=>{const r=e.get(t)||[];r.some(e=>s(e,n))||r.push(n),e.set(t,r)},pad=e=>String(e).padStart(2,"0");for(const a of t)for(const t of n){const bare=n=>e(eng().toTime(n,{..."string"==typeof a?{timeStyle:a}:a,ierab:t,timePeriod:"off",timeWord:"off",...s}));for(let e=0;e<24;e++)add(l,bare(`${pad(e)}:00`),e,(e,t)=>e===t);const n=[...l.keys()].sort((e,t)=>t.length-e.length);for(const e of[3,15])for(let t=0;t<60;t++){const s=bare(`${pad(e)}:${pad(t)}`),a=n.find(e=>s===e||s.startsWith(e+" "));if(a)for(const n of l.get(a)){const l=n%12==e%12?0:n%12==(e+1)%12?-1:null;null!==l&&add(i,s.slice(a.length).trim(),r(t,l),o)}}}return{hours:l,mins:i}}let L=null;const U=new Map,Z=new Map;function dtParts(){if(L)return L;const e=eng(),pad=e=>String(e).padStart(2,"0"),add=(e,t,n)=>{const s=e.get(t)||[];s.includes(n)||s.push(n),e.set(t,s)},t=new Map,n=new Map,s=new Map,longest=(e,t)=>[...e.keys()].filter(e=>t===e||t.startsWith(e+" ")).sort((e,t)=>t.length-e.length)[0],{hours:r,mins:o}=timePhrases(dtKey,["common","exact","h24",P],["r","n","j"],{tashkeel:"n"},(e,t)=>100*(t+1)+e,(e,t)=>e===t);for(const l of["r","n","j"]){const dur=t=>dtKey(e.toTime(t,{timeStyle:"duration",ierab:l,tashkeel:"n"}));for(let e=1;e<48;e++)add(t,dur(`${e}:00`),e);for(let e=1;e<60;e++)add(s,dur(`0:${pad(e)}`),e);for(const e of[1,2,3,10,11,15,25])for(let s=1;s<60;s++){const r=dur(`${e}:${pad(s)}`),o=longest(t,r);o&&add(n,r.slice(o.length).trim(),s)}}return L={hours:r,mins:o,dh:t,dm:n,dOnly:s,longest}}const G=["common","exact","h24"].map(e=>({timeStyle:e})).concat(P);function dtTime(e){if(U.has(e))return U.get(e);let t=null;const n=e.replace(/^الساعه /,"");if(/^(ال|منتصف)/.test(n)){const s=eng(),r=dtParts(),pad=e=>String(e).padStart(2,"0"),o=new Set(/^منتصف/.test(n)?[0]:[]),l=r.longest(r.hours,n);if(l)for(const e of r.hours.get(l))for(const t of r.mins.get(n.slice(l.length).trim())||[]){const n=Math.floor(t/100)-1,s=t%100;for(const t of[e+n,e+n+12])o.add((t%24+24)%24*60+s)}const i=[...o].sort((e,t)=>e-t).map(e=>`${pad(Math.floor(e/60))}:${pad(e%60)}`),a=[];if(!i.length)return U.set(e,null),null;for(const t of G)for(const n of["r","n","j"])for(const r of i){const o=dtKey(s.toTime(r,{...t,ierab:n,timePeriod:"off",tashkeel:"n"}));o!==e&&o.replace(/^الساعه /,"")!==e||a.some(e=>e[0]===r&&e[1]===t)||a.push([r,t])}a.length&&(t=a)}return U.size>=2e4&&U.clear(),U.set(e,t),t}function dtDur(e){if(Z.has(e))return Z.get(e);let t=null;if("ساعه"!==e&&"دقيقه"!==e&&/ساع|دقيق|دقائق/.test(e)){const n=eng(),s=dtParts(),pad=e=>String(e).padStart(2,"0"),r=[];for(const t of s.dOnly.get(e)||[])r.push([0,t]);const o=s.longest(s.dh,e);if(o){const t=e.slice(o.length).trim();for(const e of s.dh.get(o)){t||r.push([e,0]);for(const n of s.dm.get(t)||[])r.push([e,n])}}r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);e:for(const l of["r","n","j"])for(const[s,o]of r)if(dtKey(n.toTime(`${s}:${pad(o)}`,{timeStyle:"duration",ierab:l,tashkeel:"n"}))===e){t=`${s}:${pad(o)}`;break e}}return Z.size>=2e4&&Z.clear(),Z.set(e,t),t}const Q=/^\s+(بعد منتصف الليل|ليلا|فجرا|صباحا|ظهرا|عصرا|مساء|مساءا)(?![\u0621-\u064A])/,H=/^\s*(للميلاد|ميلاديه|ميلادي|للهجره|هجريه|هجري|هـ|ه|م)(?![\u0621-\u064A])/,J="[\\u064B-\\u0652\\u0670\\u0640]*";function apRe(e){return e.split("").map(e=>(" "===e?"\\s+":"اأإآ".includes(e)?"[اأإآ]":"ة"===e?"[ةه]":"ى"===e||"ي"===e?"[ىي]":e)+(" "===e?"":J)).join("")}const K=[["about",["قرابة","نحو","زهاء","حوالي","ما يقارب"]],["atLeast",["ما لا يقل عن"]],["atMost",["ما لا يزيد على","ما لا يزيد عن"]],["over",["ما يزيد على","ما يزيد عن","أكثر من","ما يربو على"]],["under",["أقل من","ما دون"]]].map(([e,t])=>[e,new RegExp("(?:^|[\\s،(«])("+t.map(apRe).join("|")+")\\s+$")]),V={عشر:20,ثلاث:30,اربع:40,خمس:50,ست:60,سبع:70,ثمان:80,تسع:90},X=[["مئات",100n],["آلاف",1000n],["ألفا",1000n],["ألف",1000n],["ملايين",10n**6n],["مليونا",10n**6n],["مليون",10n**6n],["مليارات",10n**9n],["مليارا",10n**9n],["مليار",10n**9n]],Y="و"+J+"("+Object.keys(V).map(apRe).join("|")+")(?:"+apRe("ون")+"|"+apRe("ين")+")",_="(?:\\s+("+X.map(([e])=>apRe(e)).join("|")+"))?",ee=new RegExp("("+apRe("بضع")+"(?:[ةه]"+J+")?)(?:(\\s+"+apRe("عشر")+"(?:[ةه]"+J+")?)|\\s+("+Y+"))?"+_,"g"),te=new RegExp("("+apRe("و")+")?"+apRe("نيف")+"(?:ا"+J+")?\\s+("+Y+")"+_,"g"),ne=new RegExp(apRe("و")+apRe("نيف")+"(?:ا"+J+")?(?![\\u0600-\\u06FF]*\\s+و"+J+"(?:"+Object.keys(V).map(apRe).join("|")+"))","g");function digits(e,t){return t&&"on"===t.arabicNumbers?eng().utils.digits(e,"eastern").replace(/\./g,"٫"):e}function arqamWordsToNumbers(e,t={}){const n=options(t);let s="",r=0;for(const o of find(e,t)){if(null===o.value)continue;if(void 0!==o.currency&&"code"!==n.currency){const t=q&&q.text===e?q.core.filter(e=>e.start>=o.start&&e.end<=o.end).map(e=>({...e,start:e.start-o.start,end:e.end-o.start})):findCore(e.slice(o.start,o.end),n,{scales:k[n.scale],zero:"on"===n.zero,ambiguous:"on"===n.ambiguous,joined:new Set});let l=e.slice(o.start,o.end),i="",a=0;for(const e of t)i+=l.slice(a,e.start)+digits(e.value.toString(),n),a=e.end;s+=e.slice(r,o.start)+i+l.slice(a),r=o.end;continue}let t=o.value;o.currency&&"code"===n.currency&&(t=fracText(frac(...(()=>{const[e,t=""]=o.value.replace("-","").split(".");return[BigInt((o.value.startsWith("-")?"-":"")+e+t),10n**BigInt(t.length)]})()),o.places)),s+=e.slice(r,o.start)+digits(t,n)+(o.percent?"%":"")+(o.currency&&"code"===n.currency?" "+o.currency:""),r=o.end}return s+e.slice(r)}arqamWordsToNumbers.find=find,arqamWordsToNumbers.value=(e,t={})=>{if("string"!=typeof e)return null;const n=(e=e.replace(/\u0640/g,"")).replace(/[(\[«{][^)\]»}]*[)\]»}]\s*$/,"").replace(/^\s*ف[\u0640\u064B-\u0652]*ق[\u0640\u064B-\u0652]*ط[\u0640\u064B-\u0652]*\s+/,"").replace(/\s+ل[\u0640\u064B-\u0652]*ا\s*غ[\u0640\u064B-\u0652]*ي[\u0640\u064B-\u0652]*ر[\u0640\u064B-\u0652]*\s*$/,""),one=e=>{const n=find(e,t),s=e.trim();return 1===n.length&&(void 0!==n[0].approxStart?n[0].approxStart:n[0].start)===e.length-e.trimStart().length&&n[0].end===e.trimEnd().length&&s?n[0].value:null};let s=null;if(/^\s*-?[0-9٠-٩]+(?:[.٫][0-9٠-٩]+)?\s*$/.test(n))return westDigits(n.trim());if(/[0-9٠-٩]/.test(n)){let e=0,r=0n,o=0,l=!1;const i=/^\s*س[\u064B-\u0652]*ا[\u064B-\u0652]*ل[\u064B-\u0652]*ب[\u064B-\u0652]*\s+/.exec(n);i&&(e=i[0].length,l=!0);const a=/^(?:[\s،,]+(?=و[\u064B-\u0652]?\s*\S)|\s*)(?:و[\u064B-\u0652]?\s*)?([0-9٠-٩]+(?:\s+(?!و)[\u0621-\u064A\u064B-\u0652]+)?|[\u0621-\u064A\u064B-\u0652]+)/,c=new RegExp(a.source.replace("(?:و[\\u064B-\\u0652]?\\s*)?",""));for(let s;s=(o?a:c).exec(n.slice(e));){const l=/^[0-9٠-٩]+$/.test(s[1])?null:find(s[1],t)[0],i=null===l?westDigits(s[1]):!l||l.currency||l.noun||l.end!==s[1].length?null:l.value;if(null===i||!/^\d+$/.test(i))break;if(l&&!/^[0-9٠-٩]/.test(s[1])&&!/^[12](000)+$/.test(i)&&(0!==o||!/^[12]$/.test(i)))break;const a=l&&/^1(000)+$/.test(i)&&/ا$/.test(s[1])&&/^\s+[\u0621-\u064A]/.test(n.slice(e+s[0].length))&&!/^\s+و/.test(n.slice(e+s[0].length));r+=BigInt(i)*(a?2n:1n),e+=s[0].length,o++}const u=n.slice(e).trim(),sign=e=>null!==e&&l&&/[1-9]/.test(e)?"-"+e:e;if(o>1&&!u)s=sign(r.toString());else if(o>1&&/^،/.test(u)&&!find(u,t).some(e=>e.currency)){const e=one(words().toWords(r.toString(),{currency:"",..."long"===t.scale?{scale:"long"}:{}})+u);null!==e&&(s=sign(e))}else if(o>1){const e=/^،/.test(u)?one("واحد"+u):one(u),t=/^،/.test(u)?"1":one(u.split("،")[0]);if(null!==e&&null!==t&&/^\d+$/.test(t)){const[n,o=""]=e.split(".");s=sign((r+BigInt(n)-BigInt(t)).toString()+(o?"."+o:""))}}}if(null===s&&/[0-9٠-٩]/.test(n)&&/[\u0621-\u064A]/.test(n)){const e=n.replace(/(^|[^0-9٠-٩.,٫٬])([0-9٠-٩]+)(?![0-9٠-٩.,٫٬])/g,(e,t,n)=>t+words().toWords(eng().utils.digits(n),{currency:""}));e!==n&&(s=one(e))}if(null===s&&(s=one(n)),null===s){const e=eng().removeTashkeel(n).trim(),t=/^(سالب\s+)?(جزء|جزءا|جزءان|جزأين|جزءين)(\s+من\s)/.exec(e);t&&(s=one(e.slice(0,t.index+(t[1]||"").length+t[2].length)+(/^جزء(ا)?$/.test(t[2])?" واحد":" اثنان")+e.slice(t.index+(t[1]||"").length+t[2].length)))}if(null===s){const e=eng().removeTashkeel(n).trim(),r=/^سالب\s+/.exec(e);if(r){const n=arqamWordsToNumbers.value(e.slice(r[0].length),t);null===n||/^-/.test(n)||(s=/[1-9]/.test(n)?"-"+n:n)}}return null===s&&void 0===t.zero&&/صفر/.test(eng().removeTashkeel(n))&&(t={...t,zero:"on"},s=one(n)),s},arqamWordsToNumbers.verify=function verify(e,t,n={}){if("string"!=typeof e)throw new TypeError("arqamWordsToNumbers.verify: the words must be a string");if(n&&"code"in n)throw new TypeError('arqamWordsToNumbers.verify: unknown option "code"; did you mean "currency"?');const{currency:s,...r}=n;if(void 0!==s&&("string"!=typeof s||!/^[A-Za-z][A-Za-z0-9]{2,7}$/.test(s)))throw new TypeError('arqamWordsToNumbers.verify: currency is a currency code such as "QAR"');const o="bigint"==typeof t?t.toString():String("number"==typeof t?t:t??""),l=westDigits(o.trim()).replace(/\s+/g,"");if(!/^-?\d+(\.\d+)?$/.test(l))throw new TypeError('arqamWordsToNumbers.verify: the number must be digits, such as "1250.50"');const i=decimalFrac(l.replace(/^-/,""));l.startsWith("-")&&(i.n=-i.n);const a=find(e.replace(/[(\[«][^)\]»]*[)\]»]\s*$/,""),{zero:"on",...r});let c=null;try{c=eng().toWords(o.trim(),s?{currency:s.toUpperCase()}:{})}catch(h){c=null}const parts=e=>{const t=e.n<0n,n=t?-e.n:e.n;return{w:(t?-1n:1n)*(n/e.d),r:frac((t?-1n:1n)*(n%e.d),e.d)}},res=(e,t,n,s,r)=>({ok:e,reason:t,read:n?n.value+(n.percent?"%":""):null,expected:fracText(i),currency:n&&n.currency||null,issue:r||t,difference:s?fracText(frac(s.n*i.d-i.n*s.d,s.d*i.d)):null,expectedWords:c});if(!a.length)return res(!1,"none",null);if(a.length>1)return res(!1,"several",a[0]);const u=a[0],[f,d=""]=u.value.replace("-","").split(".");if(/\//.test(u.value))return res(!1,"different",u,null,"both");const g=frac(BigInt(f+d)*(u.value.startsWith("-")?-1n:1n),10n**BigInt(d.length));return g.n*i.d!==i.n*g.d?res(!1,"different",u,g,(e=>{const t=parts(e),n=parts(i),s=t.w===n.w,r=t.r.n===n.r.n&&t.r.d===n.r.d;return s&&r?"match":s?"subunit":r?"whole":"both"})(g)):s&&void 0!==u.currency&&null!==u.currency&&u.currency!==s.toUpperCase()?res(!1,"currency",u,g,"currency"):res(!0,"match",u,g,"match")};const W2N_PLAIN=e=>norm(eng().removeTashkeel(String(e))).replace(/\s+/g," ").trim();let se=null;function monthTable(){if(se)return se;se=[];const e=eng(),pick=e=>(/من شهر (.+?) (?:الف|ألف)/.exec(W2N_PLAIN(e))||[])[1];for(let t=1;t<=12;t++){const n=String(t).padStart(2,"0");for(const r of["","gulf","levant","maghreb","morocco"]){const s=pick(e.toDate(`2026-${n}-15`,{months:r,era:"none",year:"none"}));s&&se.push([s,t,"g"])}const s=pick(e.toDate(`1448-${n}-15 هـ`,{calendar:"h",era:"none",year:"none"}));s&&se.push([s,t,"h"])}return se=se.filter((e,t,n)=>n.findIndex(t=>t[0]===e[0]&&t[2]===e[2])===t).sort((e,t)=>t[0].length-e[0].length),se}const re=[];for(const e of["h24","common","exact"].map(e=>({timeStyle:e})).concat(P))for(const t of["on","off"])for(const n of["on","off"])for(const s of["","nasb","jarr"])re.push({...e,timeWord:t,timePeriod:n,ierab:s});const oe=new Map;let le=null,ie=null;arqamWordsToNumbers.date=function readDate(e){if("string"!=typeof e)return null;let t=W2N_PLAIN(e).split("، الموافق")[0].replace(/[،.]$/,"").trim();const pad=(e,t)=>String(e).padStart(t,"0");let n=/^(\d{1,2}|غره) (.+?) (\d{1,4}) ?(م|ه|هـ|للميلاد|ميلاديه|ميلادي|للهجره|هجريه|هجري)?$/.exec(eng().utils.digits(t));const s=n&&(e=>{const t=W2N_PLAIN(e).replace(/\/.*$/,"").replace(/ (لعام|سنه|عام)$/,"").trim();return monthTable().find(e=>e[0]===t)||monthTable().find(e=>t.startsWith(e[0]+"/"))||null})(n[2]);if(s){const e="h"===s[2]||/^(ه|هـ|للهجره|هجريه|هجري)$/.test(n[4]||"");return`${pad(n[3],4)}-${pad(s[1],2)}-${pad("غره"===n[1]?1:n[1],2)}`+(e?" هـ":"")}const r=/\s+(للميلاد|ميلاديه|ميلادي|م|للهجره|هجريه|هجري|ه|هـ)$/.exec(t);let o=!1;if(r)o=/^(للهجره|هجريه|هجري|ه|هـ)$/.test(r[1]),t=t.slice(0,r.index);else{const e=/(\d)(م|هـ?)$/.exec(t);e&&(o=/ه/.test(e[2]),t=t.slice(0,e.index+1))}if(n=/^(?:(.+?) من شهر|(غره) شهر) (.+)$/.exec(t),!n)return null;const l=n[3],i=monthTable().find(e=>l===e[0]||l.startsWith(e[0]+" ")||l.startsWith(e[0]+"/"));if(!i)return null;let a=l.slice(i[0].length);if(a.startsWith("/")){const e=monthTable().find(e=>a.slice(1).startsWith(e[0]));a=e?a.slice(1+e[0].length):a.replace(/^\/\S+/,"")}a=a.trim().replace(/^(لعام|سنه|عام)\s+/,"");const c=n[2]?"1":arqamWordsToNumbers.value(n[1],{ordinals:"on"})||arqamWordsToNumbers.value(n[1]),u=/^\d+$/.test(a)?a:arqamWordsToNumbers.value(a);return!c||!u||!/^\d+$/.test(c)||!/^\d+$/.test(u)||+c<1||+c>30+("g"===i[2])?null:`${pad(u,4)}-${pad(i[1],2)}-${pad(c,2)}`+("h"===i[2]||o?" هـ":"")},arqamWordsToNumbers.time=function readTime(e){if("string"!=typeof e)return null;const t=W2N_PLAIN(e).replace(/[،.]$/,"");if(oe.has(t))return oe.get(t);let n=null;const s=t.replace(/^الساعه /,"");if(t.length<=120&&/^(ال|منتصف)/.test(s)){const e=eng(),r=t!==s,o=function timePeriods(){if(le)return le;const e=eng(),t=new Set;for(const n of["h24","common","exact"])for(const s of["","nasb","jarr"])for(let r=0;r<24;r++)for(const o of["00","01","30"]){const l=String(r).padStart(2,"0")+":"+o,i=W2N_PLAIN(e.toTime(l,{timeStyle:n,ierab:s})),a=W2N_PLAIN(e.toTime(l,{timeStyle:n,ierab:s,timePeriod:"off"}));i!==a&&i.startsWith(a+" ")&&t.add(i.slice(a.length+1))}return le=[...t].sort((e,t)=>t.length-e.length)}().find(e=>s.endsWith(" "+e)||s===e),l=re.filter(e=>!("on"!==e.timeWord&&r||"on"!==e.timePeriod&&o)),i=function timeParts(){if(ie)return ie;const{hours:e,mins:t}=timePhrases(W2N_PLAIN,["h24","common","exact",P],["","nasb","jarr"],{},(e,t)=>({m:e,shift:t}),(e,t)=>e.m===t.m&&e.shift===t.shift);return ie={hours:e,mins:t,hp:[...e.keys()].sort((e,t)=>t.length-e.length)}}(),a=o&&s!==o?s.slice(0,-(o.length+1)):s,c=new Set,u=i.hp.find(e=>a===e||a.startsWith(e+" "));if(u){const e=a.slice(u.length).trim();for(const t of i.hours.get(u))for(const{m:n,shift:s}of i.mins.get(e)||[])for(const e of[t+s,t+s+12])c.add((e%24+24)%24*60+n)}c.add(0),c.add(720);const f=[...c].sort((e,t)=>e-t).map(e=>String(Math.floor(e/60)).padStart(2,"0")+":"+String(e%60).padStart(2,"0"));e:for(const s of l)for(const r of f)if(W2N_PLAIN(e.toTime(r,s))===t){n=r;break e}}return oe.size>=5e3&&oe.clear(),oe.set(t,n),n},arqamWordsToNumbers.removeTashkeel=(e,t)=>eng().removeTashkeel(e,t),arqamWordsToNumbers.version="1.02";let ae=null;try{ae=eng()}catch(ce){ae=null}return ae&&!Object.isFrozen(ae)&&(ae.fromWords=(e,t)=>arqamWordsToNumbers.value(e,t),ae.findNumbers=(e,t)=>arqamWordsToNumbers.find(e,t),ae.verify=(e,t,n)=>arqamWordsToNumbers.verify(e,t,n),ae.fromDate=e=>arqamWordsToNumbers.date(e),ae.fromTime=e=>arqamWordsToNumbers.time(e)),arqamWordsToNumbers}();export default t;export const version=t.version;export const find=(e,n)=>t.find(e,n),value=(e,n)=>t.value(e,n),verify=(e,n,s)=>t.verify(e,n,s),wordsToNumbers=(e,n)=>t(e,n),removeTashkeel=(e,n)=>t.removeTashkeel(e,n),date=e=>t.date(e),time=e=>t.time(e);
1
+ /*! arqamWordsToNumbers v1.05 — Arabic number words back to numbers, by Mohsen Alyafei. ES module, self-contained: no dependencies, no network. MIT licence. Built from arqamWordsToNumbers.js. Readable source: https://github.com/MohsenAlyafei/arqam. */
2
+ import{arqamAR as t}from"./arqamAR.mjs";const e=function(){function eng(){const e=void 0!==t?t:null;if(!e||"function"!=typeof e.toWords||"function"!=typeof e.removeTashkeel||"function"!=typeof e.createArqam||!e.currencies||!e.version||!e.utils||e.version.split(".").map(Number).reduce((t,e,n)=>t+e/(n?1e3:1),0)<1.064)throw new Error("arqamWordsToNumbers needs the Arqam library (arqamAR 1.64 or later): load arqamAR.js before arqamWordsToNumbers.js, or import it");return e}let e=null,n=null;function words(){const t=eng();return n!==t&&(n=t,e=t.createArqam()),e}const s=["تيريليونات",3,"تيريليونان",2,"تيريليونين",2,"تيريليونا",1,"تيريليوني",2,"تيريليونى",2,"تيريليون",0,"تريليونات",3,"تريليونان",2,"تريليونين",2,"تريليونا",1,"تريليوني",2,"تريليونى",2,"تريليون",0,"ترليونات",3,"ترليونان",2,"ترليونين",2,"ترليونا",1,"ترليوني",2,"ترليونى",2,"ترليون",0,"تريلونات",3,"تريلونان",2,"تريلونين",2,"تريلونا",1,"تريلوني",2,"تريلونى",2,"تريلون",0,"ترلونات",3,"ترلونان",2,"ترلونين",2,"ترلونا",1,"ترلوني",2,"ترلونى",2,"ترلون",0,"تيرليونات",3,"تيرليونان",2,"تيرليونين",2,"تيرليونا",1,"تيرليوني",2,"تيرليونى",2,"تيرليون",0,"تيريلونات",3,"تيريلونان",2,"تيريلونين",2,"تيريلونا",1,"تيريلوني",2,"تيريلونى",2,"تيريلون",0,"تيرلونات",3,"تيرلونان",2,"تيرلونين",2,"تيرلونا",1,"تيرلوني",2,"تيرلونى",2,"تيرلون",0],r=["ملياراي",2,"ملياراى",2,"ملاراي",2,"ملاراى",2,"ملايير",3,"مليارات",3,"مليارين",2,"ملياران",2,"ملياري",2,"مليارى",2,"مليارا",1,"مليار",0,"ميلايير",3,"ملارات",3,"ملارين",2,"ملاران",2,"ملاري",2,"ملارى",2,"ملارا",1,"ملار",0,"ملرات",3,"ملرين",2,"ملران",2,"ملري",2,"ملرى",2,"ملر",0,"مليارت",3,"مليارن",2,"ملير",0,"ميليارات",3,"ميليارين",2,"ميلياران",2,"ميلياري",2,"ميليارى",2,"ميليارا",1,"ميليار",0,"ميلارات",3,"ميلارين",2,"ميلاران",2,"ميلاري",2,"ميلارى",2,"ميلارا",1,"ميلار",0,"ميلرات",3,"ميلرين",2,"ميلران",2,"ميلري",2,"ميلرى",2,"ميلرا",1,"ميلر",0,"ميليارت",3,"ماليارن",2,"مالير",0,"ماليارات",3,"ماليارين",2,"مالياران",2,"مالياري",2,"ماليارى",2,"ماليارا",1,"ماليار",0,"مالارات",3,"مالارين",2,"مالرات",3,"مالرين",2,"مالران",2,"ماليارت",3,"بلايين",3,"بليونين",2,"بليونان",2,"بليونات",3,"بليونا",1,"بليوني",2,"بليونى",2,"بليون",0,"بلاين",3,"بلونين",2,"بلونان",2,"بلونا",1,"بلوني",2,"بلونى",2,"بلون",0,"بليونن",2,"بالايين",3,"باليونين",2,"باليونان",2,"باليونا",1,"باليوني",2,"باليونى",2,"باليون",0,"بالاين",3,"بالونين",2,"بالونان",2,"بالونا",1,"بالوني",2,"بالونى",2,"بالون",0,"باليونات",3,"باليونن",2,"بوليونان",2,"بوليونا",1,"بوليوني",2,"بوليونى",2,"بوليون",0,"بوليونات",3,"بوليونين",2,"بولونان",2,"بولونا",1,"بولوني",2,"بولونى",2,"بولون",0,"بولونين",2,"بوليونن",2],o=["مليونين",2,"ميليونين",2,"ملونين",2,"ميلونين",2,"مليونان",2,"ميليونان",2,"ملونان",2,"ميلونان",2,"مليونات",3,"مليونا",1,"ميليونا",1,"ملونا",1,"ميلونا",1,"مليوني",2,"مليونى",2,"ميليوني",2,"ميليونى",2,"ملوني",2,"ملونى",2,"ميلوني",2,"ميلونى",2,"مليون",0,"ميليون",0,"ملون",0,"ميلون",0,"ملايين",3,"ميلايين",3,"ملاين",3,"ميلاين",3],i=["الفان",2,"الفين",2,"الفي",2,"الفى",2,"الفات",3,"الفا",1,"الف",0,"الاف",3,"الوفات",3,"الوف",3,"الافات",3,"الافت",3],l=["عشره","عشرا","عسره","اعشر","اعسر","عشر","عسر","تيعشاره","تيعساره","تيعشار","تيعسار","تيعشره","تيعسره","تيعشر","تيعسر","تيشار","تيسار","تيشره","تيسره","تيشر","تيسر","تيشه","تيش","تعشاره","تعساره","تعشار","تعسار","تعشره","تعسره","تعشر","تعسر","تعيشه","تعيش","تعشه","تعسه","تعش","تعس","تاعشره","تاعسره","تاعشر","تاعسر","تاشره","تاسره","تاشر","تاسر","تاشه","تاسه","تاش","تاس","طيعشاره","طيعساره","طيعشار","طيعسار","طيعشره","طيعسره","طيعشر","طيعسر","طيشار","طيسار","طيشره","طيسره","طيشر","طيسر","طيشه","طيش","طيس","طعشاره","طعساره","طعشار","طعسار","طعشره","طعسره","طعشر","طعسر","طعيشه","طعيسه","طعيش","طعيس","طعشه","طعسه","طعش","طعس","طاعشره","طاعسره","طاعشر","طاعسر","طاشره","طاسره","طاشر","طاسر","طاشه","طاش","طاس","طاسه","تشره","تشر","طشره","طشر","طسره","طسر","يشره","يشر","يسره","يسر","اشره","اشر","اسره","اسر","عش","عس","تش","طش","طس","اش","يش","شر","ش"],a=["رون","رين","رن","ون","ين"],c=["عشره","عشرا","عسره","عسرا","عشر","عسر","اشر","اسر","يشر","يسر"],u=["مئتان","مئتا","مئتين","مئتي","مئتن","مئيتان","مئيتين","مئيتي","مئيتا","مئيتن","مائتين","مائتي","مائتى","مئتى","مائتان","مائتا","مائيتين","مائيتي","مائيتان","مائيتا","مايتين","مايئتين","مايتي","مايئتي","مايتان","مايئتان","مايتا","مايئتا","ميئتين","ميئتي","ميئتن","ميئتان","ميئتا","ميتين","ميتي","ميتن","ميتان","ميتا","ماتان","ماتئان","ماتين","ماتئين","ماتي","ماتئي","متين","متئين","متان","متئان","متي","متا","مائيه","مائه","مائا","مايئه","ماياه","مايا","مايه","ميئاه","ميئه","مياه","مييه","مئيا","مئيه","ميه","ميا","مئه"],f=new Set(u.slice(0,u.indexOf("مائيه"))),d=["واحده",1,"واحدا",1,"واهده",1,"واهدا",1,"واحدن",101,"واهدن",1,"واحد",1,"واهد",1,"وحده",1,"وهده",1,"وحدا",101,"وهدا",101,"وحد",101,"وهد",101,"احدى",101,"اهدى",101,"احدن",101,"اهدن",101,"احدا",101,"اهدا",101,"احد",101,"اهد",101,"حدا",101,"هدا",101,"حدى",101,"هدى",101,"حد",101,"هد",101,"ثنتينا",2,"ثانتينا",2,"تنتينا",2,"تانتينا",2,"اثنتينه",2,"اتنتينه",2,"ثنتينه",2,"ثانتينه",2,"تنتينه",2,"تانتينه",2,"ثنتانه",2,"ثانتانه",2,"تنتانه",2,"تلنتانه",2,"ثنتانا",2,"ثانتانا",2,"تنتانا",2,"تانتانا",2,"اثنتين",2,"اتنتين",2,"ثنتين",2,"ثانتين",2,"تنتين",2,"تانتين",2,"ثنتان",2,"ثانتان",2,"تنتان",2,"تانتان",2,"اثنتانا",2,"اتنتانا",2,"اثنتان",2,"اتنتان",2,"اثنتا",102,"اتنتا",102,"اثنتي",102,"اتنتي",102,"اثنتى",102,"اتنتى",102,"اثنينا",2,"اتنينا",2,"اثنينه",2,"اتنينه",2,"ثنينه",2,"ثانينه",2,"تنينه",2,"تانينه",2,"ثنينا",2,"ثانينا",2,"تنينا",2,"تانينا",2,"ثنانه",2,"ثانانه",2,"تنانه",2,"تانانه",2,"ثنانا",2,"ثانانا",2,"تنانا",2,"تانانا",2,"اثنين",2,"اتنين",2,"ثنين",2,"ثانين",2,"تنين",2,"تانين",2,"ثنان",2,"ثانان",2,"تنان",2,"تانان",2,"اثنانا",2,"اتنانا",2,"اثنان",2,"اتنان",2,"اثنا",102,"اتنا",102,"اثنيا",102,"اتنيا",102,"اثني",102,"اتني",102,"اثنى",102,"اتنى",102,"ثنتن",2,"تنتن",2,"ثنن",2,"تنن",2,"ثنتي",102,"تنتي",102,"ثنتى",102,"تنتى",102,"ثنتا",102,"تنتا",102,"ثني",102,"ثنى",102,"ثنا",102,"تني",102,"تنى",102,"تنا",102,"تن",102,"ثن",102,"طن",102,"ثلاثه",3,"تلاته",3,"ثلاته",3,"تلاثه",3,"ثلاثا",3,"تلاثا",3,"تلاتا",3,"ثلاتا",3,"ثلاطا",3,"تلاطا",3,"طلاتا",3,"طلاثا",3,"ثلاث",3,"تلات",3,"تلاث",3,"ثلات",3,"ثلاط",103,"تلاط",103,"طلات",103,"طلاث",103,"ثالاثه",3,"تالاته",3,"تالاثه",3,"ثالاته",3,"ثالاطه",3,"تالاطه",3,"طالاته",3,"طالاثه",3,"ثالاثا",3,"تالاتا",3,"تالاثا",3,"ثالاتا",3,"طالاتا",3,"طالاثا",3,"ثالاث",3,"تالات",3,"تالاث",3,"ثالات",3,"طالات",3,"طالاث",3,"ثالثا",103,"تالتا",103,"تالثا",103,"ثالتا",103,"طالتا",103,"طالثا",103,"ثالث",103,"تالت",103,"تالث",103,"ثالت",103,"ثالط",103,"طالت",103,"ثلثا",103,"تلتا",103,"تلثا",103,"ثلتا",103,"طلتا",103,"طلثا",103,"ثليثا",103,"تليتا",103,"تليثا",103,"ثليتا",103,"طليتا",103,"طليثا",103,"ثليث",103,"تليت",103,"تليث",103,"ثليت",103,"طليت",103,"طليث",103,"ثلث",103,"تلتون",30,"تلتو",103,"تلت",103,"تلث",103,"ثلت",103,"طلث",103,"طلت",103,"تولتون",30,"تولتو",103,"تولت",103,"ثولتون",30,"ثولتو",103,"ثولثون",30,"ثولثو",103,"تولثون",30,"تولثو",103,"ثولث",103,"تل",103,"ثل",103,"طل",103,"ثولثا",103,"تولتا",103,"طولتا",103,"طولتون",30,"طولتو",103,"طولت",103,"اربعه",4,"ارباعه",4,"اربعا",4,"ارباعا",4,"اربع",4,"ربعا",104,"رباعا",104,"رباعه",104,"رباع",104,"ربوع",104,"ربعون",40,"ربعو",104,"ربع",104,"روبعون",40,"روبعو",104,"روبع",104,"خمسه",5,"خامسه",105,"خمسا",5,"خامسا",105,"خمسون",50,"خمسو",105,"خمس",5,"خامس",105,"خومسون",50,"خومسو",105,"خومس",105,"ستا",6,"سته",6,"سوته",106,"سوتا",106,"سوتون",60,"سوتو",106,"سوت",106,"ستون",60,"ستو",106,"سيته",6,"سيتا",106,"سيت",106,"ست",6,"سودس",106,"سبعه",7,"سابعه",107,"سبعا",7,"سابعا",107,"سباه",107,"ساباه",107,"سبا",107,"سابا",107,"سوبعه",7,"سوبعا",7,"سوبا",107,"سوبعون",70,"سوبعو",107,"سوبع",107,"سبعون",70,"سبعو",107,"سبع",7,"سبيع",107,"سابع",107,"سابيع",107,"سابييع",107,"سبه",107,"سبيه",107,"سابه",107,"سب",107,"صوبعون",70,"صوبعو",107,"صوبع",107,"صبعا",107,"صبعون",70,"صبعو",107,"صبع",107,"صبا",107,"صوبا",107,"صبو",107,"ثمانيه",8,"تمانيه",8,"ثمانيا",8,"تمانيا",8,"ثمانين",80,"تمانين",80,"ثماني",8,"تماني",8,"ثمانى",8,"تمانى",8,"ثمانه",8,"تمانه",8,"ثمانا",8,"تمانا",8,"ثمان",8,"تمان",8,"ثمينا",8,"تمينا",8,"ثمينين",80,"تمينين",80,"ثميني",8,"تميني",8,"ثمينه",8,"تمينه",8,"ثمينى",8,"تمينى",8,"ثمنيا",8,"تمنيا",8,"ثمنيه",8,"تمنيه",8,"ثمنين",80,"تمنين",80,"ثمني",108,"ثمنى",108,"تمني",108,"تمنى",108,"ثمنا",108,"ثمنو",108,"تمنو",108,"ثيمانيه",8,"تيمانيه",8,"ثيمانيا",8,"تيمانيا",8,"ثيمانين",80,"تيمانين",80,"ثيماني",8,"تيماني",8,"ثيمانى",8,"تيمانى",8,"ثيمانه",8,"تيمانه",8,"ثيمانا",8,"تيمانا",8,"ثيمان",8,"تيمان",8,"ثيمنيا",8,"تيمنيا",8,"ثيمنيه",8,"تيمنيه",8,"ثيمنين",80,"تيمنين",80,"ثيمني",8,"تيمني",8,"ثيمنى",108,"تيمنى",108,"ثيمنا",108,"تيمنا",108,"ثيمن",108,"تيمن",108,"ثيمينا",8,"تيمينا",8,"ثيمينه",8,"تيمينه",8,"ثيمينين",80,"تيمينين",80,"ثيميني",8,"تيميني",8,"ثيمينى",8,"تيمينى",8,"ثيمين",108,"تيمين",108,"ثامانيه",8,"تامانيه",8,"ثامانيا",8,"تامانيا",8,"ثامانين",80,"تامانين",80,"ثاماني",8,"تاماني",8,"ثامانى",8,"تامانى",8,"ثامانه",8,"تامانه",8,"ثامانا",8,"تامانا",8,"ثامان",8,"تامان",8,"ثامينا",8,"تامينا",8,"ثامينه",8,"تامينه",8,"ثامينين",80,"تامينين",80,"ثاميني",8,"تاميني",8,"ثامينى",8,"تامينى",8,"ثامين",108,"تامين",108,"ثامنيه",8,"تامنيه",8,"ثامنيا",8,"تامنيا",8,"ثامني",108,"ثامنى",108,"تامني",108,"تامنى",108,"تمنا",108,"ثمن",108,"ثيمن",108,"ثامن",108,"تمن",108,"تيمن",108,"تامن",108,"تومنون",80,"تومنو",108,"تومن",108,"ثومنون",80,"ثومنو",108,"ثومن",108,"تسعه",9,"تيسعه",9,"تسعا",9,"تسعون",90,"تسعو",109,"تيسعا",9,"تيسعون",90,"تيسعو",109,"تسا",109,"تسه",109,"تيسا",109,"تسع",9,"تيسع",9,"تيس",109,"تس",109,"توسعون",90,"توسعو",109,"توسع",109].concat(["جوج",2,"زوج",2,"تسعود",9,"سطاش",16,"اتن",102,"اثن",102,"سط",106]),g=new Set(["تلت","ثلت","تمن","ربع"]),m=u.concat(["مياتين","مياتيين","اميه","اميا"]);for(const t of["مياتين","مياتيين"])f.add(t);const h=new Set(["مياه","متين","متي","متى","متا","زوج","وحده","وحدا","وحد","ثمينه","ثمين","تنين","ثلثين","تلتين"]),p={كوادرليون:["كوادريليون"],كوينتليون:["كوينتيليون"],سكستليون:["سكستيليون"],سيبتليون:["سبتليون","سيبتيليون"],وكتليون:["اوكتليون","اوكتيليون"],نونليون:["نونيليون"],ديسيليون:["ديسليون"]},w=[["ات",3],["ان",2],["ين",2],["ي",2],["ى",2],["ا",1],["",0]],v={short:null,long:null},k=/[\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06ED\u08D3-\u08E1\u08E3-\u08FF\uFE70-\uFE72\uFE74\uFE76-\uFE7F\u0640]/,x=new RegExp(k.source,"g"),y=/[\u0621-\u063A\u0641-\u064A\u0671-\u06D3]/;function norm(t){return t.replace(/[آأإٱٲٳٵ]/g,"ا").replace(/ؤ/g,"و").replace(/ة/g,"ه")}const S=/[\s،(«]/;function*matchesAfter(t,e,n=S){t.lastIndex=0;for(let s;s=t.exec(e);)0===s.index||n.test(e[s.index-1])?(yield s,s[0]||t.lastIndex++):t.lastIndex=s.index+1}const b=new WeakMap,W=new WeakMap;function scalesNorm(t){let e=b.get(t);return e||(e=t.map(([t,e,n])=>[t,e,n,norm(t)]),b.set(t,e)),e}function at(t,e,n){let s=0;for(;s<n.length;){for(;e<t.length&&k.test(t[e]);)e++;if(t[e]!==n[s])return-1;e++,s++}for(;e<t.length&&k.test(t[e]);)e++;return e}function skipSpaces(t,e){for(;e<t.length&&(" "===t[e]||" "===t[e]||"\t"===t[e]||k.test(t[e]));)e++;return e}const isLetterAt=(t,e)=>e<t.length&&y.test(t[e]);function atomsAt(t,e,n,s,r=0){s.memoS===t&&s.memoO===e||(s.memoS=t,s.memoO=e,s.memo=new Map);const o=8*n+r;if(s.memo.has(o))return s.memo.get(o).slice();const i=function atomsAtOnce(t,e,n,s,r){const o=[],tryFrom=(n,r)=>{{let e=n;for(;e<t.length&&k.test(t[e]);)e++;if(!function firstLetters(t){let e=W.get(t);if(e)return e;e=new Set(["ص"]);const add=t=>{const n=norm(String(t)).replace(x,"");n&&e.add(n[0])};for(let n=0;n<d.length;n+=2)add(d[n]);for(const n of m)add(n);for(const n of c)add(n);for(const n of l)add(n);for(const n of a)add(n);for(const n of scalesNorm(t))add(n[3]);return W.set(t,e),e}(s.scales).has(t[e]))return}for(const e of m){const s=at(t,n,e);s>=0&&o.push({kind:"h",v:f.has(e)?200:100,end:s,wa:r,word:e})}for(const s of function unitsAt(t,e){for(;e<t.length&&k.test(t[e]);)e++;if(!$){$=new Map;for(let t=0;t<d.length;t+=2){const e=d[t][0];$.has(e)||$.set(e,[]),$.get(e).push(t)}}return $.get(t[e])||[]}(t,n)){const i=d[s],c=at(t,n,i);if(c<0)continue;let u=d[s+1];const g=u>100;if(g&&(u-=100),u>10){o.push({kind:"t",v:u,end:c,wa:r,word:i});continue}for(const e of a){const n=at(t,skipSpaces(t,c),e);n>=0&&u>=3&&o.push({kind:"t",v:10*u,end:n,wa:r,word:i+e})}const p=skipSpaces(t,c);for(const e of l){const n=at(t,p,e);n>=0&&!a.some(e=>at(t,n,e)===n+e.length&&!isLetterAt(t,n+e.length))&&o.push({kind:"u",v:u+10,end:n,wa:r,word:i+" "+e})}if(u<=9)for(const e of m)if(!(f.has(e)||h.has(e)&&p>c)){const n=at(t,p,e);n>=0&&o.push({kind:"h",v:100*u,end:n,wa:r,word:i+e})}o.push({kind:"u",v:u,end:c,wa:r,word:i,only:g,tanween:/\u064B/.test(e.slice(n,c+1))})}for(const e of c){const s=at(t,n,e);if(s<0)continue;let i=!1;for(const n of a){const l=at(t,skipSpaces(t,s),n);l>=0&&(o.push({kind:"t",v:20,end:l,wa:r,word:e+n}),i=!0)}o.push({kind:"u",v:10,end:s,wa:r,word:e})}for(const[i,l,a,c]of scalesNorm(s.scales)){const s=at(t,n,c);s>=0&&o.push({kind:"s",v:l,type:a,end:s,wa:r,word:i,tanween:/\u064B/.test(e.slice(n,s+1))})}if(s.zero){let e=at(t,n,"صفرا");e<0&&(e=at(t,n,"صفر")),e>=0&&o.push({kind:"z",v:0,end:e,wa:r,word:"صفر"})}};tryFrom(n,!1),"و"===t[n]&&tryFrom(skipSpaces(t,n+1),!0);const i=o.filter(n=>!isLetterAt(t,n.end)||r<4&&atomsAt(t,e,n.end,s,r+1).length>0).filter(n=>!(n.only||!n.wa&&!s.ambiguous&&h.has(n.word))||r<4&&atomsAt(t,e,skipSpaces(t,n.end),s,r+1).some(e=>"t"===e.kind&&e.wa||n.only&&g.has(n.word)&&"s"===e.kind&&!e.wa&&(/^تا?لاف$/.test(e.word)||"لاف"===e.word&&/ت$/.test(n.word)&&e.end>n.end&&!/\s/.test(t.slice(n.end,e.end-3))))),u=new Set;return i.filter(t=>{const e=t.kind+t.end+"|"+t.v+"|"+t.wa+"|"+t.type;return!u.has(e)&&(u.add(e),!0)}).sort((t,e)=>e.end-t.end||t.wa-e.wa)}(t,e,n,s,r).filter(s=>!(s.end<=e.length&&!isLetterAt(t,s.end)&&markedDual(e.slice(n,s.end))));return s.memo.set(o,i),i.slice()}let $=null;function readLarge(t){const e=[];let n=0;for(;n<t.length;){let s=0n,r=0n,o=0,i=null,l=n,a=0,c=n-1,u=0n,f=!1,d=!1,g=!1,m=!1;const close=()=>{c=l,u=s+r,g=d};for(;l<t.length;l++){const e=t[l],c=l===n,u=!c&&(o>0||f);if("s"===e.kind){const n=10n**BigInt(e.v),a=null!==i&&n===i&&m&&r<100n;if(null!==i&&n>=i&&!a)break;if(m=!a&&1===o&&!e.wa,!e.wa&&o>0&&!c){if(2===e.type)break;if(3===e.type&&!(r%100n>=3n&&r%100n<=10n||2n===r))break;s+=r*n}else{if(!c&&!e.wa)break;{if(3===e.type)break;let i=2===e.type?2n:1n;if(1===e.type&&!e.tanween&&l+1>=t.length&&e.nounAfter&&(i=2n),1===o&&e.wa)s+=(r+i)*n,d=!0;else{if(0!==o)break;s+=i*n}}}r=0n,o=0,i=a?n-1n:n,f=!0,close();continue}if(u&&!e.wa)break;if("z"===e.kind){if(!c)break;r=0n,o=9,close(),l++;break}if("h"===e.kind){if(0!==o)break;r=BigInt(e.v),o=1}else if("u"===e.kind){if(o>1)break;if(r+=BigInt(e.v),a=e.v,o=e.v>=10?3:2,e.only)continue}else if("t"===e.kind){if(3===o||2===o&&(a>9||!e.wa))break;r+=BigInt(e.v),o=3}close()}c<n?(e.push(null),n++):(e.push({from:n,to:c,value:u,legalOff:g}),n=c+1)}return e}function readSmall(t){const e=[];let n=0;for(;n<t.length;){let s=0n,r=0n,o="",i=null,l=n,a=n-1,c=0n,u=0,f=!1;const key=(t,e)=>2n*t+BigInt(e),endPart=t=>{const e=key(t,"h"===o?1:0);return!(null!==i&&e<=i||(i=e,s+=r*t,r=0n,o="",f=!1,0))};for(;l<t.length;l++){const e=t[l],d=l===n;if(!(d||e.wa||"s"===e.kind&&f))break;if("s"===e.kind){const n=10n**BigInt(e.v);if(f&&!e.wa){if(2===e.type)break;if(3===e.type&&!(r%100n>=3n&&r%100n<=10n||2n===r))break;if(!endPart(n))break}else{if(f&&!endPart(1n))break;if(3===e.type)break;let s=2===e.type?2n:1n;if(1===e.type&&!e.tanween&&l+1>=t.length&&(d||e.nounAfter)&&(s=2n),r=s,o="u",!endPart(n))break}a=l,c=s;continue}if("z"===e.kind){if(!d)break;a=l,c=0n,l++;break}const g="t"===e.kind&&f&&"u"===o&&u<=9&&e.wa&&!e.comma&&r<10n;if(!g){if(f&&!endPart(1n))break;r=0n,o="h"===e.kind?"h":"u",f=!0}if(r+=BigInt(e.v),"u"===e.kind&&(u=e.v),"t"!==e.kind||g||(u=99),"u"===e.kind&&e.only)continue;const m=[s,r,i],h=key(1n,"h"===o?1:0);(null===i||h>i)&&(a=l,c=s+r),[s,r,i]=m}a<n?(e.push(null),n++):(e.push({from:n,to:a,value:c}),n=a+1)}return e}function aloneAt(t,e,n,s,r){let o=skipSpaces(t,n);if(s){if("،"===t[o]&&(o=skipSpaces(t,o+1)),"و"!==e[o])return null;for(o++;k.test(t[o]);)o++}const i=currencyAt(t,e,o);if(!i||i.start!==skipSpaces(t,o))return null;if(/(^|\s)صفرا?\s*$/.test(t.slice(0,i.start).replace(/[\u064B-\u0652\u0670]/g,"")))return null;if(/[0-9٠-٩]\s*$/.test(t.slice(0,i.start)))return null;const l=i.list.filter(t=>!!t.minor==!!r&&!t.def&&t.count),a=[...new Set(l.map(t=>t.count))],c=[...new Set(l.map(t=>t.code))];if(!l.length||1!==a.length||2!==a[0]&&!l.some(t=>t.adj)&&!s&&t.slice(0,i.start).trim())return null;if(r&&!s&&!l.some(t=>t.adj)&&1!==c.length)return null;const u=nextWord(t,e,i.end),f=u&&/^(واحد[اةه]?|اثن(ان|ين|تان|تين|ا|تا))$/.test(u.w.replace(/[\u064B-\u0652\u0670]/g,""))&&!(()=>{const n=nextWord(t,e,u.end);return n&&/^عشر[هة]?$/.test(n.w)})();return f&&!r?null:{m:{...i,list:l},count:a[0],code:1===c.length?c[0]:null,end:f?u.end:i.end}}function findCore(t,e,n){const s=[];for(const r of function runs(t,e){const n=t,s=norm(t),r=[];let o=0;for(;o<s.length;){if(!isLetterAt(s,o)||o>0&&isLetterAt(s,o-1)&&!e.joined.has(o)){o++;continue}let t=o,i=atomsAt(s,n,o,e);if(!i.length&&"بفكل".includes(s[o])){let r=o+1;for(;r<s.length&&k.test(s[r]);)r++;i=atomsAt(s,n,r,e).filter(t=>!t.wa),i.length&&(t=r)}if(!i.length){for(;o<s.length&&(isLetterAt(s,o)||k.test(s[o]));)o++;continue}const l=[];let a=t,c=i;for(;c.length;){const t=c[0];l.push({...t,start:a});let r=skipSpaces(s,t.end),o=!1;"،"!==s[r]&&","!==s[r]||(o=!0,r=skipSpaces(s,r+1)),isLetterAt(s,t.end)&&(e.joined.add(t.end),r=t.end);const i=r<s.length?atomsAt(s,n,r,e):[],u=i.find(t=>t.wa||!o&&"s"===t.kind);if(!u||o&&!u.wa)break;const f=i.filter(t=>t.wa===u.wa);o&&f.forEach(t=>{t.comma=!0}),a=r,c=f}let u=l.length;for(let e=1;e<l.length;e++)if(l[e].comma&&"s"!==l[e-1].kind&&!l.slice(e).some(t=>"s"===t.kind)){u=e;break}{const t=l.slice(0,u),o=t[t.length-1],i=skipSpaces(s,o.end),a=s.slice(i).replace(x,"").match(/^\S+/),c="و"===s[i]&&!atomsAt(s,n,i+1,e).length&&(()=>{try{const t=currencyAt(n,s,i);return!!t&&t.start===i}catch(t){return!1}})();o.nounAfter=isLetterAt(s,i)&&("و"!==s[i]||c)&&!(a&&/^(فاصله|بالمائه|بالمئه|بالميه|في|الا|جزء)/.test(a[0])),r.push(t)}o=u<l.length?l[u-1].end:l[l.length-1].end}return r}(t,n)){const o=r[r.length-1],i=norm(t.slice(skipSpaces(t,o.end))).replace(x,""),l=/^[،,\s]*و?(جز[ءاي]|اجزاء)|^من\s/.test(i.replace(/^[،,\s]*و?\s*[0-9٠-٩][0-9٠-٩,٬]*\s*/,"")),a=/فاصل[هة][\u064B-\u0652]*[\s،]*$/.test(t.slice(Math.max(0,r[0].start-12),r[0].start));let c="small"!==e.order||a?readLarge(r):null,u="large"===e.order||a?null:readSmall(r);const f=/^[،,\s]*و[\u064B-\u0652]?\s*[0-9٠-٩]/.test(i);if(l&&f&&/^[،,\s]*و[\u064B-\u0652]?\s*[0-9٠-٩,٬]+\s*(جزء|اجزاء)/.test(i)){let t=r.length-1;for(;t>0&&!r[t].comma;)t--;const e=t>0?readLarge(r.slice(t)):null;if(e&&1===e.length&&e[0]&&e[0].value%1000n==0n&&e[0].value<1000000n){const n={...e[0],from:t,to:r.length-1},s=u?readSmall(r.slice(0,t)):null,o=c?readLarge(r.slice(0,t)):null;s&&1===s.length&&s[0]&&(u=[s[0],n]),o&&1===o.length&&o[0]&&(c=[o[0],n])}}const d=/^\s*[،,]\s*و\s*جز[ءاي]/.test(i);if(l&&!f&&!d){const one=t=>1===t.length&&t[0],t=i.match(/من\s+ال\s*ـ?\s*([0-9٠-٩][0-9٠-٩,٬]*)|من\s+(\S+(?:\s+\S+)?)/);let e=null;if(t&&t[1])e=BigInt(westDigits(t[1]));else if(t&&t[2])for(const s of[t[2],t[2].replace(/^ال/,"")]){const t=arqamWordsToNumbers.find(s,{order:"large",currency:"off"});if(t.length&&0===t[0].start){e=BigInt(t[0].value.split(".")[0]);break}}const n=one(readLarge(r));if(n&&(!e||n.value<e))c=[n],u=null;else for(let s=1;s<r.length;s++)if(r[s].comma){const t=one(readLarge(r.slice(s)));if(!t||e&&t.value>=e)continue;const n={...t,from:s,to:r.length-1},o=u?one(readSmall(r.slice(0,s))):null,i=c?one(readLarge(r.slice(0,s))):null;if(o||i){u=o?[o,n]:null,c=i?[i,n]:null;break}}}const count=t=>1e3*t.filter(Boolean).length+t.filter(t=>!t).length,g=r.some((t,e)=>e>0&&"h"===t.kind&&t.wa&&("u"===r[e-1].kind||"t"===r[e-1].kind)&&r.slice(e+1).some(t=>"s"===t.kind)),m=r.some((t,e)=>e>0&&t.comma&&"s"!==r[e-1].kind&&r.slice(e).some(t=>"s"===t.kind)),p=u?c?count(u)<count(c)||count(u)===count(c)&&(g||m)?u:c:u:c;for(const e of p){if(!e)continue;const o=r[e.from],i=r[e.to];if(e.from===e.to&&!n.ambiguous&&h.has(o.word))continue;let l=o.start;o.wa&&(l=skipSpaces(t,at(norm(t),o.start,"و"))),s.push({start:l,end:i.end,value:e.value,unit:"s"===i.kind?10n**BigInt(i.v):1n,wa:o.wa,waAt:o.start})}}return s}const frac=(t,e=1n)=>{const n=((t,e)=>{for(t=t<0n?-t:t;e;)[t,e]=[e,t%e];return t})(t,e)||1n;return{n:t/n,d:e/n}},fadd=(t,e)=>frac(t.n*e.d+e.n*t.d,t.d*e.d),fmul=(t,e)=>frac(t.n*e.n,t.d*e.d);function fracText(t,e,n){let{n:s,d:r}=t;const o=s<0n;o&&(s=-s);let i,l=r;for(;l%2n==0n;)l/=2n;for(;l%5n==0n;)l/=5n;if(1n!==l||n&&r>1n){const t=s/r;i=(t?t+" ":"")+s%r+"/"+r}else{let t=0;for(;10n**BigInt(t)%r;)t++;void 0!==e&&e>t&&(t=e);const n=(s*10n**BigInt(t)/r).toString().padStart(t+1,"0");i=t?n.slice(0,-t)+"."+n.slice(-t):n}return(o?"-":"")+i}function nextWord(t,e,n){const s=skipSpaces(t,n);if(s>=t.length)return null;if("،"===t[s]||","===t[s])return{w:"،",start:s,end:s+1};if("%"===t[s]||"٪"===t[s])return{w:"%",start:s,end:s+1};if(/[0-9٠-٩]/.test(t[s])){let e=s;for(;e<t.length&&/[0-9٠-٩.,٫٬]/.test(t[e]);)e++;for(;/[.,٫٬]/.test(t[e-1]);)e--;return{w:t.slice(s,e),start:s,end:e,digits:!0}}if(!isLetterAt(e,s)&&"ـ"!==t[s])return null;let r=s;for(;r<t.length&&(isLetterAt(e,r)||k.test(t[r]));)r++;return{w:e.slice(s,r).replace(x,""),start:s,end:r}}const westDigits=t=>eng().utils.digits(t).replace(/[٫]/g,".").replace(/[,٬]/g,"");function decimalFrac(t){t=westDigits(t);const[e,n=""]=t.split(".");return frac(BigInt(e+n||"0"),10n**BigInt(n.length))}const B={نصف:[1n,2n],نص:[1n,2n],ربع:[1n,4n],ثلث:[1n,3n],تلت:[1n,3n],ثلثين:[2n,3n],ثلثان:[2n,3n],تلتين:[2n,3n],خمس:[1n,5n],سدس:[1n,6n],سبع:[1n,7n],ثمن:[1n,8n],تسع:[1n,9n],عشر:[1n,10n]},T={انصاف:2n,ارباع:4n,اثلاث:3n,اخماس:5n,اسداس:6n,اسباع:7n,اثمان:8n,اتساع:9n,اعشار:10n},A={نصفان:2n,نصفين:2n,ثلثان:3n,ثلثين:3n,ثلثا:3n,ثلثي:3n,تلتين:3n,ربعان:4n,ربعين:4n,ربعا:4n,خمسان:5n,سدسان:6n,سدسين:6n,سدسا:6n,سدسي:6n,سبعان:7n,ثمنان:8n,ثمنين:8n,تسعان:9n,عشران:10n},I=/^(ثلثين|تلتين|نصفين)$/,j={خمسين:5n,خمسي:5n,خمسا:5n,سبعين:7n,سبعي:7n,سبعا:7n,ثمنين:8n,ثمني:8n,ثمنا:8n,تسعين:9n,تسعي:9n,تسعا:9n,عشرين:10n,عشري:10n,عشرا:10n,ربعين:4n},q={خمس:5n,سبع:7n,تسع:9n,عشر:10n};function markedDual(t){if(!/^(?:و[\u064B-\u0652]*)?(\S)\u064F/.exec(t))return null;let e=norm(t).replace(x,"");if(!/^و/.test(e)||j[e]||q[e]||(e=e.slice(1)),q[e])return{d:q[e],single:!0};const n=j[e];return n?{d:n,single:/[\u064B-\u064D]$/.test(t)}:null}function fractionWord(t,e,n,s){const r=s&&markedDual(s);if(r)return r.single?[1n,r.d]:[2n,r.d];const o=N.exec(t);if(n&&o&&/^[اي]$/.test(o[2]))return[2n,B[o[1]][1]];if(B[t])return B[t];if(o&&"ا"===o[2])return B[o[1]];const i=A[t];return!i||"on"!==e.fractions&&I.test(t)?null:[2n,i]}const N=/^(نصف|ثلث|ربع|سدس)([اي]?)$/,E=/^(نصف|ربع|ثلث|تلت|خمس|سدس|سبع|تسع|عشر)$/,F=/^(نص|ثمن)$/;function countedFraction(t,e){if(e>=3n&&T[t])return T[t];const n=B[t.replace(/ا$/,"")];return e>=11n&&n&&1n===n[0]&&!/^(نص|تلت)$/.test(t.replace(/ا$/,""))?n[1]:0n}const M=[["بالمائه"],["بالمئه"],["بالميه"],["في","المائه"],["في","المئه"],["في","الميه"],["بالمايه"]],z=/^(جزء|جزءا|جزءان|جزءين|جزاين|جزان|جزئين|اجزاء)$/,D=/^(جزءان|جزءين|جزاين|جزان|جزئين)$/;let R,O=null,C=null,P=new Map,L=null,U=new Set,Z=new Map;const G=new Map;function nounWords(t,e,n,s,r){const o=words();let i=o.toWords(e,{currency:t,tashkeel:"n",prefix:"",suffix:"",brackets:"",emphasisOneTwo:"on",...n}),l=e;if(s){const t=i.lastIndexOf("،");if(t<0)return[];i=i.slice(t+1),l=String(+e.split(".")[1])}else/^0\./.test(e)&&(l=String(+e.split(".")[1]));if(!G.has(l)){const t=new Set;for(const e of["r","n","j"])for(const n of["",1])for(const s of r(o.toWords(l,{tashkeel:"n",ierab:e,majorGender:n})))t.add(s);G.set(l,t)}const a=G.get(l),c=r(i).filter(t=>!(a.has(t)||t.startsWith("و")&&a.has(t.slice(1))));return s&&c.length&&c[0].startsWith("و")&&(c[0]=c[0].slice(1)),c}function currencyForms(t){if(U.has(t))return;U.add(t);const e=eng().currencies[t],n=+e[0]||0,plainWords=t=>norm(eng().removeTashkeel(t)).replace(/،/g," ").split(/\s+/).filter(Boolean),s=[new Set,new Set,new Set,new Set],r=new Map;for(const o of["1","2","3","11","100"])for(const i of["r","n","j"]){const l=nounWords(t,o,{ierab:i},!1,plainWords).join(" "),a=nounWords(t,o,{ierab:i,ignoreCountry:"on"},!1,plainWords).join(" ");if(s[0].add(l),s[1].add(a),"1"===o||"2"===o)for(const t of[l,a])r.set("M"+t,+o);if(n>0&&!e[21])for(const e of["1","2","3","11"]){const o="."+e.padStart(n,"0").slice(-n),l=nounWords(t,"0"+o,{ierab:i},!1,plainWords).join(" ");s[2].add(l),"1"!==e&&"2"!==e||r.set("m"+l,+e);const a=nounWords(t,"1"+o,{ierab:i},!0,plainWords).join(" "),c=nounWords(t,"1"+o,{ierab:i,ignoreCountry:"on"},!0,plainWords).join(" ");if(s[2].add(a),s[3].add(c),"1"===e||"2"===e)for(const t of[a,c])r.set("m"+t,+e)}}s.forEach((e,s)=>{for(const o of e)if(o&&!/[0-9]/.test(o)&&!/^(من|جزء)(\s|$)/.test(o))for(const e of[o,o.split(" ").map(t=>"ال"+t).join(" "),...o.includes(" ")?["ال"+o]:[]]){const i=e.replace(/ى/g,"ي");P.has(i)||P.set(i,[]);const l=P.get(i);l.some(e=>e.code===t&&e.minor===s>=2)||l.push({code:t,minor:s>=2,adj:s%2==0&&o.includes(" "),dec:n,def:e!==o,count:r.get((s>=2?"m":"M")+o)||0})}})}function currencyAt(t,e,n){!function currencySync(){const t=eng()[Symbol.for("arqam.tablesChanged")];if(L&&void 0!==t&&t===R)return;const e=eng().currencies,n=Object.keys(e);let s=L&&n.length===Z.size;if(s)for(const r of n)if(Z.get(r)!==e[r]){s=!1;break}if(R=t,s)return;P=new Map,U=new Set,Z=new Map,L=new Map;const plainWords=t=>norm(eng().removeTashkeel(t)).replace(/،/g," ").split(/\s+/).filter(Boolean);for(const r of n){Z.set(r,e[r]);const t=e[r],n=+t[0]||0,s=["1","3"].concat(n>0&&!t[21]?["1."+"1".padStart(n,"0"),"1."+"3".padStart(n,"0")]:[]);for(const e of s)for(const t of nounWords(r,e,{ignoreCountry:"on"},e.includes("."),plainWords)){const e=t.replace(/^ال/,"").slice(0,2);L.has(e)||L.set(e,new Set),L.get(e).add(r)}}}();const s=nextWord(t,e,n);if(!s||s.digits)return null;const r=s.w.replace(/^ال/,"").slice(0,2),o=L.get(r);if(!o)return null;for(const u of o)currencyForms(u);const i=P;let l=[],a=n,c=null;for(let u=0;u<6;u++){const s=nextWord(t,e,a);if(!s||s.digits||"،"===s.w||"%"===s.w)break;l.push(s.w),a=s.end;const r=l.join(" ").replace(/ى/g,"ي"),o=r.replace(/ا(?=\s|$)/g,""),u=i.get(r)||i.get(o);u&&(c={end:a,list:u,start:skipSpaces(t,n)})}return c}function phrases(t,e,n){const s=t,r=norm(t),o=findCore(t,e,n);n.alone||(O={text:t,core:o},C={text:t,ends:new Map});for(let l,a=/[0-9٠-٩]+(?:[.٫][0-9٠-٩]+)?/g;l=a.exec(s);){if(l.index>0&&/[0-9٠-٩.٫]/.test(s[l.index-1]))continue;const c=skipSpaces(r,l.index+l[0].length),u=(c>l.index+l[0].length||isLetterAt(r,c)?atomsAt(r,s,c,n).filter(t=>"s"===t.kind&&!t.wa):[]).find(t=>2!==t.type&&(3!==t.type||/(^|0)[3-9]$|(^|\d)10$/.test(westDigits(l[0]).replace(/^0+(?=\d)/,""))));if(u&&!o.some(t=>t.start<=c&&c<t.end&&t.start<l.index)){const f=10n**BigInt(u.v),d=fmul(decimalFrac(l[0]),frac(f));for(let g=o.length-1;g>=0;g--)o[g].start>=c&&o[g].start<u.end&&o.splice(g,1);o.push({start:l.index,end:u.end,value:null,f:d,unit:f,digitsScale:!0})}}for(let m,h=/(^|[^\u0621-\u064A])(فاصل[ةه])/g;m=h.exec(s);){const p=m.index+m[1].length,w=o.filter(t=>t.end<=p).pop();w&&/^[\s،,]*$/.test(s.slice(w.end,p))||o.push({start:p,end:p,value:0n,unit:1n,zeroFaslah:!0})}if("off"!==e.currency)for(let v=0;v<s.length;){const y=nextWord(s,r,v);if(!y)break;v=Math.max(y.end,v+1);const S=y.digits||o.some(t=>y.start<t.end&&t.start<y.end)?null:fractionWord(y.w,e,!0,s.slice(y.start,y.end));if(!S||F.test(y.w)&&"on"!==e.ambiguous)continue;const b=currencyAt(s,r,y.end);b&&b.start===skipSpaces(s,y.end)&&b.list.some(t=>!t.minor)&&o.push({start:y.start,end:y.end,value:null,f:frac(...S),unit:1n,fractionWord:!0})}o.sort((t,e)=>t.start-e.start||t.end-e.end);const i=[];for(let W=0;W<o.length;W++){const $=o[W];if(i.length&&$.start<i[i.length-1].end)continue;if($.zeroFaslah&&!/^فاصل/.test(norm(s.slice($.start,$.start+6))))continue;let B=$.f||frac($.value),T=$.start,R=$.end,P=$.fractionWord?{asFraction:!0,fractionEnd:$.end}:{},L=null;if(!("off"===e.currency||$.digitsScale||1n!==$.value&&2n!==$.value||$.wa)){const G=i.length?i[i.length-1].end:0,Q=[];for(let K=T-1;K>=G&&Q.length<6;K--)!isLetterAt(r,K)||0!==K&&(isLetterAt(r,K-1)||k.test(s[K-1]))||Q.push(K);for(const V of Q.reverse()){let X=currencyAt(s,r,V),Y=!1;if(!X&&"و"===r[V]){let _=V+1;for(;k.test(s[_]);)_++;X=currencyAt(s,r,_),Y=!0}if(X&&skipSpaces(s,X.end)===T){L=X,L.waAt=Y?V:-1;break}}L&&(T=L.start);const H=i[i.length-1],J=H&&(skipSpaces(s,H.end)===L?.waAt||/^\s*[،,]\s*$/.test(s.slice(H.end,L?.waAt))&&1n===H.f.d&&0n!==H.f.n&&H.f.n%1000n==0n);L&&L.waAt>=0&&J&&void 0===H.currency&&!H.percent&&(i.pop(),B=fadd(H.negative?frac(-H.f.n,H.f.d):H.f,frac($.value)),T=H.start,H.negative&&(P.negative=!0))}const juz=t=>{let o=nextWord(s,r,t),i=0n;if(o&&/^و/.test(o.w)&&z.test(o.w.slice(1))&&"واجزاء"!==o.w&&(i=D.test(o.w.slice(1))?2n:1n,o={...o,w:o.w.slice(1)}),!(o&&z.test(o.w)||o&&"من"===o.w))return null;let l="من"===o.w?o.start:o.end,a=nextWord(s,r,l);if(a&&/^(واحد[اه]?|اثنان|اثنين)$/.test(a.w)&&(l=a.end,a=nextWord(s,r,l)),!a||"من"!==a.w)return null;const c=nextWord(s,r,a.end);if(!c)return null;let u=null,f=null,d=!1;if(c.digits)u=BigInt(westDigits(c.w).replace(/\..*/,"")),f=c.end;else{const t=atomsAt(r,s,c.start,n).some(t=>t.end>=c.end&&!t.wa),o=c.start+(t?0:(r.slice(c.start).match(/^ال\u0652?[ـ]?/)||[""])[0].length);if(d=o>c.start,/^الـ?[0-9٠-٩]/.test(s.slice(c.start))){const t=nextWord(s,r,c.start+s.slice(c.start).search(/[0-9٠-٩]/));u=BigInt(westDigits(t.w)),f=t.end}else{const t=findCore(s.slice(o,o+90),{...e,order:"large"},{...n,joined:new Set});t.length&&0===t[0].start&&(u=t[0].value,f=o+t[0].end)}}return!u||u<=0n?null:{den:u,end:f,extra:i,def:d}},waNext=(t,e)=>t&&/^[\s،,]*(?:و[\u064B-\u0652]*\s*)?$/.test(s.slice(e,t.start))&&(t.wa||"و"===r[t.start]);{const tt=s.slice(0,T).match(/(سالب|سَالِبُ|سَالِبَ|سَالِبِ|سالبُ|سالبَ|سالبِ)\s*$/);tt&&(T-=tt[0].length,P.negative=!0)}let U=nextWord(s,r,R);const readNum=(t,e)=>{let n=0n,i=W,l=0,a=null,c=null;for(;o[i+1]&&o[i+1].start<t;)i++;for(;;){const u=s.slice(t).match(l||!e?/^[\s،,]*و[\u064B-\u0652]?\s*/:/^\s*/);if(!u)break;const f=t+u[0].length,d=o[i+1],g=d&&(d.start===f||d.start>=t&&d.start<f&&"و"===r[d.start])?d:null,m=/و/.test(u[0])||e&&!l?nextWord(s,r,f):null;if(m&&z.test(m.w)&&!/^اجزاء$/.test(m.w)){n+=D.test(m.w)?2n:1n,t=m.end;const e=o[i+1];!e||e.start!==skipSpaces(s,t)||1n!==e.value&&2n!==e.value||(t=e.end,i++),l++;break}if(g){n+=null!==g.value?g.value:g.f.n/g.f.d,t=g.end,i++,l++;continue}const h=s.slice(f).match(/^[0-9٠-٩][0-9٠-٩,٬]*(?:[.٫][0-9٠-٩]+)?/);if(h){if(/[.٫]/.test(h[0])&&!l){c=decimalFrac(h[0]),t=f+h[0].length;break}n+=BigInt(westDigits(h[0])),t=f+h[0].length,l++;const e=s.slice(t).match(/^\s*\/\s*([0-9٠-٩][0-9٠-٩,٬]*)/);if(e){a=BigInt(westDigits(e[1])),t+=e[0].length;break}continue}break}return{num:n,q:t,k:i,parts:l,slash:a,dec:c}};if(U&&"،"===U.w){const et=nextWord(s,r,U.end);et&&"فاصله"===et.w&&(U=et)}if(U&&"فاصله"===U.w){let nt=U.end,st=0,rt="",ot=!1;{let lt=nt,ct="",ut=W,ft=0,dt=0;for(;;){const gt=nextWord(s,r,lt);if(!gt)break;let mt=null,ht=gt.end;if(/^صفرا?$/.test(gt.w))mt="0";else{const wt=o[ut+1];wt&&wt.start===gt.start&&null!==wt.value&&wt.value<=9n&&!wt.wa&&(mt=wt.value.toString(),ht=wt.end,ut++)}if(null===mt)break;ct+=mt,lt=ht,ft++;const pt=nextWord(s,r,lt);if(pt&&"،"===pt.w){const vt=nextWord(s,r,pt.end);if(vt&&(/^صفرا?$/.test(vt.w)||o[ut+1]&&o[ut+1].start===vt.start&&o[ut+1].value<=9n)){lt=pt.end,dt++;continue}}break}ft>=2&&dt===ft-1&&(B=fadd(B,frac(BigInt(ct),10n**BigInt(ct.length))),R=lt,W=ut,ot="sw")}if(!ot)for(;;){const kt=nextWord(s,r,nt);if(!kt||!/^صفرا?$/.test(kt.w))break;{st++,nt=kt.end;const xt=nextWord(s,r,nt);xt&&"،"===xt.w&&(nt=xt.end)}}const it=o[W+1];if(ot);else if(!it||it.start!==skipSpaces(s,nt)||it.wa){const yt=nextWord(s,r,nt);!yt||!yt.digits||/[.٫]/.test(yt.w)||juz(yt.end)||it&&it.digitsScale&&it.start===yt.start||(rt=westDigits(yt.w),nt=yt.end,ot=!0);const St=ot?{parts:0}:readNum(nt,!0);if(St.parts){const bt=juz(St.q);bt?(B=fadd(B,frac(St.num,bt.den)),R=bt.end,W=St.k,ot="juz"):St.slash?(B=fadd(B,frac(St.num,St.slash)),R=St.q,W=St.k,ot="juz"):(rt=St.num.toString(),nt=St.q,W=St.k,ot=!0)}else(st||ot)&&(ot=!0)}else if(it&&it.start===skipSpaces(s,nt)&&!it.wa){let Wt=[it],$t=W+1;for(;$t+1<o.length;){const Bt=nextWord(s,r,o[$t].end);if(!Bt||"،"!==Bt.w||o[$t+1].start!==skipSpaces(s,Bt.end)||o[$t+1].wa)break;if(o[$t].value>9n||o[$t+1].value>9n)break;Wt.push(o[++$t])}if(Wt.length>1&&Wt.every(t=>t.value<=9n))rt=Wt.map(t=>t.value.toString()).join(""),nt=Wt[Wt.length-1].end,W=$t,ot=!0;else{const Tt=readNum(nt,!0),At=juz(Tt.q);At?(B=fadd(B,frac(Tt.num,At.den)),R=At.end,W=Tt.k,ot="juz"):(rt=Tt.num.toString(),nt=Tt.q,W=Tt.k,ot=!0)}}if(!0===ot&&(B=fadd(B,frac(BigInt(rt||"0"),10n**BigInt(st+rt.length))),R=nt),!ot&&$.zeroFaslah)continue;ot&&(U=nextWord(s,r,R))}{let It=R,jt=!1;const qt=nextWord(s,r,It);qt&&"،"===qt.w&&(jt=!0,It=qt.end),o[W+1];const Nt=R===$.end?juz(R):null;if(Nt&&!$.digitsScale&&(B=Nt.extra&&!Nt.def?fadd(frac($.value),frac(Nt.extra,Nt.den)):frac($.value+Nt.extra,Nt.den),R=Nt.end,P.fromFraction=!0),!Nt||$.digitsScale||1n!==$.value&&2n!==$.value){if(!Nt||$.digitsScale){const{num:Et,q:Ft,k:Mt,parts:zt,slash:Dt,dec:Rt}=readNum(It,!1);let Ot=!1;if(Rt)B=fadd(B,Rt),R=Ft,Ot=!0;else if(Dt)B=fadd(B,frac(Et,Dt)),R=Ft,W=Mt,Ot=!0;else if(zt){const Ct=juz(Ft);Ct&&(B=fadd(B,frac(Et,Ct.den)),R=Ct.end,P.fromFraction=!0,W=Mt,L&&(R=ofCurrency(R)),Ot=!0)}if(!Ot){const Pt=s.slice(It).match(/^\s*و[\u064B-\u0652]?\s*/),Lt=nextWord(s,r,Pt?It+Pt[0].length:It),Ut=!Pt&&Lt&&"الا"===Lt.w,Zt=Ut?nextWord(s,r,Lt.end):Lt,Gt=Zt&&nextWord(s,r,Zt.end),Qt=Gt&&(/^و./.test(Gt.w)&&(()=>{let t=Gt.start+1;for(;k.test(s[t]);)t++;return atomsAt(r,s,t,n).length>0})()||/^(عشر|عشره)$/.test(Gt.w)||"off"!==e.currency&&(()=>{const t=currencyAt(s,r,Gt.start);return t&&t.start===Gt.start})()),Ht=Zt&&!Zt.digits?fractionWord(Zt.w.replace(/^ال/,""),e,!1,s.slice(Zt.start,Zt.end)):null;if(Ht&&(Pt||Ut)&&!Qt){const[Jt,Kt]=Ht,Vt=fmul(frac(Jt,Kt),frac($.unit));B=fadd(B,Ut?frac(-Vt.n,Vt.d):Vt),R=Zt.end,P.fromFraction=!0}}}}else{let Xt=T;for(;Xt>0&&/\s/.test(s[Xt-1]);)Xt--;let Yt=Xt;for(;Yt>0&&/[\u0621-\u064A\u064B-\u0652]/.test(s[Yt-1]);)Yt--;const _t=norm(s.slice(Yt,Xt)).replace(x,"").replace(/[ئأ]/g,"ء");Yt<Xt&&z.test(_t)&&!(i.length&&i[i.length-1].end>Yt)&&(T=Yt)}}if("on"===e.fractions&&R===$.end&&1n===B.d&&!L){const te=nextWord(s,r,R),ee=te&&"على"===te.w?o[W+1]:null;ee&&ee.start===skipSpaces(s,te.end)&&ee.value>0n&&1n===(ee.f||frac(ee.value)).d&&(B=frac(B.n,ee.value),R=ee.end,W++,P.asFraction=!0)}if(R===$.end&&1n===B.d&&B.n>=3n&&!L){const ne=nextWord(s,r,R),se=ne&&!ne.digits?countedFraction(ne.w,B.n):0n;if(se){B=frac(B.n,se),R=ne.end,P.asFraction=!0,P.fractionEnd=R;const re=i[i.length-1];if(B.n<B.d&&re&&1n===re.f.d&&!re.percent&&(re.currency?/^\s*،?\s*و[\u064B-\u0652]?\s*$/:/^\s*و[\u064B-\u0652]?\s*$/).test(s.slice(re.end,T))&&(i.pop(),B=fadd(re.negative?frac(-re.f.n,1n):re.f,B),T=re.start,re.negative&&(P.negative=!0),void 0!==re.currency)){const{start:oe,end:ie,text:le,value:ae,f:ce,...ue}=re;Object.assign(P,ue),delete P.fractionEnd}}}function ofCurrency(t){const e=nextWord(s,r,t);if(!e||"من"!==e.w)return t;const n=currencyAt(s,r,e.end);return n&&n.start===skipSpaces(s,e.end)?n.end:t}if(!L&&"off"!==e.currency){const fe=nextWord(s,r,R);if(fe&&"من"===fe.w){const de=currencyAt(s,r,fe.end);de&&de.start===skipSpaces(s,fe.end)&&de.list.every(t=>t.def)&&(L={...de,after:!0})}}if("off"!==e.currency){let ge=L||currencyAt(s,r,R),me=null,he=null,pe=null,we=L||(ge&&ge.start===skipSpaces(s,R)?ge:null);if(!we){const ve=aloneAt(s,r,R,!0)||aloneAt(s,r,R,!0,!0);ve&&(B=fadd(B,frac(BigInt(ve.count))),we=ge=ve.m,ve.end>ve.m.end&&(R=Math.max(R,ve.end)))}if(we){const ke=we.list.filter(t=>!t.minor),xe=we.list.filter(t=>t.minor),ye=new Set(ke.map(t=>t.code)),Se=ke.length?ke:xe,be=[...new Set(Se.map(t=>t.code))];1===be.length&&(me=be[0]);const We=[...new Set(Se.map(t=>t.dec))];if(pe=1===We.length?We[0]:null,he=s.slice(we.start,we.end),L&&!L.after||(R=we.end),ke.length||null===pe){for(;o[W+1]&&o[W+1].start<R;)W++;const $e=o[W+1];if(waNext($e,R)){const Be=currencyAt(s,r,$e.end);if(Be&&Be.start===skipSpaces(s,$e.end)){const Te=Be.list.filter(t=>t.minor&&(me?t.code===me:ye.has(t.code))),Ae=[...new Set(Te.map(t=>t.dec))];if(Te.length&&1===Ae.length&&(B=fadd(B,frac($e.value,10n**BigInt(Ae[0]))),R=Be.end,W++,pe=Ae[0],!me)){const Ie=[...new Set(Te.map(t=>t.code))];1===Ie.length&&(me=Ie[0])}}else{const je=aloneAt(s,r,$e.end,!0,!0),qe=je?je.m.list.filter(t=>t.minor&&t.count&&(me?t.code===me:ye.has(t.code))):[];if(qe.length&&1===[...new Set(qe.map(t=>t.dec))].length){for(B=fadd(B,frac($e.value+BigInt(je.count),10n**BigInt(qe[0].dec))),R=je.end,W++,pe=qe[0].dec;o[W+1]&&o[W+1].start<R;)W++;if(!me){const Ne=[...new Set(qe.map(t=>t.code))];1===Ne.length&&(me=Ne[0])}}else{const Ee=juz($e.end);Ee&&(B=fadd(B,frac($e.value+Ee.extra,Ee.den)),R=Ee.end,W++,R=ofCurrency(R))}}}if(R===we.end){const Fe=readNum(R,!1),Me=Fe.parts?juz(Fe.q):null;Me&&(B=fadd(B,frac(Fe.num+Me.extra,Me.den)),R=ofCurrency(Me.end),W=Fe.k)}if(R===we.end||L){let ze=R;const De=nextWord(s,r,ze);De&&"،"===De.w&&(ze=De.end);const Re=skipSpaces(s,ze);if("و"===r[Re]){let Oe=Re+1;for(;k.test(s[Oe]);)Oe++;Oe=skipSpaces(s,Oe);const Ce=nextWord(s,r,Oe);if(Ce&&Ce.digits&&Ce.start===Oe&&/^[0-9٠-٩]+$/.test(Ce.w)){const Pe=currencyAt(s,r,Ce.end);if(Pe&&Pe.start===skipSpaces(s,Ce.end)){const Le=Pe.list.filter(t=>t.minor&&(me?t.code===me:ye.has(t.code))),Ue=[...new Set(Le.map(t=>t.dec))];if(Le.length&&1===Ue.length){for(B=fadd(B,frac(BigInt(westDigits(Ce.w)),10n**BigInt(Ue[0]))),R=Pe.end,pe=Ue[0];o[W+1]&&o[W+1].start<R;)W++;if(!me){const Ze=[...new Set(Le.map(t=>t.code))];1===Ze.length&&(me=Ze[0])}}}}}}if(R===we.end||L){let Ge=R;const Qe=nextWord(s,r,Ge);Qe&&"،"===Qe.w&&(Ge=Qe.end);const He=skipSpaces(s,Ge);if("و"===r[He]){let Je=He+1;for(;k.test(s[Je]);)Je++;const Ke=currencyAt(s,r,Je),Ve=o[W+1];if(!Ke||!Ve||Ve.wa||1n!==Ve.value&&2n!==Ve.value||Ve.start!==skipSpaces(s,Ke.end)){if(Ke&&Ke.start===skipSpaces(s,Je)&&(!Ve||Ve.start!==skipSpaces(s,Ke.end))){const Xe=Ke.list.filter(t=>t.minor&&t.count&&(me?t.code===me:ye.has(t.code))),Ye=[...new Set(Xe.map(t=>t.dec))],_e=[...new Set(Xe.map(t=>t.count))];if(Xe.length&&1===Ye.length&&1===_e.length&&(B=fadd(B,frac(BigInt(_e[0]),10n**BigInt(Ye[0]))),R=Ke.end,pe=Ye[0],!me)){const tn=[...new Set(Xe.map(t=>t.code))];1===tn.length&&(me=tn[0])}}}else{const en=Ke.list.filter(t=>t.minor&&(me?t.code===me:ye.has(t.code))),nn=[...new Set(en.map(t=>t.dec))];if(en.length&&1===nn.length&&(B=fadd(B,frac(Ve.value,10n**BigInt(nn[0]))),R=Ve.end,W++,pe=nn[0],!me)){const sn=[...new Set(en.map(t=>t.code))];1===sn.length&&(me=sn[0])}}}}if(R===we.end&&1n===B.d){const rn=s.slice(R).match(/^\s*و[\u064B-\u0652]?\s*/),on=rn?nextWord(s,r,R+rn[0].length):null,ln=on&&!on.digits&&on.start===R+rn[0].length?fractionWord(on.w,e):null;if(ln&&ln[0]<ln[1]){const an=nextWord(s,r,on.end);if(!an||an.digits||!(/^ال/.test(an.w)||atomsAt(r,s,an.start,n).length>0||(()=>{const t=currencyAt(s,r,an.start);return t&&t.start===an.start})()))for(B=fadd(B,frac(ln[0],ln[1])),R=on.end,P.fromFraction=!0;o[W+1]&&o[W+1].start<R;)W++}}}else B=fmul(B,frac(1n,10n**BigInt(pe)));P.currency=me,P.noun=he.replace(x,""),null!==pe&&(P.places=pe)}}{const cn=nextWord(s,r,R);if(cn&&"%"===cn.w)R=cn.end,P.percent=!0;else for(const un of M){let fn=R,dn=!0,gn=R;for(const mn of un){const hn=nextWord(s,r,fn);if(!hn||hn.w!==mn){dn=!1;break}fn=gn=hn.end}if(dn){R=gn,P.percent=!0;break}}}if(P.negative&&(B=frac(-B.n,B.d)),R<=T)continue;const Z=!P.currency&&(P.asFraction||"on"===e.fractions&&P.fromFraction);P.fractionEnd&&!n.alone&&C.ends.set(T,{end:P.fractionEnd,value:fracText(B,void 0,!0)}),delete P.asFraction,delete P.fromFraction,delete P.fractionEnd,i.push({start:T,end:R,text:s.slice(T,R),value:fracText(B,void 0,Z),...P,f:B})}if(function fractionWordsAlone(t,e,n,s){const inside=t=>s.some(e=>t>=e.start&&t<e.end),r=[];for(let o=0;o<t.length;){const i=nextWord(t,e,o);if(!i)break;if(o=Math.max(i.end,o+1),i.digits||inside(i.start))continue;let l=null,a=i.end,c=null,u=!0;const f=markedDual(t.slice(i.start,i.end));if(f&&/^و/.test(i.w)&&!j[i.w]&&!q[i.w]){const e=t.slice(i.start).match(/^و[\u064B-\u0652]*/)[0].length;i.start+=e}if(f)if(f.single){if("on"!==n.fractions)continue;l=frac(1n,f.d)}else{const s=/[اي]$/.test(i.w)?nextWord(t,e,i.end):null,r=/[اي]$/.test(i.w)&&(!s||s.digits||"،"===s.w||"%"===s.w);if(r&&("on"!==n.fractions||/ي$/.test(i.w)))continue;l=frac(r?1n:2n,f.d)}else if(!A[i.w]||"on"!==n.fractions&&I.test(i.w))if(z.test(i.w)&&!/^اجزاء$/.test(i.w)){const r=nextWord(t,e,i.end),o=r&&"من"===r.w?s.find(e=>e.start===skipSpaces(t,r.end)):null;if(!o||1n!==o.f.d||o.f.n<=0n||o.currency||o.percent||o.negative)continue;l=frac(D.test(i.w)?2n:1n,o.f.n),a=o.end,c=o,u="on"===n.fractions}else"on"===n.fractions&&(E.test(i.w)||/^نصفا$/.test(i.w)||"on"===n.ambiguous&&F.test(i.w))&&(l=frac(...fractionWord(i.w,n)));else{let s=!1;if(/[اي]$/.test(i.w)){const r=nextWord(t,e,i.end);if(!r||r.digits||"،"===r.w||"%"===r.w||/[\u064B-\u064D]/.test(t.slice(i.start,i.end))){const t=N.exec(i.w);if("on"!==n.fractions||!t||"ا"!==t[2])continue;s=!0}}l=s?frac(...fractionWord(i.w,n)):frac(2n,A[i.w])}if(!l)continue;let d=i.start,g=!1;const m=t.slice(0,d).match(/(سالب|سَالِبُ|سَالِبَ|سَالِبِ|سالبُ|سالبَ|سالبِ)\s*$/);m&&!inside(d-m[0].length)&&(d-=m[0].length,g=!0,l=frac(-l.n,l.d)),r.push([{start:d,end:a,text:t.slice(d,a),value:fracText(l,void 0,u),...g?{negative:g}:{},f:l},c]),o=a}for(const[o,i]of r)i&&s.splice(s.indexOf(i),1),s.push(o);r.length&&s.sort((t,e)=>t.start-e.start)}(s,r,e,i),!("off"===e.currency||n&&n.alone)){const inside=t=>i.some(e=>t>=e.start&&t<e.end);for(let pn=0;pn<s.length;){const wn=nextWord(s,r,pn);if(!wn)break;const vn=inside(wn.start)?null:aloneAt(s,r,wn.start,!1)||aloneAt(s,r,wn.start,!1,!0);if(!vn){pn=wn.end;continue}const kn=/^\s+و/.test(s.slice(vn.m.end)),xn=" "+(1===vn.count?"واحد":"اثنان")+(kn?"،":""),yn=phrases(s.slice(0,vn.m.end)+xn+s.slice(vn.m.end),e,{...n||{},alone:!0}).find(t=>t.start<=vn.m.start&&t.end>=vn.m.end+xn.length);if(!yn){pn=vn.m.end;continue}const Sn=yn.end-xn.length,bn=Math.min(yn.start,vn.m.start);for(let Wn=i.length-1;Wn>=0;Wn--)i[Wn].start>=bn&&i[Wn].start<Sn&&i.splice(Wn,1);i.push({...yn,start:bn,end:Sn,text:s.slice(bn,Sn)}),pn=Sn}i.sort((t,e)=>t.start-e.start)}for(let $n=i.length-2;$n>=0;$n--){const Bn=i[$n],Tn=i[$n+1];Bn.currency&&Bn.noun&&!Tn.currency&&/^\s+$/.test(s.slice(Bn.end,Tn.start))&&/^(1|2)$/.test(String(Tn.value))&&/^(واحد[اةه]?|اثن(ان|ين|تان|تين))$/.test(norm(eng().removeTashkeel(Tn.text)).trim())&&i.splice($n,2,{...Bn,end:Tn.end,text:s.slice(Bn.start,Tn.end)})}return i}let Q=null;function ordWords(){if(Q)return Q;Q={};const add=(t,e)=>{const n=norm(eng().removeTashkeel(t)).replace(/^ال/,"");Q[n]=e,Q[n.replace(/ى$/,"ي")]=e};for(let t=1;t<=10;t++)for(const e of["m","f"])add(words().toWords(String(t),{ordinal:e,tashkeel:"n"}),t);for(const t of["m","f"])add(words().toWords("11",{ordinal:t,tashkeel:"n"}).split(" ")[0],1);return Q}const H=["order","scale","zero","ambiguous","arabicNumbers","currency","ordinals","dates","times","fractions"];function options(t){if(null===t||"object"!=typeof t)throw new TypeError("arqamWordsToNumbers: the options must be an object");const e={order:"auto",scale:"short",zero:"off",ambiguous:"off",currency:"words",ordinals:"off",dates:"on",times:"on",fractions:"off",...t};for(const n in t)if(!H.includes(n))throw new TypeError('arqamWordsToNumbers: unknown option "'+n+'"; use: '+H.join(", "));if(!["auto","large","small"].includes(e.order))throw new TypeError('arqamWordsToNumbers: order is "auto", "large" or "small"');if(!["short","long"].includes(e.scale))throw new TypeError('arqamWordsToNumbers: scale is "short" or "long"');if(!["words","code","off"].includes(e.currency))throw new TypeError('arqamWordsToNumbers: currency is "words", "code" or "off"');for(const n of["zero","ambiguous","ordinals","arabicNumbers","dates","times","fractions"])if(n in t&&!["on","off"].includes(e[n]))throw new TypeError("arqamWordsToNumbers: "+n+' is "on" or "off"');return v[e.scale]||(v[e.scale]=function scaleTables(t){const e=[],add=(t,n,s)=>e.push([t,n,s]),name=(t,e)=>norm(words().toWords("1"+"000".repeat(t),{scale:e,tashkeel:"n"}));for(const[l,a]of[[s,12],[r,9],[o,6],[i.concat(["تلاف",3,"تالاف",3,"لاف",3]),3]])for(let t=0;t<l.length;t+=2)add(l[t],a,l[t+1]);const n=[];for(let s=5;s<=11;s++){const t=name(s,"short");n.push([t,3*s]);for(const e of p[t]||[])n.push([norm(e),3*s])}for(const[s,r]of n)for(const[t,e]of w)add(s+t,r,e);if(t){for(const t of e)t[1]>=9&&!/^م/.test(norm(t[0]))&&(t[1]=2*t[1]-6);for(let t=3;t<=11;t++){const e=name(t,"long");if(/يار$/.test(e)&&!/^م/.test(e))for(const[n,s]of w)add(e+n,3*t,s)}}return e.sort((t,e)=>e[0].length-t[0].length)}("long"===e.scale)),e}function find(t,e={}){if("string"!=typeof t)throw new TypeError("arqamWordsToNumbers: the text must be a string");const n=options(e),s={scales:v[n.scale],zero:"on"===n.zero,ambiguous:"on"===n.ambiguous,joined:new Set};let r=phrases(t,n,s).map(({f:t,...e})=>e);{const e=function ordinals(t,e,n,s){const r=t,o=norm(t),i=[],definiteAt=t=>{let s="",i=[],l=t;const a=Math.min(r.length,t+200);for(;l<a;){if(l===t||/\s/.test(r[l-1])){const e=o.slice(l).match(/^(و[ً-ْ]?)?ال/);let a=l;for(;a<r.length&&(isLetterAt(o,a)||k.test(r[a]));)a++;const c=atomsAt(o,r,l+(e&&e[1]?e[1].length:0),n).some(t=>t.end===a&&!t.wa);if(e&&!c){if(e[1]&&l!==t)for(let t=0;t<e[1].length;t++)s+=r[l+t],i.push(l+t);l+=e[0].length;continue}}s+=r[l],i.push(l),l++}const c=findCore(s,{...e,order:"large"},{...n,joined:new Set});return c.length&&c[0].start===skipSpaces(s,0)&&!c[0].wa?{value:c[0].value,end:i[c[0].end-1]+1}:null};for(let a,c=/(^|[^ء-ي])(ال)/g;a=c.exec(o);){const t=a.index+a[1].length;if(s.some(e=>t>=e.start&&t<e.end)||i.some(e=>t>=e.start&&t<e.end))continue;const e=nextWord(r,o,t);if(!e)continue;const l=e.w.replace(/^ال/,"");if(void 0===ordWords()[l]&&!atomsAt(o,r,t+2,n).length)continue;if(atomsAt(o,r,t,n).some(t=>t.end===e.end&&!t.wa))continue;let c=null,u=e.end,f=!1,d=t;if(void 0!==ordWords()[l]){c=BigInt(ordWords()[l]),f=l.startsWith("حادي");const t=nextWord(r,o,u);if(t&&/^(عشر|عشره)$/.test(t.w)&&c<10n)c+=10n,u=t.end,f=!1;else{const t=nextWord(r,o,u);if(t&&/^وال/.test(t.w)&&c<10n){const e=definiteAt(t.start);e&&e.value>=20n&&e.value<=90n&&e.value%10n==0n&&(c+=e.value,u=e.end,f=!1)}}}else{const s=definiteAt(t);s&&s.value%10n==0n&&s.value>=20n&&(c=s.value,u=s.end);let a=t;for(;a>0&&/\s/.test(r[a-1]);)a--;let f=a;for(;f>0&&(isLetterAt(o,f-1)||k.test(r[f-1]));)f--;if(f<a&&/^(الف|الاف|مليون|ملايين|مليار|مليارات)/.test(l)&&!/^ال/.test(o.slice(f))&&atomsAt(o,r,f,n).length&&!i.some(t=>f>=t.start&&f<t.end)){const t=definiteAt(f);t&&t.end>=e.end&&t.value>=1000n&&(c=t.value,u=t.end,d=f)}}if(null===c)continue;const g=nextWord(r,o,u);if(g&&"بعد"===g.w){const t=definiteAt(skipSpaces(r,g.end));t&&(c+=t.value,u=t.end,f=!1)}f||i.push({start:d,end:u,text:r.slice(d,u),value:c.toString(),ordinal:!0})}const l={ثان:2,حاد:1};for(let a,c=/(^|[^ء-ي])([ء-ي])/g;a=c.exec(o);){const t=a.index+a[1].length;if(/^ال/.test(o.slice(t)))continue;if(s.some(e=>t>e.start&&t<e.end)||i.some(e=>t>=e.start&&t<e.end))continue;const e=nextWord(r,o,t);if(!e||e.start!==t)continue;let n=void 0===ordWords()[e.w]||/^ال/.test(e.w)?l[e.w]:ordWords()[e.w],c=!1;if(void 0===n){const s=nextWord(r,o,e.end);if(!s||"بعد"!==s.w)continue;const i=definiteAt(t);if(!i||i.end!==e.end||i.value<20n||i.value>90n||i.value%10n)continue;n=Number(i.value),c=!0}let u=BigInt(n),f=e.end,d=!1;const g=c?null:nextWord(r,o,f);if(g&&/^(عشر|عشره)$/.test(g.w)&&u<10n&&!/^حاد$/.test(e.w))u+=10n,f=g.end,d=!0;else if(g&&/^و./.test(g.w)&&u<10n){let t=g.start+1;for(;t<r.length&&k.test(r[t]);)t++;const e=definiteAt(t);e&&e.value>=20n&&e.value<=90n&&e.value%10n==0n&&(u+=e.value,f=e.end,d=!0)}const m=nextWord(r,o,f);if(m&&"بعد"===m.w){const t=definiteAt(skipSpaces(r,m.end));t&&(u+=t.value,f=t.end,d=!0)}!d||c&&u<100n||i.push({start:t,end:f,text:r.slice(t,f),value:u.toString(),ordinal:!0})}return i.sort((t,e)=>t.start-e.start)}(t,n,{...s,joined:new Set},r);r=r.filter(t=>!e.some(e=>t.start<e.end&&e.start<t.end)).concat("on"===n.ordinals?e:[])}if("on"===n.dates||"on"===n.times){const e=function datesTimes(t,e){const{n,at:s}=dtNorm(t),r=[],o=[],free=(t,e)=>!o.some(([n,s])=>t<s&&n<e),item=(e,n,i)=>{const l=s[e],a=s[n];o.push([e,n]),r.push({start:l,end:a,text:t.slice(l,a),...i})},orig=(e,n)=>t.slice(s[e],s[n]),i=eng(),l=i.utils;if("on"===e.dates&&/شهر|[0-9]/.test(n)){const tryMonth=t=>{const e=n.slice(t).match(/^\s*((?:[^\s،,.؛0-9]+)(?:\s*\/\s*[^\s،,.؛0-9]+)?(?:\s+[^\s،,.؛0-9]+){0,2})/);if(!e)return null;const s=e[1].split(/\s+/);for(let n=s.length;n>=1;n--){const o=s.slice(0,n).join(" "),i=t+e[0].length-e[1].length,a=i+o.length,c=orig(i,a);let u=!1;try{l.parseDate("1 "+c+" 2000"),u=!0}catch(r){}if(!u&&!/\//.test(c))try{l.parseDate("1 "+c+" 1440",{input:"h"}),u=!0}catch(r){}if(u)return{a:i,b:a,name:c}}return null},tryYear=e=>{let r=n.slice(e).match(/^\s+(?:(لعام|لسنه|سنه|عام)\s+)?/);if(!r)return null;let o=e+r[0].length;const i=n.slice(o).match(/^([0-9]{1,4})(?![0-9])/);let l,a;if(i)l=+i[1],a=o+i[0].length;else{const e=find(t.slice(s[o],s[Math.min(n.length,o+140)]),{dates:"off",times:"off",currency:"off"});if(!e.length||0!==e[0].start||!/^[0-9]+$/.test(e[0].value))return null;l=+e[0].value,a=dtNorm(t.slice(0,s[o]+e[0].end)).n.length}if(l<1||l>9999)return null;const c=n.slice(a).match(nt),u=c?/هجر|^ه/.test(c[1])?"h":"g":"";return{y:l,end:c?a+c[0].length:a,cal:u}},add=(t,e,n,s,r)=>{if(!free(t,r.end))return;const o="h"===r.cal?"هـ":"g"===r.cal?"م":"";let i,a=!1;const c=String(r.y).padStart(4,"0");try{i=l.parseDate(`${n} ${s.name} ${c}${o}`)}catch(d){return}try{l.parseDate(`${n} ${s.name} ${c}${o}`,{input:"g"})}catch(d){a=!0}const pad=t=>String(t).padStart(2,"0"),u=`${String(i.year).padStart(4,"0")}-${pad(i.month)}-${pad(i.day)}`,f=a?`${i.hijri.day}/${i.hijri.month}/${i.hijri.year}هـ`:`${i.day}/${i.month}/${i.year}م`;item(t,r.end,{value:f,kind:"date",calendar:a?"h":"g",iso:u})};for(const t of matchesAfter(/(?:(غره)\s+|من\s+)شهر\s+/g,n)){let e,s;if(t[1])e=t.index,s=1;else{const r=n.slice(0,t.index).replace(/\s+$/,""),o=r.split(/(\s+)/);for(let t=Math.min(7,o.length);t>=1;t-=2){const n=o.slice(o.length-t).join(""),i=dtDays().get(n.replace(/\s+/g," "));if(i){s=i,e=r.length-n.length;break}}if(!s)continue}const r=tryMonth(t.index+t[0].length);if(!r)continue;const o=tryYear(r.b);o&&add(e,null,s,r,o)}for(const t of matchesAfter(/([0-9]{1,2})\s+(?=[^\s0-9])/g,n)){if(!free(t.index,t.index+t[0].length))continue;const e=tryMonth(t.index+t[1].length);if(!e)continue;const s=tryYear(e.b);s&&/^\s+(?:(?:لعام|لسنه|سنه|عام)\s+)?[0-9]/.test(n.slice(e.b))&&add(t.index,null,+t[1],e,s)}}if("on"===e.times&&/ساع|دقيق|دقائق|منتصف|ثاني|ثوان|صباحا|ظهرا|عصرا|مساء|ليلا|فجرا/.test(n)){const pad=t=>String(t).padStart(2,"0"),e=[...n.matchAll(/[^\s،,.؛()«»]+/g)];for(let r=0;r<e.length;r++){const o=e[r].index;if(!free(o,o+1))continue;let l=null;for(let t=Math.min(12,e.length-r);t>=1&&!l;t--){const s=e[r+t-1].index+e[r+t-1][0].length,i=n.slice(o,s).replace(/\s+/g," ");if(/[،,.؛]/.test(i))continue;const a=dtTime(i),c=a?null:dtDur(i);a?l={kind:"time",b:s,key:i,vals:a,k:t}:c&&(l={kind:"duration",b:s,key:i,value:c,k:t})}if(!l)continue;let a=l.b;if("duration"===l.kind){item(o,a,{value:l.value,kind:"duration"}),r+=l.k-1;continue}let c="";const u=n.slice(a).match(/^\s+و\s*((?:[^\s،,.؛]+\s+){0,6}?)(ثانيه|ثوان|ثانيتان|ثانيتين)(?![\u0621-\u064A])/);if(u){let e=null;if(u[1].trim()){const n=find(t.slice(s[a+u[0].indexOf(u[1])],s[a+u[0].indexOf(u[1])+u[1].trimEnd().length]),{dates:"off",times:"off"});1===n.length&&/^[0-9]+$/.test(n[0].value)&&(e=+n[0].value)}else e=/ثانيتان|ثانيتين/.test(u[2])?2:1;null!==e&&e<60&&(c=":"+pad(e),a+=u[0].length)}const f=n.slice(a).match(et);if(!/^الساعه /.test(l.key)&&"منتصف الليل"!==l.key&&!f&&!/(دقيقه|دقائق|دقيقتان|دقيقتين|النصف|الربع|الثلث)$/.test(l.key))continue;let d,g=l.vals,m=!1;if(f){const t=dtKey(f[1]),e=g.filter(([e,n])=>dtKey(i.toTime(e,{...n,tashkeel:"n"})).endsWith(t));e.length?g=e:"بعد منتصف الليل"===t&&(g=g.map(([t,e])=>[pad(+t.split(":")[0]%12)+":"+t.split(":")[1],e])),a+=f[0].length}const h=[...new Set(g.map(t=>t[0]))];if(1===h.length)d=h[0]+c;else{const[t,e]=h[0].split(":");d=`${+t%12||12}:${e}`+c,m=!0}for(item(o,a,{value:d,kind:"time",...m?{hour12:!0}:{}});r+1<e.length&&e[r+1].index<a;)r++}}return r}(t,n);e.length&&(r=r.filter(t=>!e.some(e=>t.start<e.end&&e.start<t.end)).concat(e))}return r=function approxFind(t,e){for(const s of e){const e=t.slice(0,s.start);for(const[t,n]of rt){const r=e.match(n);if(r){s.approx=t,s.approxText=r[1],s.approxStart=e.length-r[0].length+r[0].indexOf(r[1]);break}}}const bare=t=>t.replace(/[\u064B-\u0652\u0670\u0640]/g,"").replace(/[أإآ]/g,"ا"),scaleOf=t=>{if(!t)return 1n;const e=bare(t),n=it.find(([t])=>bare(t)===e);return n?n[1]:1n},tensOf=t=>ot[bare(t).replace(/^و/,"").replace(/(ون|ين)$/,"")]||0,add=(n,s,r,o,i)=>{const l={start:n,end:s,text:t.slice(n,s),value:null,approx:r,min:String(o),max:String(i)};e=e.filter(t=>!(t.start<s&&n<t.end)).concat(l)},n=t.replace(/[\u064B-\u0652\u0670\u0640]/g,"");if(/بضع/.test(n))for(const s of matchesAfter(ut,t)){const t=scaleOf(s[5]);let e=3n,n=9n;if(s[2])e=13n,n=19n;else if(s[3]){const t=BigInt(tensOf(s[3]));e=t+3n,n=t+9n}add(s.index,s.index+s[0].length,"few",e*t,n*t)}if(/ن[يى]ف/.test(n))for(const s of t.matchAll(ft)){const n=BigInt(tensOf(s[2])),r=scaleOf(s[4]);let o=s.index,i=0n;if(s[1]){const n=e.find(e=>null!==e.value&&e.end<=s.index&&!t.slice(e.end,s.index).trim());n&&/^\d+$/.test(n.value)&&(i=BigInt(n.value),o=n.start)}add(o,s.index+s[0].length,"plus",i+(n+1n)*r,i+(n+9n)*r)}if(/ن[يى]ف/.test(n))for(const s of t.matchAll(dt)){const n=e.find(e=>null!==e.value&&e.end<=s.index&&!t.slice(e.end,s.index).trim()&&/^\d+$/.test(e.value));if(n){const r=BigInt(n.value),o={...n,start:n.start,end:s.index+s[0].length,text:t.slice(n.start,s.index+s[0].length),value:null,approx:"plus",min:String(r+1n),max:String(r+9n)};e=e.filter(t=>t!==n).concat(o)}}return e}(t,r),r.sort((t,e)=>t.start-e.start)}const J=/[\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06ED\u0640]/;function dtNorm(t){let e="",n=[];for(let s=0;s<t.length;s++){const r=t[s];if(J.test(r))continue;let o="أإآٱ".includes(r)?"ا":"ة"===r?"ه":"ى"===r?"ي":r;const i="٠١٢٣٤٥٦٧٨٩".indexOf(o),l="۰۱۲۳۴۵۶۷۸۹".indexOf(o);i>=0?o=String(i):l>=0&&(o=String(l)),e+=o,n.push(s)}return n.push(t.length),{n:e,at:n}}const dtKey=t=>dtNorm(eng().removeTashkeel(t)).n.replace(/\s+/g," ").trim();let K=null;function dtDays(){if(K)return K;K=new Map;for(let t=1;t<=31;t++)for(const e of["r","n","j"])K.set(dtKey(eng().toWords(String(t),{ordinal:"m",ierab:e,tashkeel:"n"})),t);return K.set("غره",1),K}const V={timeStyle:"common",timeParts:"on"};function timePhrases(t,e,n,s,r,o){const i=new Map,l=new Map,add=(t,e,n,s)=>{const r=t.get(e)||[];r.some(t=>s(t,n))||r.push(n),t.set(e,r)},pad=t=>String(t).padStart(2,"0");for(const a of e)for(const e of n){const bare=n=>t(eng().toTime(n,{..."string"==typeof a?{timeStyle:a}:a,ierab:e,timePeriod:"off",timeWord:"off",...s}));for(let t=0;t<24;t++)add(i,bare(`${pad(t)}:00`),t,(t,e)=>t===e);const n=[...i.keys()].sort((t,e)=>e.length-t.length);for(const t of[3,15])for(let e=0;e<60;e++){const s=bare(`${pad(t)}:${pad(e)}`),a=n.find(t=>s===t||s.startsWith(t+" "));if(a)for(const n of i.get(a)){const i=n%12==t%12?0:n%12==(t+1)%12?-1:null;null!==i&&add(l,s.slice(a.length).trim(),r(e,i),o)}}}return{hours:i,mins:l}}let X=null;const Y=new Map,_=new Map;function dtParts(){if(X)return X;const t=eng(),pad=t=>String(t).padStart(2,"0"),add=(t,e,n)=>{const s=t.get(e)||[];s.includes(n)||s.push(n),t.set(e,s)},e=new Map,n=new Map,s=new Map,longest=(t,e)=>[...t.keys()].filter(t=>e===t||e.startsWith(t+" ")).sort((t,e)=>e.length-t.length)[0],{hours:r,mins:o}=timePhrases(dtKey,["common","exact","h24",V],["r","n","j"],{tashkeel:"n"},(t,e)=>100*(e+1)+t,(t,e)=>t===e);for(const i of["r","n","j"]){const dur=e=>dtKey(t.toTime(e,{timeStyle:"duration",ierab:i,tashkeel:"n"}));for(let t=1;t<48;t++)add(e,dur(`${t}:00`),t);for(let t=1;t<60;t++)add(s,dur(`0:${pad(t)}`),t);for(const t of[1,2,3,10,11,15,25])for(let s=1;s<60;s++){const r=dur(`${t}:${pad(s)}`),o=longest(e,r);o&&add(n,r.slice(o.length).trim(),s)}}return X={hours:r,mins:o,dh:e,dm:n,dOnly:s,longest}}const tt=["common","exact","h24"].map(t=>({timeStyle:t})).concat(V);function dtTime(t){if(Y.has(t))return Y.get(t);let e=null;const n=t.replace(/^الساعه /,"");if(/^(ال|منتصف)/.test(n)){const s=eng(),r=dtParts(),pad=t=>String(t).padStart(2,"0"),o=new Set(/^منتصف/.test(n)?[0]:[]),i=r.longest(r.hours,n);if(i)for(const t of r.hours.get(i))for(const e of r.mins.get(n.slice(i.length).trim())||[]){const n=Math.floor(e/100)-1,s=e%100;for(const e of[t+n,t+n+12])o.add((e%24+24)%24*60+s)}const l=[...o].sort((t,e)=>t-e).map(t=>`${pad(Math.floor(t/60))}:${pad(t%60)}`),a=[];if(!l.length)return Y.set(t,null),null;for(const e of tt)for(const n of["r","n","j"])for(const r of l){const o=dtKey(s.toTime(r,{...e,ierab:n,timePeriod:"off",tashkeel:"n"}));o!==t&&o.replace(/^الساعه /,"")!==t||a.some(t=>t[0]===r&&t[1]===e)||a.push([r,e])}a.length&&(e=a)}return Y.size>=2e4&&Y.clear(),Y.set(t,e),e}function dtDur(t){if(_.has(t))return _.get(t);let e=null;if("ساعه"!==t&&"دقيقه"!==t&&/ساع|دقيق|دقائق/.test(t)){const n=eng(),s=dtParts(),pad=t=>String(t).padStart(2,"0"),r=[];for(const e of s.dOnly.get(t)||[])r.push([0,e]);const o=s.longest(s.dh,t);if(o){const e=t.slice(o.length).trim();for(const t of s.dh.get(o)){e||r.push([t,0]);for(const n of s.dm.get(e)||[])r.push([t,n])}}r.sort((t,e)=>t[0]-e[0]||t[1]-e[1]);t:for(const i of["r","n","j"])for(const[s,o]of r)if(dtKey(n.toTime(`${s}:${pad(o)}`,{timeStyle:"duration",ierab:i,tashkeel:"n"}))===t){e=`${s}:${pad(o)}`;break t}}return _.size>=2e4&&_.clear(),_.set(t,e),e}const et=/^\s+(بعد منتصف الليل|ليلا|فجرا|صباحا|ظهرا|عصرا|مساء|مساءا)(?![\u0621-\u064A])/,nt=/^\s*(للميلاد|ميلاديه|ميلادي|للهجره|هجريه|هجري|هـ|ه|م)(?![\u0621-\u064A])/,st="[\\u064B-\\u0652\\u0670\\u0640]*";function apRe(t){return t.split("").map(t=>(" "===t?"\\s+":"اأإآ".includes(t)?"[اأإآ]":"ة"===t?"[ةه]":"ى"===t||"ي"===t?"[ىي]":t)+(" "===t?"":st)).join("")}const rt=[["about",["قرابة","نحو","زهاء","حوالي","ما يقارب"]],["atLeast",["ما لا يقل عن"]],["atMost",["ما لا يزيد على","ما لا يزيد عن"]],["over",["ما يزيد على","ما يزيد عن","أكثر من","ما يربو على"]],["under",["أقل من","ما دون"]]].map(([t,e])=>[t,new RegExp("(?:^|[\\s،(«])("+e.map(apRe).join("|")+")\\s+$")]),ot={عشر:20,ثلاث:30,اربع:40,خمس:50,ست:60,سبع:70,ثمان:80,تسع:90},it=[["مئات",100n],["آلاف",1000n],["ألفا",1000n],["ألف",1000n],["ملايين",10n**6n],["مليونا",10n**6n],["مليون",10n**6n],["مليارات",10n**9n],["مليارا",10n**9n],["مليار",10n**9n]],lt="و"+st+"("+Object.keys(ot).map(apRe).join("|")+")(?:"+apRe("ون")+"|"+apRe("ين")+")",ct="(?:\\s+("+it.map(([t])=>apRe(t)).join("|")+"))?",ut=new RegExp("("+apRe("بضع")+"(?:[ةه]"+st+")?)(?:(\\s+"+apRe("عشر")+"(?:[ةه]"+st+")?)|\\s+("+lt+"))?"+ct,"g"),ft=new RegExp("("+apRe("و")+")?"+apRe("نيف")+"(?:ا"+st+")?\\s+("+lt+")"+ct,"g"),dt=new RegExp(apRe("و")+apRe("نيف")+"(?:ا"+st+")?(?![\\u0600-\\u06FF]*\\s+و"+st+"(?:"+Object.keys(ot).map(apRe).join("|")+"))","g");function digits(t,e){return e&&"on"===e.arabicNumbers?eng().utils.digits(t,"eastern").replace(/\./g,"٫"):t}function arqamWordsToNumbers(t,e={}){const n=options(e);let s="",r=0;for(const o of find(t,e)){if(null===o.value)continue;const e=C&&C.text===t&&C.ends.get(o.start);if(e&&void 0!==o.currency&&"code"!==n.currency){s+=t.slice(r,o.start)+digits(e.value,n)+t.slice(e.end,o.end),r=o.end;continue}if(void 0!==o.currency&&"code"!==n.currency){const e=O&&O.text===t?O.core.filter(t=>t.start>=o.start&&t.end<=o.end).map(t=>({...t,start:t.start-o.start,end:t.end-o.start})):findCore(t.slice(o.start,o.end),n,{scales:v[n.scale],zero:"on"===n.zero,ambiguous:"on"===n.ambiguous,joined:new Set});let i=t.slice(o.start,o.end),l="",a=0;const c=C&&C.text===t?C.ends:null;for(const t of e){if(t.start<a)continue;const e=c&&c.get(o.start+t.start);e&&e.end<=o.end?(l+=i.slice(a,t.start)+digits(e.value,n),a=e.end-o.start):null!==t.value&&(l+=i.slice(a,t.start)+digits(t.value.toString(),n),a=t.end)}s+=t.slice(r,o.start)+l+i.slice(a),r=o.end;continue}let i=o.value;o.currency&&"code"===n.currency&&(i=fracText(frac(...(()=>{const t=o.value.startsWith("-")?-1n:1n,e=o.value.replace("-","").match(/^(?:(\d+) )?(\d+)\/(\d+)$/);if(e)return[t*(BigInt(e[1]||0)*BigInt(e[3])+BigInt(e[2])),BigInt(e[3])];const[n,s=""]=o.value.replace("-","").split(".");return[t*BigInt(n+s),10n**BigInt(s.length)]})()),o.places)),s+=t.slice(r,o.start)+digits(i,n)+(o.percent?"%":"")+(o.currency&&"code"===n.currency?" "+o.currency:""),r=o.end}return s+t.slice(r)}arqamWordsToNumbers.find=find,arqamWordsToNumbers.value=(t,e={})=>{if("string"!=typeof t)return null;const n=(t=t.replace(/\u0640/g,"")).replace(/[(\[«{][^)\]»}]*[)\]»}]\s*$/,"").replace(/^\s*ف[\u0640\u064B-\u0652]*ق[\u0640\u064B-\u0652]*ط[\u0640\u064B-\u0652]*\s+/,"").replace(/\s+ل[\u0640\u064B-\u0652]*ا\s*غ[\u0640\u064B-\u0652]*ي[\u0640\u064B-\u0652]*ر[\u0640\u064B-\u0652]*\s*$/,""),one=t=>{const n=find(t,e),s=t.trim();return 1===n.length&&(void 0!==n[0].approxStart?n[0].approxStart:n[0].start)===t.length-t.trimStart().length&&n[0].end===t.trimEnd().length&&s?n[0].value:null};let s=null;if(/^\s*-?[0-9٠-٩]+(?:[.٫][0-9٠-٩]+)?\s*$/.test(n))return westDigits(n.trim());if(/[0-9٠-٩]/.test(n)){let t=0,r=0n,o=0,i=!1;const l=/^\s*س[\u064B-\u0652]*ا[\u064B-\u0652]*ل[\u064B-\u0652]*ب[\u064B-\u0652]*\s+/.exec(n);l&&(t=l[0].length,i=!0);const a=/^(?:[\s،,]+(?=و[\u064B-\u0652]?\s*\S)|\s*)(?:و[\u064B-\u0652]?\s*)?([0-9٠-٩]+(?:\s+(?!و)[\u0621-\u064A\u064B-\u0652]+)?|[\u0621-\u064A\u064B-\u0652]+)/,c=new RegExp(a.source.replace("(?:و[\\u064B-\\u0652]?\\s*)?",""));for(let s;s=(o?a:c).exec(n.slice(t));){const i=/^[0-9٠-٩]+$/.test(s[1])?null:find(s[1],e)[0],l=null===i?westDigits(s[1]):!i||i.currency||i.noun||i.end!==s[1].length?null:i.value;if(null===l||!/^\d+$/.test(l))break;if(i&&!/^[0-9٠-٩]/.test(s[1])&&!/^[12](000)+$/.test(l)&&(0!==o||!/^[12]$/.test(l)))break;const a=i&&/^1(000)+$/.test(l)&&/ا$/.test(s[1])&&/^\s+[\u0621-\u064A]/.test(n.slice(t+s[0].length))&&!/^\s+و/.test(n.slice(t+s[0].length));r+=BigInt(l)*(a?2n:1n),t+=s[0].length,o++}const u=n.slice(t).trim(),sign=t=>null!==t&&i&&/[1-9]/.test(t)?"-"+t:t;if(o>1&&!u)s=sign(r.toString());else if(o>1&&/^،/.test(u)&&!find(u,e).some(t=>t.currency)){const t=one(words().toWords(r.toString(),{currency:"",..."long"===e.scale?{scale:"long"}:{}})+u);null!==t&&(s=sign(t))}else if(o>1){const t=/^،/.test(u)?one("واحد"+u):one(u),e=/^،/.test(u)?"1":one(u.split("،")[0]);if(null!==t&&null!==e&&/^\d+$/.test(e)){const[n,o=""]=t.split(".");s=sign((r+BigInt(n)-BigInt(e)).toString()+(o?"."+o:""))}}}if(null===s&&/[0-9٠-٩]/.test(n)&&/[\u0621-\u064A]/.test(n)){const t=n.replace(/(^|[^0-9٠-٩.,٫٬])([0-9٠-٩]+)(?![0-9٠-٩.,٫٬])/g,(t,e,n)=>e+words().toWords(eng().utils.digits(n),{currency:""}));t!==n&&(s=one(t))}if(null===s&&(s=one(n)),null===s){const t=eng().removeTashkeel(n).trim(),e=/^(سالب\s+)?(جزء|جزءا|جزءان|جزأين|جزءين)(\s+من\s)/.exec(t);e&&(s=one(t.slice(0,e.index+(e[1]||"").length+e[2].length)+(/^جزء(ا)?$/.test(e[2])?" واحد":" اثنان")+t.slice(e.index+(e[1]||"").length+e[2].length)))}if(null===s){const t=eng().removeTashkeel(n).trim(),r=/^سالب\s+/.exec(t);if(r){const n=arqamWordsToNumbers.value(t.slice(r[0].length),e);null===n||/^-/.test(n)||(s=/[1-9]/.test(n)?"-"+n:n)}}return null===s&&void 0===e.zero&&/صفر/.test(eng().removeTashkeel(n))&&(e={...e,zero:"on"},s=one(n)),s},arqamWordsToNumbers.verify=function verify(t,e,n={}){if("string"!=typeof t)throw new TypeError("arqamWordsToNumbers.verify: the words must be a string");if(n&&"code"in n)throw new TypeError('arqamWordsToNumbers.verify: unknown option "code"; did you mean "currency"?');const{currency:s,...r}=n;if(void 0!==s&&("string"!=typeof s||!/^[A-Za-z][A-Za-z0-9]{2,7}$/.test(s)))throw new TypeError('arqamWordsToNumbers.verify: currency is a currency code such as "QAR"');const o="bigint"==typeof e?e.toString():String("number"==typeof e?e:e??""),i=westDigits(o.trim()).replace(/\s+/g,"");if(!/^-?\d+(\.\d+)?$/.test(i))throw new TypeError('arqamWordsToNumbers.verify: the number must be digits, such as "1250.50"');const l=decimalFrac(i.replace(/^-/,""));i.startsWith("-")&&(l.n=-l.n);const a=find(t.replace(/[(\[«][^)\]»]*[)\]»]\s*$/,""),{zero:"on",...r});let c=null;try{c=eng().toWords(o.trim(),s?{currency:s.toUpperCase()}:{})}catch(m){c=null}const parts=t=>{const e=t.n<0n,n=e?-t.n:t.n;return{w:(e?-1n:1n)*(n/t.d),r:frac((e?-1n:1n)*(n%t.d),t.d)}},res=(t,e,n,s,r)=>({ok:t,reason:e,read:n?n.value+(n.percent?"%":""):null,expected:fracText(l),currency:n&&n.currency||null,issue:r||e,difference:s?fracText(frac(s.n*l.d-l.n*s.d,s.d*l.d)):null,expectedWords:c});if(!a.length)return res(!1,"none",null);if(a.length>1)return res(!1,"several",a[0]);const u=a[0],[f,d=""]=u.value.replace("-","").split(".");if(/\//.test(u.value))return res(!1,"different",u,null,"both");const g=frac(BigInt(f+d)*(u.value.startsWith("-")?-1n:1n),10n**BigInt(d.length));return g.n*l.d!==l.n*g.d?res(!1,"different",u,g,(t=>{const e=parts(t),n=parts(l),s=e.w===n.w,r=e.r.n===n.r.n&&e.r.d===n.r.d;return s&&r?"match":s?"subunit":r?"whole":"both"})(g)):s&&void 0!==u.currency&&null!==u.currency&&u.currency!==s.toUpperCase()?res(!1,"currency",u,g,"currency"):res(!0,"match",u,g,"match")};const W2N_PLAIN=t=>norm(eng().removeTashkeel(String(t))).replace(/\s+/g," ").trim();let gt=null;function monthTable(){if(gt)return gt;gt=[];const t=eng(),pick=t=>(/من شهر (.+?) (?:الف|ألف)/.exec(W2N_PLAIN(t))||[])[1];for(let e=1;e<=12;e++){const n=String(e).padStart(2,"0");for(const r of["","gulf","levant","maghreb","morocco"]){const s=pick(t.toDate(`2026-${n}-15`,{months:r,era:"none",year:"none"}));s&&gt.push([s,e,"g"])}const s=pick(t.toDate(`1448-${n}-15 هـ`,{calendar:"h",era:"none",year:"none"}));s&&gt.push([s,e,"h"])}return gt=gt.filter((t,e,n)=>n.findIndex(e=>e[0]===t[0]&&e[2]===t[2])===e).sort((t,e)=>e[0].length-t[0].length),gt}const mt=[];for(const t of["h24","common","exact"].map(t=>({timeStyle:t})).concat(V))for(const e of["on","off"])for(const n of["on","off"])for(const s of["","nasb","jarr"])mt.push({...t,timeWord:e,timePeriod:n,ierab:s});const ht=new Map;let pt=null,wt=null;arqamWordsToNumbers.date=function readDate(t){if("string"!=typeof t)return null;let e=W2N_PLAIN(t).split("، الموافق")[0].replace(/[،.]$/,"").trim();const pad=(t,e)=>String(t).padStart(e,"0");let n=/^(\d{1,2}|غره) (.+?) (\d{1,4}) ?(م|ه|هـ|للميلاد|ميلاديه|ميلادي|للهجره|هجريه|هجري)?$/.exec(eng().utils.digits(e));const s=n&&(t=>{const e=W2N_PLAIN(t).replace(/\/.*$/,"").replace(/ (لعام|سنه|عام)$/,"").trim();return monthTable().find(t=>t[0]===e)||monthTable().find(t=>e.startsWith(t[0]+"/"))||null})(n[2]);if(s){const t="h"===s[2]||/^(ه|هـ|للهجره|هجريه|هجري)$/.test(n[4]||"");return`${pad(n[3],4)}-${pad(s[1],2)}-${pad("غره"===n[1]?1:n[1],2)}`+(t?" هـ":"")}const r=/\s+(للميلاد|ميلاديه|ميلادي|م|للهجره|هجريه|هجري|ه|هـ)$/.exec(e);let o=!1;if(r)o=/^(للهجره|هجريه|هجري|ه|هـ)$/.test(r[1]),e=e.slice(0,r.index);else{const t=/(\d)(م|هـ?)$/.exec(e);t&&(o=/ه/.test(t[2]),e=e.slice(0,t.index+1))}if(n=/^(?:(.+?) من شهر|(غره) شهر) (.+)$/.exec(e),!n)return null;const i=n[3],l=monthTable().find(t=>i===t[0]||i.startsWith(t[0]+" ")||i.startsWith(t[0]+"/"));if(!l)return null;let a=i.slice(l[0].length);if(a.startsWith("/")){const t=monthTable().find(t=>a.slice(1).startsWith(t[0]));a=t?a.slice(1+t[0].length):a.replace(/^\/\S+/,"")}a=a.trim().replace(/^(لعام|سنه|عام)\s+/,"");const c=n[2]?"1":arqamWordsToNumbers.value(n[1],{ordinals:"on"})||arqamWordsToNumbers.value(n[1]),u=/^\d+$/.test(a)?a:arqamWordsToNumbers.value(a);return!c||!u||!/^\d+$/.test(c)||!/^\d+$/.test(u)||+c<1||+c>30+("g"===l[2])?null:`${pad(u,4)}-${pad(l[1],2)}-${pad(c,2)}`+("h"===l[2]||o?" هـ":"")},arqamWordsToNumbers.time=function readTime(t){if("string"!=typeof t)return null;const e=W2N_PLAIN(t).replace(/[،.]$/,"");if(ht.has(e))return ht.get(e);let n=null;const s=e.replace(/^الساعه /,"");if(e.length<=120&&/^(ال|منتصف)/.test(s)){const t=eng(),r=e!==s,o=function timePeriods(){if(pt)return pt;const t=eng(),e=new Set;for(const n of["h24","common","exact"])for(const s of["","nasb","jarr"])for(let r=0;r<24;r++)for(const o of["00","01","30"]){const i=String(r).padStart(2,"0")+":"+o,l=W2N_PLAIN(t.toTime(i,{timeStyle:n,ierab:s})),a=W2N_PLAIN(t.toTime(i,{timeStyle:n,ierab:s,timePeriod:"off"}));l!==a&&l.startsWith(a+" ")&&e.add(l.slice(a.length+1))}return pt=[...e].sort((t,e)=>e.length-t.length)}().find(t=>s.endsWith(" "+t)||s===t),i=mt.filter(t=>!("on"!==t.timeWord&&r||"on"!==t.timePeriod&&o)),l=function timeParts(){if(wt)return wt;const{hours:t,mins:e}=timePhrases(W2N_PLAIN,["h24","common","exact",V],["","nasb","jarr"],{},(t,e)=>({m:t,shift:e}),(t,e)=>t.m===e.m&&t.shift===e.shift);return wt={hours:t,mins:e,hp:[...t.keys()].sort((t,e)=>e.length-t.length)}}(),a=o&&s!==o?s.slice(0,-(o.length+1)):s,c=new Set,u=l.hp.find(t=>a===t||a.startsWith(t+" "));if(u){const t=a.slice(u.length).trim();for(const e of l.hours.get(u))for(const{m:n,shift:s}of l.mins.get(t)||[])for(const t of[e+s,e+s+12])c.add((t%24+24)%24*60+n)}c.add(0),c.add(720);const f=[...c].sort((t,e)=>t-e).map(t=>String(Math.floor(t/60)).padStart(2,"0")+":"+String(t%60).padStart(2,"0"));t:for(const s of i)for(const r of f)if(W2N_PLAIN(t.toTime(r,s))===e){n=r;break t}}return ht.size>=5e3&&ht.clear(),ht.set(e,n),n},arqamWordsToNumbers.removeTashkeel=(t,e)=>eng().removeTashkeel(t,e),arqamWordsToNumbers.version="1.05";let vt=null;try{vt=eng()}catch(kt){vt=null}return vt&&!Object.isFrozen(vt)&&(vt.fromWords=(t,e)=>arqamWordsToNumbers.value(t,e),vt.findNumbers=(t,e)=>arqamWordsToNumbers.find(t,e),vt.verify=(t,e,n)=>arqamWordsToNumbers.verify(t,e,n),vt.fromDate=t=>arqamWordsToNumbers.date(t),vt.fromTime=t=>arqamWordsToNumbers.time(t)),arqamWordsToNumbers}();export default e;export const version=e.version;export const find=(t,n)=>e.find(t,n),value=(t,n)=>e.value(t,n),verify=(t,n,s)=>e.verify(t,n,s),wordsToNumbers=(t,n)=>e(t,n),removeTashkeel=(t,n)=>e.removeTashkeel(t,n),date=t=>e.date(t),time=t=>e.time(t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arqam",
3
- "version": "2.0.1",
4
- "arqamEngine": "1.90",
3
+ "version": "2.0.2",
4
+ "arqamEngine": "1.99",
5
5
  "description": "Arabic number-to-words (tafqeet): amounts in 188 currencies, numbers, ordinals, percentages, units of measure, Gregorian or Hijri dates, times and fractions, with full i'rab and tashkeel; an Intl-style formatter (arqamAR.NumberFormat). Also reads Arabic number words back into numbers, dialects included. No dependencies, no network. 2.x is a new library; the old one is arqam@1.",
6
6
  "keywords": [
7
7
  "arabic",
@@ -116,9 +116,8 @@
116
116
  },
117
117
  "scripts": {
118
118
  "build": "node tools/build_units.js && python3 tools/build_dist.py",
119
- "test": "node tests/arqamAR.test.js && node tests/dist.test.js && node tests/fuzz.test.js && node tests/property.test.js && node tests/w2n.test.js && node tests/explain.test.js && node tests/explain-audit.js && node tests/golden-book.test.js",
119
+ "test": "node tests/arqamAR.test.js && node tests/dist.test.js && node tests/fuzz.test.js && node tests/property.test.js && node tests/w2n.test.js && node tests/explain.test.js && node tests/golden-book.test.js && node tools/golden_fraction_check.js --check",
120
120
  "prepublishOnly": "npm test",
121
- "test:quick": "node tests/quick.js",
122
121
  "benchmark": "node tools/benchmark.js"
123
122
  }
124
123
  }