New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@area17/parse-numeric-date

Package Overview
Dependencies
Maintainers
7
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@area17/parse-numeric-date - npm Package Compare versions

Comparing version

to
0.0.9

4

changelog.md

@@ -7,2 +7,6 @@ # Changelog

## 0.0.9
* Two year cut off is now dynamic and not fixed
* Returns null and a `console.log` on none valid entry
## 0.0.8

@@ -9,0 +13,0 @@ Refactored to make it easier to add ambiguous combos - removes a few bytes.

2

dist/parse-numeric-date.modern.js

@@ -1,2 +0,2 @@

let e=(new Intl.NumberFormat).resolvedOptions().locale;const t=(new Date).setHours(0,0,0,0);new Date(t).getFullYear();const n=()=>{const t=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:t.indexOf("13")},{name:"m",index:t.indexOf("12")},{name:"y",index:t.indexOf("2000")}].sort((e,t)=>e.index-t.index).map(e=>e.name).join("-")};let a=n();const Y=e=>2===e.length?parseInt(e)>60?`19${e}`:`20${e}`:e,r=(e,t,n)=>e.substring(t.indexOf(n),t.indexOf(n)+(t.match(new RegExp(n,"g"))||[]).length),l=(e,t)=>t.map(t=>((e,t)=>{const n=[{name:"d",index:t.indexOf("D")},{name:"m",index:t.indexOf("M")},{name:"y",index:t.indexOf("Y")}].sort((e,t)=>e.index-t.index);return{y:r(e,t,"Y"),m:r(e,t,"M"),d:r(e,t,"D"),order:n.map(e=>e.name).join("-")}})(e,t)),s=(e,t,n)=>{e=Y(e),e=parseInt(e,10),t=parseInt(t,10),n=(n=parseInt(n,10))>((e,t)=>new Date(t,e,0).getDate())(t=t>12?null:t,e)?null:n,t=t<10?`0${t}`:t,n=n<10?`0${n}`:n;let a=new Date(`${e}-${t}-${n}T00:00:00.000+00:00`);return a instanceof Date&&!isNaN(a)?a:null},D=(e,n)=>{const r=(e=e.map(e=>(e.d=s(e.y,e.m,e.d),e.y=parseInt(Y(e.y),10),e.diff=Math.abs(t-e.d),e.score=a===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e)).filter(e=>null!==e.d).sort((e,t)=>t.score-e.score)).length?e[0].score:0;return(e=e.filter(e=>e.score===r).sort((e,t)=>e.diff-t.diff).map(e=>e.d)).length?e[0]:null},d=(t,Y)=>{null!=Y&&Y.locale&&(e=Y.locale,a=n());let r=t,d=[],o=[...(t=t.replace(/[۰-۹]/g,e=>"۰۱۲۳۴۵۶۷۸۹".indexOf(e)).replace(/[٠-٩]/g,e=>"٠١٢٣٤٥٦٧٨٩".indexOf(e)).trim()).matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g)];return o.length>0?r.match(/[۰-۹]/g)?function(e,t,n){e=parseInt(e,10),t=parseInt(t,10),n=parseInt(n,10);const a=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"});let Y=new Date(Date.UTC(2e3,t,n));Y=new Date(Y.setUTCDate(Y.getUTCDate()+226867));const r=Y.getUTCFullYear()-2e3+e;Y=new Date((r<0?"-":"+")+("00000"+Math.abs(r)).slice(-6)+"-"+("0"+(Y.getUTCMonth()+1)).slice(-2)+"-"+("0"+Y.getUTCDate()).slice(-2));let[l,s,D]=[...a.format(Y).split("/")],d=0;for(Y=new Date(Y.setUTCDate(Y.getUTCDate()+Math.floor(365.25*e+30.44*t+n-(365.25*D.split(" ")[0]+30.44*l+1*s))-2));d<4;){if([l,s,D]=[...a.format(Y).split("/")],parseInt(s,10)===n&&parseInt(l,10)===t&&parseInt(D.split(" ")[0],10)===e)return Y;Y=new Date(Y.setUTCDate(Y.getUTCDate()+1)),d++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(o[0][1],o[0][2],o[0][3]):s(o[0][1],o[0][2],o[0][3]):(o=[...t.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g)],o.length>0?(d.push({y:o[0][3],m:o[0][2],d:o[0][1],order:"d-m-y"}),d.push({y:o[0][3],m:o[0][1],d:o[0][2],order:"m-d-y"}),D(d)):(o=[...t.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g)],o.length>0?(d.push({y:o[0][3],m:o[0][2],d:o[0][1],order:"d-m-y"}),d.push({y:o[0][3],m:o[0][1],d:o[0][2],order:"m-d-y"}),d.push({y:o[0][1],m:o[0][2],d:o[0][3],order:"y-m-d"}),D(d)):(8===t.length&&(d=l(t,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===t.length&&(d=l(t,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===t.length&&(d=l(t,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===t.length&&(d=l(t,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===t.length&&(d=l(t,["YYMD","DMYY","MDYY"])),D(d))))};export{d as default};
let e=(new Intl.NumberFormat).resolvedOptions().locale;const t=(new Date).setHours(0,0,0,0),n=new Date(t).getFullYear(),a=()=>{const t=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:t.indexOf("13")},{name:"m",index:t.indexOf("12")},{name:"y",index:t.indexOf("2000")}].sort((e,t)=>e.index-t.index).map(e=>e.name).join("-")};let r=a();const l=e=>{if(2===e.length){let t=50,a=1e3*Math.floor(n/1e3)+parseInt(e,10),r=Math.abs(a-(n+t));return a<n+t||r>100?a:a-100}return e},Y=(e,t,n)=>e.substring(t.indexOf(n),t.indexOf(n)+(t.match(new RegExp(n,"g"))||[]).length),s=(e,t)=>t.map(t=>((e,t)=>{const n=[{name:"d",index:t.indexOf("D")},{name:"m",index:t.indexOf("M")},{name:"y",index:t.indexOf("Y")}].sort((e,t)=>e.index-t.index);return{y:Y(e,t,"Y"),m:Y(e,t,"M"),d:Y(e,t,"D"),order:n.map(e=>e.name).join("-")}})(e,t)),D=(e,t,n)=>{e=l(e),e=parseInt(e,10),t=parseInt(t,10),n=(n=parseInt(n,10))>((e,t)=>new Date(t,e,0).getDate())(t=t>12?null:t,e)?null:n,t=t<10?`0${t}`:t,n=n<10?`0${n}`:n;let a=new Date(`${e}-${t}-${n}T00:00:00.000+00:00`);return a instanceof Date&&!isNaN(a)?a:null},o=(e,n)=>{const a=(e=e.map(e=>(e.d=D(e.y,e.m,e.d),e.y=parseInt(l(e.y),10),e.diff=Math.abs(t-e.d),e.score=r===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e)).filter(e=>null!==e.d).sort((e,t)=>t.score-e.score)).length?e[0].score:0;return(e=e.filter(e=>e.score===a).sort((e,t)=>e.diff-t.diff).map(e=>e.d)).length?e[0]:null},d=(t,n)=>{null!=n&&n.locale&&(e=n.locale,r=a());let l=t,Y=[],d=[...(t=t.replace(/[۰-۹]/g,e=>"۰۱۲۳۴۵۶۷۸۹".indexOf(e)).replace(/[٠-٩]/g,e=>"٠١٢٣٤٥٦٧٨٩".indexOf(e)).trim()).matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g)];return d.length>0?l.match(/[۰-۹]/g)?function(e,t,n){e=parseInt(e,10),t=parseInt(t,10),n=parseInt(n,10);const a=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"});let r=new Date(Date.UTC(2e3,t,n));r=new Date(r.setUTCDate(r.getUTCDate()+226867));const l=r.getUTCFullYear()-2e3+e;r=new Date((l<0?"-":"+")+("00000"+Math.abs(l)).slice(-6)+"-"+("0"+(r.getUTCMonth()+1)).slice(-2)+"-"+("0"+r.getUTCDate()).slice(-2));let[Y,s,D]=[...a.format(r).split("/")],o=0;for(r=new Date(r.setUTCDate(r.getUTCDate()+Math.floor(365.25*e+30.44*t+n-(365.25*D.split(" ")[0]+30.44*Y+1*s))-2));o<4;){if([Y,s,D]=[...a.format(r).split("/")],parseInt(s,10)===n&&parseInt(Y,10)===t&&parseInt(D.split(" ")[0],10)===e)return r;r=new Date(r.setUTCDate(r.getUTCDate()+1)),o++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(d[0][1],d[0][2],d[0][3]):D(d[0][1],d[0][2],d[0][3]):(d=[...t.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g)],d.length>0?(Y.push({y:d[0][3],m:d[0][2],d:d[0][1],order:"d-m-y"}),Y.push({y:d[0][3],m:d[0][1],d:d[0][2],order:"m-d-y"}),o(Y)):(d=[...t.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g)],d.length>0?(Y.push({y:d[0][3],m:d[0][2],d:d[0][1],order:"d-m-y"}),Y.push({y:d[0][3],m:d[0][1],d:d[0][2],order:"m-d-y"}),Y.push({y:d[0][1],m:d[0][2],d:d[0][3],order:"y-m-d"}),o(Y)):(d=[...t.matchAll(/[0-9]{1,}/g)],d.length>0?(8===t.length&&(Y=s(t,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===t.length&&(Y=s(t,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===t.length&&(Y=s(t,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===t.length&&(Y=s(t,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===t.length&&(Y=s(t,["YYMD","DMYY","MDYY"])),o(Y)):(console.log("parseNumericDate - unknown format:",t),null))))};export{d as default};
//# sourceMappingURL=parse-numeric-date.modern.js.map

@@ -1,2 +0,2 @@

var e=(new Intl.NumberFormat).resolvedOptions().locale,n=(new Date).setHours(0,0,0,0);new Date(n).getFullYear();var t=function(){var n=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:n.indexOf("13")},{name:"m",index:n.indexOf("12")},{name:"y",index:n.indexOf("2000")}].sort(function(e,n){return e.index-n.index}).map(function(e){return e.name}).join("-")},r=t(),a=function(e){return 2===e.length?parseInt(e)>60?"19"+e:"20"+e:e},Y=function(e,n,t){return e.substring(n.indexOf(t),n.indexOf(t)+(n.match(new RegExp(t,"g"))||[]).length)},i=function(e,n){return n.map(function(n){return function(e,n){var t=[{name:"d",index:n.indexOf("D")},{name:"m",index:n.indexOf("M")},{name:"y",index:n.indexOf("Y")}].sort(function(e,n){return e.index-n.index});return{y:Y(e,n,"Y"),m:Y(e,n,"M"),d:Y(e,n,"D"),order:t.map(function(e){return e.name}).join("-")}}(e,n)})},o=function(e,n,t){e=a(e),e=parseInt(e,10),n=parseInt(n,10),t=(t=parseInt(t,10))>function(e,n){return new Date(n,e,0).getDate()}(n=n>12?null:n,e)?null:t,n=n<10?"0"+n:n,t=t<10?"0"+t:t;var r=new Date(e+"-"+n+"-"+t+"T00:00:00.000+00:00");return r instanceof Date&&!isNaN(r)?r:null},u=function(e,t){var Y=(e=e.map(function(e){return e.d=o(e.y,e.m,e.d),e.y=parseInt(a(e.y),10),e.diff=Math.abs(n-e.d),e.score=r===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e}).filter(function(e){return null!==e.d}).sort(function(e,n){return n.score-e.score})).length?e[0].score:0;return(e=e.filter(function(e){return e.score===Y}).sort(function(e,n){return e.diff-n.diff}).map(function(e){return e.d})).length?e[0]:null},l=function(n,a){null!=a&&a.locale&&(e=a.locale,r=t());var Y=n;n=n.replace(/[۰-۹]/g,function(e){return"۰۱۲۳۴۵۶۷۸۹".indexOf(e)}).replace(/[٠-٩]/g,function(e){return"٠١٢٣٤٥٦٧٨٩".indexOf(e)}).trim();var l=[],D=[].concat(n.matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g));return D.length>0?Y.match(/[۰-۹]/g)?function(e,n,t){e=parseInt(e,10),n=parseInt(n,10),t=parseInt(t,10);var r=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"}),a=new Date(Date.UTC(2e3,n,t)),Y=(a=new Date(a.setUTCDate(a.getUTCDate()+226867))).getUTCFullYear()-2e3+e;a=new Date((Y<0?"-":"+")+("00000"+Math.abs(Y)).slice(-6)+"-"+("0"+(a.getUTCMonth()+1)).slice(-2)+"-"+("0"+a.getUTCDate()).slice(-2));var i=[].concat(r.format(a).split("/")),o=i[0],u=i[1],l=i[2],D=0;for(a=new Date(a.setUTCDate(a.getUTCDate()+Math.floor(365.25*e+30.44*n+t-(365.25*l.split(" ")[0]+30.44*o+1*u))-2));D<4;){var c=[].concat(r.format(a).split("/"));if(o=c[0],u=c[1],l=c[2],parseInt(u,10)===t&&parseInt(o,10)===n&&parseInt(l.split(" ")[0],10)===e)return a;a=new Date(a.setUTCDate(a.getUTCDate()+1)),D++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(D[0][1],D[0][2],D[0][3]):o(D[0][1],D[0][2],D[0][3]):(D=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g))).length>0?(l.push({y:D[0][3],m:D[0][2],d:D[0][1],order:"d-m-y"}),l.push({y:D[0][3],m:D[0][1],d:D[0][2],order:"m-d-y"}),u(l)):(D=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g))).length>0?(l.push({y:D[0][3],m:D[0][2],d:D[0][1],order:"d-m-y"}),l.push({y:D[0][3],m:D[0][1],d:D[0][2],order:"m-d-y"}),l.push({y:D[0][1],m:D[0][2],d:D[0][3],order:"y-m-d"}),u(l)):(8===n.length&&(l=i(n,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===n.length&&(l=i(n,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===n.length&&(l=i(n,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===n.length&&(l=i(n,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===n.length&&(l=i(n,["YYMD","DMYY","MDYY"])),u(l))};export{l as default};
var e=(new Intl.NumberFormat).resolvedOptions().locale,n=(new Date).setHours(0,0,0,0),t=new Date(n).getFullYear(),r=function(){var n=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:n.indexOf("13")},{name:"m",index:n.indexOf("12")},{name:"y",index:n.indexOf("2000")}].sort(function(e,n){return e.index-n.index}).map(function(e){return e.name}).join("-")},a=r(),o=function(e){if(2===e.length){var n=1e3*Math.floor(t/1e3)+parseInt(e,10),r=Math.abs(n-(t+50));return n<t+50||r>100?n:n-100}return e},Y=function(e,n,t){return e.substring(n.indexOf(t),n.indexOf(t)+(n.match(new RegExp(t,"g"))||[]).length)},i=function(e,n){return n.map(function(n){return function(e,n){var t=[{name:"d",index:n.indexOf("D")},{name:"m",index:n.indexOf("M")},{name:"y",index:n.indexOf("Y")}].sort(function(e,n){return e.index-n.index});return{y:Y(e,n,"Y"),m:Y(e,n,"M"),d:Y(e,n,"D"),order:t.map(function(e){return e.name}).join("-")}}(e,n)})},l=function(e,n,t){e=o(e),e=parseInt(e,10),n=parseInt(n,10),t=(t=parseInt(t,10))>function(e,n){return new Date(n,e,0).getDate()}(n=n>12?null:n,e)?null:t,n=n<10?"0"+n:n,t=t<10?"0"+t:t;var r=new Date(e+"-"+n+"-"+t+"T00:00:00.000+00:00");return r instanceof Date&&!isNaN(r)?r:null},u=function(e,t){var r=(e=e.map(function(e){return e.d=l(e.y,e.m,e.d),e.y=parseInt(o(e.y),10),e.diff=Math.abs(n-e.d),e.score=a===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e}).filter(function(e){return null!==e.d}).sort(function(e,n){return n.score-e.score})).length?e[0].score:0;return(e=e.filter(function(e){return e.score===r}).sort(function(e,n){return e.diff-n.diff}).map(function(e){return e.d})).length?e[0]:null},c=function(n,t){null!=t&&t.locale&&(e=t.locale,a=r());var o=n;n=n.replace(/[۰-۹]/g,function(e){return"۰۱۲۳۴۵۶۷۸۹".indexOf(e)}).replace(/[٠-٩]/g,function(e){return"٠١٢٣٤٥٦٧٨٩".indexOf(e)}).trim();var Y=[],c=[].concat(n.matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g));return c.length>0?o.match(/[۰-۹]/g)?function(e,n,t){e=parseInt(e,10),n=parseInt(n,10),t=parseInt(t,10);var r=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"}),a=new Date(Date.UTC(2e3,n,t)),o=(a=new Date(a.setUTCDate(a.getUTCDate()+226867))).getUTCFullYear()-2e3+e;a=new Date((o<0?"-":"+")+("00000"+Math.abs(o)).slice(-6)+"-"+("0"+(a.getUTCMonth()+1)).slice(-2)+"-"+("0"+a.getUTCDate()).slice(-2));var Y=[].concat(r.format(a).split("/")),i=Y[0],l=Y[1],u=Y[2],c=0;for(a=new Date(a.setUTCDate(a.getUTCDate()+Math.floor(365.25*e+30.44*n+t-(365.25*u.split(" ")[0]+30.44*i+1*l))-2));c<4;){var D=[].concat(r.format(a).split("/"));if(i=D[0],l=D[1],u=D[2],parseInt(l,10)===t&&parseInt(i,10)===n&&parseInt(u.split(" ")[0],10)===e)return a;a=new Date(a.setUTCDate(a.getUTCDate()+1)),c++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(c[0][1],c[0][2],c[0][3]):l(c[0][1],c[0][2],c[0][3]):(c=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g))).length>0?(Y.push({y:c[0][3],m:c[0][2],d:c[0][1],order:"d-m-y"}),Y.push({y:c[0][3],m:c[0][1],d:c[0][2],order:"m-d-y"}),u(Y)):(c=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g))).length>0?(Y.push({y:c[0][3],m:c[0][2],d:c[0][1],order:"d-m-y"}),Y.push({y:c[0][3],m:c[0][1],d:c[0][2],order:"m-d-y"}),Y.push({y:c[0][1],m:c[0][2],d:c[0][3],order:"y-m-d"}),u(Y)):(c=[].concat(n.matchAll(/[0-9]{1,}/g))).length>0?(8===n.length&&(Y=i(n,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===n.length&&(Y=i(n,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===n.length&&(Y=i(n,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===n.length&&(Y=i(n,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===n.length&&(Y=i(n,["YYMD","DMYY","MDYY"])),u(Y)):(console.log("parseNumericDate - unknown format:",n),null)};export{c as default};
//# sourceMappingURL=parse-numeric-date.module.js.map

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e||self).parseNumericDate=n()}(this,function(){var e=(new Intl.NumberFormat).resolvedOptions().locale,n=(new Date).setHours(0,0,0,0);new Date(n).getFullYear();var t=function(){var n=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:n.indexOf("13")},{name:"m",index:n.indexOf("12")},{name:"y",index:n.indexOf("2000")}].sort(function(e,n){return e.index-n.index}).map(function(e){return e.name}).join("-")},r=t(),a=function(e){return 2===e.length?parseInt(e)>60?"19"+e:"20"+e:e},o=function(e,n,t){return e.substring(n.indexOf(t),n.indexOf(t)+(n.match(new RegExp(t,"g"))||[]).length)},i=function(e,n){return n.map(function(n){return function(e,n){var t=[{name:"d",index:n.indexOf("D")},{name:"m",index:n.indexOf("M")},{name:"y",index:n.indexOf("Y")}].sort(function(e,n){return e.index-n.index});return{y:o(e,n,"Y"),m:o(e,n,"M"),d:o(e,n,"D"),order:t.map(function(e){return e.name}).join("-")}}(e,n)})},Y=function(e,n,t){e=a(e),e=parseInt(e,10),n=parseInt(n,10),t=(t=parseInt(t,10))>function(e,n){return new Date(n,e,0).getDate()}(n=n>12?null:n,e)?null:t,n=n<10?"0"+n:n,t=t<10?"0"+t:t;var r=new Date(e+"-"+n+"-"+t+"T00:00:00.000+00:00");return r instanceof Date&&!isNaN(r)?r:null},u=function(e,t){var o=(e=e.map(function(e){return e.d=Y(e.y,e.m,e.d),e.y=parseInt(a(e.y),10),e.diff=Math.abs(n-e.d),e.score=r===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e}).filter(function(e){return null!==e.d}).sort(function(e,n){return n.score-e.score})).length?e[0].score:0;return(e=e.filter(function(e){return e.score===o}).sort(function(e,n){return e.diff-n.diff}).map(function(e){return e.d})).length?e[0]:null};return function(n,a){null!=a&&a.locale&&(e=a.locale,r=t());var o=n;n=n.replace(/[۰-۹]/g,function(e){return"۰۱۲۳۴۵۶۷۸۹".indexOf(e)}).replace(/[٠-٩]/g,function(e){return"٠١٢٣٤٥٦٧٨٩".indexOf(e)}).trim();var l=[],d=[].concat(n.matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g));return d.length>0?o.match(/[۰-۹]/g)?function(e,n,t){e=parseInt(e,10),n=parseInt(n,10),t=parseInt(t,10);var r=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"}),a=new Date(Date.UTC(2e3,n,t)),o=(a=new Date(a.setUTCDate(a.getUTCDate()+226867))).getUTCFullYear()-2e3+e;a=new Date((o<0?"-":"+")+("00000"+Math.abs(o)).slice(-6)+"-"+("0"+(a.getUTCMonth()+1)).slice(-2)+"-"+("0"+a.getUTCDate()).slice(-2));var i=[].concat(r.format(a).split("/")),Y=i[0],u=i[1],l=i[2],d=0;for(a=new Date(a.setUTCDate(a.getUTCDate()+Math.floor(365.25*e+30.44*n+t-(365.25*l.split(" ")[0]+30.44*Y+1*u))-2));d<4;){var f=[].concat(r.format(a).split("/"));if(Y=f[0],u=f[1],l=f[2],parseInt(u,10)===t&&parseInt(Y,10)===n&&parseInt(l.split(" ")[0],10)===e)return a;a=new Date(a.setUTCDate(a.getUTCDate()+1)),d++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(d[0][1],d[0][2],d[0][3]):Y(d[0][1],d[0][2],d[0][3]):(d=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g))).length>0?(l.push({y:d[0][3],m:d[0][2],d:d[0][1],order:"d-m-y"}),l.push({y:d[0][3],m:d[0][1],d:d[0][2],order:"m-d-y"}),u(l)):(d=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g))).length>0?(l.push({y:d[0][3],m:d[0][2],d:d[0][1],order:"d-m-y"}),l.push({y:d[0][3],m:d[0][1],d:d[0][2],order:"m-d-y"}),l.push({y:d[0][1],m:d[0][2],d:d[0][3],order:"y-m-d"}),u(l)):(8===n.length&&(l=i(n,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===n.length&&(l=i(n,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===n.length&&(l=i(n,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===n.length&&(l=i(n,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===n.length&&(l=i(n,["YYMD","DMYY","MDYY"])),u(l))}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e||self).parseNumericDate=n()}(this,function(){var e=(new Intl.NumberFormat).resolvedOptions().locale,n=(new Date).setHours(0,0,0,0),t=new Date(n).getFullYear(),r=function(){var n=new Date(2e3,11,13).toLocaleDateString(e);return[{name:"d",index:n.indexOf("13")},{name:"m",index:n.indexOf("12")},{name:"y",index:n.indexOf("2000")}].sort(function(e,n){return e.index-n.index}).map(function(e){return e.name}).join("-")},a=r(),o=function(e){if(2===e.length){var n=1e3*Math.floor(t/1e3)+parseInt(e,10),r=Math.abs(n-(t+50));return n<t+50||r>100?n:n-100}return e},i=function(e,n,t){return e.substring(n.indexOf(t),n.indexOf(t)+(n.match(new RegExp(t,"g"))||[]).length)},l=function(e,n){return n.map(function(n){return function(e,n){var t=[{name:"d",index:n.indexOf("D")},{name:"m",index:n.indexOf("M")},{name:"y",index:n.indexOf("Y")}].sort(function(e,n){return e.index-n.index});return{y:i(e,n,"Y"),m:i(e,n,"M"),d:i(e,n,"D"),order:t.map(function(e){return e.name}).join("-")}}(e,n)})},u=function(e,n,t){e=o(e),e=parseInt(e,10),n=parseInt(n,10),t=(t=parseInt(t,10))>function(e,n){return new Date(n,e,0).getDate()}(n=n>12?null:n,e)?null:t,n=n<10?"0"+n:n,t=t<10?"0"+t:t;var r=new Date(e+"-"+n+"-"+t+"T00:00:00.000+00:00");return r instanceof Date&&!isNaN(r)?r:null},Y=function(e,t){var r=(e=e.map(function(e){return e.d=u(e.y,e.m,e.d),e.y=parseInt(o(e.y),10),e.diff=Math.abs(n-e.d),e.score=a===e.order?2:1,e.diff>315576e7&&e.score--,e.diff<631152e5&&e.score++,e}).filter(function(e){return null!==e.d}).sort(function(e,n){return n.score-e.score})).length?e[0].score:0;return(e=e.filter(function(e){return e.score===r}).sort(function(e,n){return e.diff-n.diff}).map(function(e){return e.d})).length?e[0]:null};return function(n,t){null!=t&&t.locale&&(e=t.locale,a=r());var o=n;n=n.replace(/[۰-۹]/g,function(e){return"۰۱۲۳۴۵۶۷۸۹".indexOf(e)}).replace(/[٠-٩]/g,function(e){return"٠١٢٣٤٥٦٧٨٩".indexOf(e)}).trim();var i=[],c=[].concat(n.matchAll(/([0-9]{4})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g));return c.length>0?o.match(/[۰-۹]/g)?function(e,n,t){e=parseInt(e,10),n=parseInt(n,10),t=parseInt(t,10);var r=new Intl.DateTimeFormat("en-u-ca-persian",{dateStyle:"short",timeZone:"UTC"}),a=new Date(Date.UTC(2e3,n,t)),o=(a=new Date(a.setUTCDate(a.getUTCDate()+226867))).getUTCFullYear()-2e3+e;a=new Date((o<0?"-":"+")+("00000"+Math.abs(o)).slice(-6)+"-"+("0"+(a.getUTCMonth()+1)).slice(-2)+"-"+("0"+a.getUTCDate()).slice(-2));var i=[].concat(r.format(a).split("/")),l=i[0],u=i[1],Y=i[2],c=0;for(a=new Date(a.setUTCDate(a.getUTCDate()+Math.floor(365.25*e+30.44*n+t-(365.25*Y.split(" ")[0]+30.44*l+1*u))-2));c<4;){var f=[].concat(r.format(a).split("/"));if(l=f[0],u=f[1],Y=f[2],parseInt(u,10)===t&&parseInt(l,10)===n&&parseInt(Y.split(" ")[0],10)===e)return a;a=new Date(a.setUTCDate(a.getUTCDate()+1)),c++}throw console.log("Invalid Persian date"),new Error("Invalid Persian date")}(c[0][1],c[0][2],c[0][3]):u(c[0][1],c[0][2],c[0][3]):(c=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{2})[^0-9]{1,}([0-9]{4})/g))).length>0?(i.push({y:c[0][3],m:c[0][2],d:c[0][1],order:"d-m-y"}),i.push({y:c[0][3],m:c[0][1],d:c[0][2],order:"m-d-y"}),Y(i)):(c=[].concat(n.matchAll(/([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})[^0-9]{1,}([0-9]{1,2})/g))).length>0?(i.push({y:c[0][3],m:c[0][2],d:c[0][1],order:"d-m-y"}),i.push({y:c[0][3],m:c[0][1],d:c[0][2],order:"m-d-y"}),i.push({y:c[0][1],m:c[0][2],d:c[0][3],order:"y-m-d"}),Y(i)):(c=[].concat(n.matchAll(/[0-9]{1,}/g))).length>0?(8===n.length&&(i=l(n,["YYYYMMDD","DDMMYYYY","MMDDYYYY"])),7===n.length&&(i=l(n,["YYYYMMD","YYYYMDD","DDMYYYY","MDDYYYY","DMMYYYY","MMDYYYY"])),6===n.length&&(i=l(n,["YYMMDD","DDMMYY","MMDDYY","YYYYMD","DMYYYY","MDYYYY"])),5===n.length&&(i=l(n,["YYMMD","YYMDD","DDMYY","MDDYY","DMMYY","MMDYY"])),4===n.length&&(i=l(n,["YYMD","DMYY","MDYY"])),Y(i)):(console.log("parseNumericDate - unknown format:",n),null)}});
//# sourceMappingURL=parse-numeric-date.umd.js.map
{
"name": "@area17/parse-numeric-date",
"version": "0.0.8",
"version": "0.0.9",
"description": "Parse numeric based date inputs",

@@ -5,0 +5,0 @@ "type": "module",

let locale = new Intl.NumberFormat().resolvedOptions().locale;
const twoDigitCutoffYear = 60;
const today = new Date().setHours(0, 0, 0, 0);

@@ -30,3 +29,7 @@ const thisYear = new Date(today).getFullYear();

if (y.length === 2) {
return parseInt(y) > twoDigitCutoffYear ? `19${y}` : `20${y}`;
let twoDigitCutoffYear = 50;
let century = Math.floor(thisYear / 1000) * 1000;
let year = century + parseInt(y, 10);
let diff = Math.abs(year - (thisYear + twoDigitCutoffYear));
return (year < thisYear + twoDigitCutoffYear) || diff > 100 ? year : year - 100;
}

@@ -295,34 +298,44 @@ return y;

// could be YYYYMMDD, DDMMYYYY, MMDDYYYY
if (dateStr.length === 8) {
dates = splitDates(dateStr, ['YYYYMMDD', 'DDMMYYYY', 'MMDDYYYY']);
}
matches = [
...dateStr.matchAll(
/[0-9]{1,}/g
)
];
if (matches.length > 0) {
// could be YYYYMMDD, DDMMYYYY, MMDDYYYY
if (dateStr.length === 8) {
dates = splitDates(dateStr, ['YYYYMMDD', 'DDMMYYYY', 'MMDDYYYY']);
}
// could be YYYYMMD, YYYYMDD,
// or DDMYYYY, MDDYYYY, DMMYYYY, MMDYYYY
if (dateStr.length === 7) {
dates = splitDates(dateStr, ['YYYYMMD', 'YYYYMDD', 'DDMYYYY', 'MDDYYYY', 'DMMYYYY', 'MMDYYYY']);
}
// could be YYYYMMD, YYYYMDD,
// or DDMYYYY, MDDYYYY, DMMYYYY, MMDYYYY
if (dateStr.length === 7) {
dates = splitDates(dateStr, ['YYYYMMD', 'YYYYMDD', 'DDMYYYY', 'MDDYYYY', 'DMMYYYY', 'MMDYYYY']);
}
// or could be YYMMDD, DDMMYY, MMDDYY
// or worse, could be YYYYMD, DMYYYY, MDYYYY
if (dateStr.length === 6) {
dates = splitDates(dateStr, ['YYMMDD', 'DDMMYY', 'MMDDYY', 'YYYYMD', 'DMYYYY', 'MDYYYY']);
}
// or could be YYMMDD, DDMMYY, MMDDYY
// or worse, could be YYYYMD, DMYYYY, MDYYYY
if (dateStr.length === 6) {
dates = splitDates(dateStr, ['YYMMDD', 'DDMMYY', 'MMDDYY', 'YYYYMD', 'DMYYYY', 'MDYYYY']);
}
// could be YYMMD, YYMDD,
// or DDMYY, MDDYY, DMMYY, MMDYY
if (dateStr.length === 5) {
dates = splitDates(dateStr, ['YYMMD', 'YYMDD', 'DDMYY', 'MDDYY', 'DMMYY', 'MMDYY']);
}
// could be YYMMD, YYMDD,
// or DDMYY, MDDYY, DMMYY, MMDYY
if (dateStr.length === 5) {
dates = splitDates(dateStr, ['YYMMD', 'YYMDD', 'DDMYY', 'MDDYY', 'DMMYY', 'MMDYY']);
}
// could be YYMD, DMYY, MDYY
if (dateStr.length === 4) {
dates = splitDates(dateStr, ['YYMD', 'DMYY', 'MDYY']);
}
// could be YYMD, DMYY, MDYY
if (dateStr.length === 4) {
dates = splitDates(dateStr, ['YYMD', 'DMYY', 'MDYY']);
}
//
return getMostProbableDate(dates, dateStr);
//
return getMostProbableDate(dates, dateStr);
}
console.log('parseNumericDate - unknown format:', dateStr);
return null;
};
export default parseNumericDate;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet