UNPKG

match-iz

Version:

A tiny pattern-matching library in the style of the TC39 proposal

8 lines (7 loc) 4.38 kB
/* * match-iz * v5.0.7 * https://github.com/shuckster/match-iz * License: MIT */ var q=Object.create;var y=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var z=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of R(e))!j.call(t,c)&&c!==n&&y(t,c,{get:()=>e[c],enumerable:!(r=E(e,c))||r.enumerable});return t};var C=(t,e,n)=>(n=t!=null?q($(t)):{},b(e||!t||!t.__esModule?y(n,"default",{value:t,enumerable:!0}):n,t)),G=t=>b(y({},"__esModule",{value:!0}),t);var Bt={};z(Bt,{inDay:()=>B,inDays:()=>Jt,inMonth:()=>P,inMonths:()=>Lt,inTheFuture:()=>D.inTheFuture,inTheNext:()=>D.inTheNext,inThePast:()=>D.inThePast,inYear:()=>_,inYears:()=>vt,isAM:()=>v,isAfter:()=>Ht,isAfternoon:()=>Ot,isApr:()=>pt,isAug:()=>yt,isBefore:()=>kt,isDay:()=>J,isDayOfWeek:()=>St,isDec:()=>Yt,isEvening:()=>Wt,isFeb:()=>ut,isFri:()=>et,isHour:()=>m,isJan:()=>Dt,isJul:()=>mt,isJun:()=>Mt,isLeapYear:()=>wt,isMar:()=>lt,isMay:()=>ht,isMinute:()=>Tt,isMon:()=>V,isMonth:()=>L,isMorning:()=>Nt,isNov:()=>Ft,isOct:()=>xt,isPM:()=>At,isSat:()=>nt,isSecond:()=>dt,isSep:()=>ft,isSun:()=>U,isThu:()=>tt,isTime:()=>D.isTime,isTue:()=>X,isWed:()=>Z,isWeekNumber:()=>bt,isYear:()=>h,nthFri:()=>ct,nthMon:()=>ot,nthSat:()=>gt,nthSun:()=>st,nthThu:()=>at,nthTue:()=>it,nthWed:()=>rt});module.exports=G(Bt);var Y=C(require("match-iz"),1),w=require("match-iz/dates/utc");var T=require("match-iz"),o=t=>e=>(0,T.isDate)(e)&&t(e),d=t=>(e,n)=>n===t,A=t=>(e,n,r)=>n===r.length+t;function*u(t,e){for(let n=t;n<=e;n++)yield n}var p=t=>e=>(...n)=>new Date(new Date(t)[`set${e}`](...n));var D=require("match-iz/dates/utc"),{match:O,against:a,when:s}=Y,{allOf:x,anyOf:S,every:W,inRange:l,gt:K,lt:Q,eq:f}=Y,{isArray:M,isDate:I,isFunction:g,isNumber:i}=Y,k=t=>p(t)("Month")(t.getMonth()+1,0).getDate(),N=t=>{let e=p(t)("Date")(t.getDate()+4-(t.getDay()||7)),n=p(t)("Month")(0,1);return Math.ceil(((+e-+n)/864e5+1)/7)},[U,V,X,Z,tt,et,nt]=[...u(0,6)].map(t=>o(e=>e.getDay()===t)),[st,ot,it,rt,at,ct,gt]=[...u(0,6)].map(t=>e=>o(n=>[...u(1,k(n))].map(p(n)("Date")).filter(r=>r.getDay()===t).filter(e<0?A(e):d(e-1)).filter(x(J(n.getDate()),L(n.getMonth()+1),h(n.getFullYear()))).map(r=>r.getDate()).includes(n.getDate()))),H=t=>o(e=>e.getMonth()===t),[Dt,ut,lt,pt,ht,Mt]=[...u(0,5)].map(H),[mt,yt,ft,xt,Ft,Yt]=[...u(6,11)].map(H),J=a(s(g)(t=>o(e=>t(e.getDate()))),s(i)(t=>t<0?o(e=>e.getDate()===k(e)+t+1):o(e=>e.getDate()===t))),L=a(s(g)(t=>o(e=>t(e.getMonth()+1))),s(i)(t=>o(e=>e.getMonth()===t-1))),h=a(s(g)(t=>o(e=>t(e.getFullYear()))),s(i)(t=>o(e=>e.getFullYear()===t))),wt=o(S(h(t=>t%400===0),x(h(t=>t%4===0),h(t=>t%100!==0)))),St=a(s(g)(t=>o(e=>t(e.getDay()))),s(i)(t=>o(e=>e.getDay()===t))),bt=a(s(g)(t=>o(e=>t(N(e)))),s(i)(t=>o(e=>N(e)===t))),m=a(s(g)(t=>o(e=>t(e.getHours()))),s(i)(t=>o(e=>e.getHours()===t))),Tt=a(s(g)(t=>o(e=>t(e.getMinutes()))),s(i)(t=>o(e=>e.getMinutes()===t))),dt=a(s(g)(t=>o(e=>t(e.getSeconds()))),s(i)(t=>o(e=>e.getSeconds()===t))),v=m(l(0,11)),At=m(l(12,23)),Nt=v,Ot=m(l(12,17)),Wt=m(l(18,23)),F=t=>O(t)(s(S(I,i))(e=>new Date(e)),s(f([i]))(([e])=>new Date(e,0,1)),s(f([i,i]))(([e,n])=>new Date(e,n-1,1)),s(x(M,{length:l(3,7)},W(i)))(([e,n,r,...c])=>new Date(e,n-1,r,...c))),It=t=>O(t)(s(S(I,i))(e=>new Date(e)),s(f([i]))(([e])=>new Date(e+1,0,0)),s(f([i,i]))(([e,n])=>new Date(e,n,0)),s(x(M,{length:l(3,7)},W(i)))(([e,n,r,...c])=>new Date(e,n-1,r+1,...c))),kt=t=>(0,w.isTime)(Q(F(t))),Ht=t=>(0,w.isTime)(K(It(t))),B=t=>{let e=F(t);return o(n=>n.getFullYear()===e.getFullYear()&&n.getMonth()===e.getMonth()&&n.getDate()===e.getDate())},P=t=>{let e=F(t);return o(n=>n.getFullYear()===e.getFullYear()&&n.getMonth()===e.getMonth())},_=t=>{let e=F(t);return o(n=>n.getFullYear()===e.getFullYear())},Jt=a(s(M)(t=>e=>t.some(n=>B(n)(e)))),Lt=a(s(M)(t=>e=>t.some(n=>P(n)(e)))),vt=a(s(M)(t=>e=>t.some(n=>_(n)(e))));0&&(module.exports={inDay,inDays,inMonth,inMonths,inTheFuture,inTheNext,inThePast,inYear,inYears,isAM,isAfter,isAfternoon,isApr,isAug,isBefore,isDay,isDayOfWeek,isDec,isEvening,isFeb,isFri,isHour,isJan,isJul,isJun,isLeapYear,isMar,isMay,isMinute,isMon,isMonth,isMorning,isNov,isOct,isPM,isSat,isSecond,isSep,isSun,isThu,isTime,isTue,isWed,isWeekNumber,isYear,nthFri,nthMon,nthSat,nthSun,nthThu,nthTue,nthWed});