0.1.1 • Published 4 years ago

bplokjs-calendar-dates v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

bplokjs-calendar-dates

获取指定月份天数

install & useage

npm install --save bplokjs-calendar-dates

calendarDates(date, options)

import calendarDates from './bplokjs-calendar-dates';

const dates = calendarDates(new Date(), {
    firstDay: 0
});

console.log(dates[0]);

{
    type: "previous",
    date: [Date Object]
}

options

firstDay

Number 默认:0

指定0(周末)-6(周六)作为一周的开始

totalDays

Number 默认:0

指定返回日期数,默认情况下自动适配,负数返回空数组,大于 0 则返回指定数量的日期数组

matrix

Boolean 默认:false

矩阵形式返回 eg:

[
    [{type:'current', date: Date}, ...6],
    [...]
]

Interface

export type DateItem = {
	type: "previous" | "current" | "next";
	date: Date;
};

declare function calendarDates<
	T extends {
		firstDay?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
		matrix?: boolean;
		totalDays?: number;
	}
>(
	date: Date,
	options?: T
): T extends { matrix: true } ? Array<DateItem[]> : DateItem[];

export default calendarDates;