calendar-dates
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
"use strict";var monthTypes={PREVIOUS:"previous",CURRENT:"current",NEXT:"next"},pad=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0";return t<10?e+t:t},iso8601=function(t){return t.getFullYear()+"-"+pad(t.getUTCMonth()+1)+"-"+pad(t.getDate())},getLastDate=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},getFirstDayIndex=function(t){var e=new Date(t.getFullYear(),t.getMonth(),1).toDateString().substring(0,3);return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(e)},getDatesWithMetadata=function(t){return new Promise(function(e){var n=[],a=getPreviousDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.PREVIOUS}}),r=getCurrentDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.CURRENT}});n=n.concat(a).concat(r);var u=getNextDates(t,n.length).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.NEXT}});e(n.concat(u))})},getCurrentDates=function(t){var e=getLastDate(t);return Array(e).fill().map(function(e,n){var a=n+1;return t.setDate(a),{date:a,iso:iso8601(t)}})},getPreviousDates=function(t){var e=t.getMonth(),n=t.getFullYear(),a=Math.min(e-1,11),r=new Date(n,a),u=getLastDate(r),o=u-getFirstDayIndex(t)+1;return Array(u-o+1).fill().map(function(t,e){var n=o+e;return r.setDate(n),{date:n,iso:iso8601(r)}})},getNextDates=function(t,e){var n=42-e,a=t.getMonth()+1===12?0:t.getMonth()+1,r=0===a?t.getFullYear()+1:t.getFullYear(),u=new Date(r,a);return Array(n).fill().map(function(t,e){var n=e+1;return u.setDate(n),{date:n,iso:iso8601(u)}})},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}(),CalendarDates=function(){function t(){classCallCheck(this,t)}return createClass(t,[{key:"getDates",value:function(t){return new Promise(function(e){return e(getDatesWithMetadata(t).then(function(t){return t.map(function(t){return t})}))})}},{key:"getMatrix",value:function(t){return new Promise(function(e){e(getDatesWithMetadata(t).then(function(t){return t.reduce(function(t,e,n){return(n%7==0?t.push([e]):t[t.length-1].push(e))&&t},[])}))})}}]),t}();module.exports=CalendarDates; | ||
"use strict";var monthTypes={PREVIOUS:"previous",CURRENT:"current",NEXT:"next"},pad=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0";return t<10?e+t:t},iso8601=function(t){return t.getFullYear()+"-"+pad(t.getUTCMonth()+1)+"-"+pad(t.getDate())},getLastDate=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},getFirstDayIndex=function(t){var e=new Date(t.getFullYear(),t.getMonth(),1).toDateString().substring(0,3);return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(e)},getDatesWithMetadata=function(t){return new Promise(function(e){var n=[],a=getPreviousDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.PREVIOUS}}),r=getCurrentDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.CURRENT}});n=n.concat(a).concat(r);var u=getNextDates(t,n.length).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.NEXT}});e(n.concat(u))})},dateMapper=function(t){return function(e){return Array(t).fill().map(e)}},getCurrentDates=function(t){var e=getLastDate(t);return dateMapper(e)(function(e,n){var a=n+1;return t.setDate(a),{date:a,iso:iso8601(t)}})},getPreviousDates=function(t){var e=t.getMonth(),n=t.getFullYear(),a=Math.min(e-1,11),r=new Date(n,a),u=getLastDate(r),o=u-getFirstDayIndex(t)+1;return dateMapper(u-o+1)(function(t,e){var n=o+e;return r.setDate(n),{date:n,iso:iso8601(r)}})},getNextDates=function(t,e){var n=42-e,a=t.getMonth()+1===12?0:t.getMonth()+1,r=0===a?t.getFullYear()+1:t.getFullYear(),u=new Date(r,a);return dateMapper(n)(function(t,e){var n=e+1;return u.setDate(n),{date:n,iso:iso8601(u)}})},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}(),CalendarDates=function(){function t(){classCallCheck(this,t)}return createClass(t,[{key:"getDates",value:function(t){return new Promise(function(e){return e(getDatesWithMetadata(t).then(function(t){return t.map(function(t){return t})}))})}},{key:"getMatrix",value:function(t){return new Promise(function(e){e(getDatesWithMetadata(t).then(function(t){return t.reduce(function(t,e,n){return(n%7==0?t.push([e]):t[t.length-1].push(e))&&t},[])}))})}}]),t}();module.exports=CalendarDates; |
@@ -1,1 +0,1 @@ | ||
var monthTypes={PREVIOUS:"previous",CURRENT:"current",NEXT:"next"},pad=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0";return t<10?e+t:t},iso8601=function(t){return t.getFullYear()+"-"+pad(t.getUTCMonth()+1)+"-"+pad(t.getDate())},getLastDate=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},getFirstDayIndex=function(t){var e=new Date(t.getFullYear(),t.getMonth(),1).toDateString().substring(0,3);return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(e)},getDatesWithMetadata=function(t){return new Promise(function(e){var n=[],a=getPreviousDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.PREVIOUS}}),r=getCurrentDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.CURRENT}});n=n.concat(a).concat(r);var u=getNextDates(t,n.length).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.NEXT}});e(n.concat(u))})},getCurrentDates=function(t){var e=getLastDate(t);return Array(e).fill().map(function(e,n){var a=n+1;return t.setDate(a),{date:a,iso:iso8601(t)}})},getPreviousDates=function(t){var e=t.getMonth(),n=t.getFullYear(),a=Math.min(e-1,11),r=new Date(n,a),u=getLastDate(r),o=u-getFirstDayIndex(t)+1;return Array(u-o+1).fill().map(function(t,e){var n=o+e;return r.setDate(n),{date:n,iso:iso8601(r)}})},getNextDates=function(t,e){var n=42-e,a=t.getMonth()+1===12?0:t.getMonth()+1,r=0===a?t.getFullYear()+1:t.getFullYear(),u=new Date(r,a);return Array(n).fill().map(function(t,e){var n=e+1;return u.setDate(n),{date:n,iso:iso8601(u)}})},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}(),CalendarDates=function(){function t(){classCallCheck(this,t)}return createClass(t,[{key:"getDates",value:function(t){return new Promise(function(e){return e(getDatesWithMetadata(t).then(function(t){return t.map(function(t){return t})}))})}},{key:"getMatrix",value:function(t){return new Promise(function(e){e(getDatesWithMetadata(t).then(function(t){return t.reduce(function(t,e,n){return(n%7==0?t.push([e]):t[t.length-1].push(e))&&t},[])}))})}}]),t}();export default CalendarDates; | ||
var monthTypes={PREVIOUS:"previous",CURRENT:"current",NEXT:"next"},pad=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"0";return t<10?e+t:t},iso8601=function(t){return t.getFullYear()+"-"+pad(t.getUTCMonth()+1)+"-"+pad(t.getDate())},getLastDate=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},getFirstDayIndex=function(t){var e=new Date(t.getFullYear(),t.getMonth(),1).toDateString().substring(0,3);return["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].indexOf(e)},getDatesWithMetadata=function(t){return new Promise(function(e){var n=[],a=getPreviousDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.PREVIOUS}}),r=getCurrentDates(t).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.CURRENT}});n=n.concat(a).concat(r);var u=getNextDates(t,n.length).map(function(t){return{date:t.date,iso:t.iso,type:monthTypes.NEXT}});e(n.concat(u))})},dateMapper=function(t){return function(e){return Array(t).fill().map(e)}},getCurrentDates=function(t){var e=getLastDate(t);return dateMapper(e)(function(e,n){var a=n+1;return t.setDate(a),{date:a,iso:iso8601(t)}})},getPreviousDates=function(t){var e=t.getMonth(),n=t.getFullYear(),a=Math.min(e-1,11),r=new Date(n,a),u=getLastDate(r),o=u-getFirstDayIndex(t)+1;return dateMapper(u-o+1)(function(t,e){var n=o+e;return r.setDate(n),{date:n,iso:iso8601(r)}})},getNextDates=function(t,e){var n=42-e,a=t.getMonth()+1===12?0:t.getMonth()+1,r=0===a?t.getFullYear()+1:t.getFullYear(),u=new Date(r,a);return dateMapper(n)(function(t,e){var n=e+1;return u.setDate(n),{date:n,iso:iso8601(u)}})},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,n,a){return n&&t(e.prototype,n),a&&t(e,a),e}}(),CalendarDates=function(){function t(){classCallCheck(this,t)}return createClass(t,[{key:"getDates",value:function(t){return new Promise(function(e){return e(getDatesWithMetadata(t).then(function(t){return t.map(function(t){return t})}))})}},{key:"getMatrix",value:function(t){return new Promise(function(e){e(getDatesWithMetadata(t).then(function(t){return t.reduce(function(t,e,n){return(n%7==0?t.push([e]):t[t.length-1].push(e))&&t},[])}))})}}]),t}();export default CalendarDates; |
{ | ||
"name": "calendar-dates", | ||
"version": "2.5.5", | ||
"version": "2.5.6", | ||
"license": "MIT", | ||
@@ -11,4 +11,15 @@ "author": "Sung Kim", | ||
"build": "rollup -c", | ||
"test": "yarn build && jest" | ||
"bundlesize": "bundlesize", | ||
"test": "yarn build && bundlesize && jest" | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "dist/calendardates.cjs.js", | ||
"maxSize": "1 kB" | ||
}, | ||
{ | ||
"path": "dist/calendardates.esm.js", | ||
"maxSize": "1 kB" | ||
} | ||
], | ||
"dependencies": {}, | ||
@@ -23,2 +34,3 @@ "devDependencies": { | ||
"babel-preset-env": "1.6.1", | ||
"bundlesize": "^0.17.1", | ||
"eslint": "5.12.1", | ||
@@ -25,0 +37,0 @@ "eslint-plugin-react": "7.9.1", |
@@ -52,14 +52,17 @@ const monthTypes = { | ||
const dateMapper = dateCount => mapper => | ||
Array(dateCount) | ||
.fill() | ||
.map(mapper); | ||
const getCurrentDates = currentDate => { | ||
const lastDate = getLastDate(currentDate); | ||
return Array(lastDate) | ||
.fill() | ||
.map((_, i) => { | ||
const date = i + 1; | ||
currentDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(currentDate) | ||
}; | ||
}); | ||
return dateMapper(lastDate)((_, i) => { | ||
const date = i + 1; | ||
currentDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(currentDate) | ||
}; | ||
}); | ||
}; | ||
@@ -78,12 +81,10 @@ | ||
return Array(length) | ||
.fill() | ||
.map((_, i) => { | ||
const date = start + i; | ||
prevDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(prevDate) | ||
}; | ||
}); | ||
return dateMapper(length)((_, i) => { | ||
const date = start + i; | ||
prevDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(prevDate) | ||
}; | ||
}); | ||
}; | ||
@@ -102,12 +103,10 @@ | ||
return Array(length) | ||
.fill() | ||
.map((_, i) => { | ||
const date = i + 1; | ||
nextDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(nextDate) | ||
}; | ||
}); | ||
return dateMapper(length)((_, i) => { | ||
const date = i + 1; | ||
nextDate.setDate(date); | ||
return { | ||
date, | ||
iso: iso8601(nextDate) | ||
}; | ||
}); | ||
}; | ||
@@ -114,0 +113,0 @@ |
Sorry, the diff of this file is not supported yet
599246
3.66%18
5.88%630
-0.32%