-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 470bd62
Showing
13 changed files
with
1,922 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node_version: [16, 18] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
id: pnpm-install | ||
with: | ||
version: 7 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v3 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build the library | ||
run: pnpm build | ||
|
||
- name: Test the library | ||
run: pnpm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": false, | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"trailingComma": "es5", | ||
"arrowParens": "always", | ||
"bracketSameLine": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright 2023 Konstantin Epishev <konstantin@epishev.me> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# `dayjs-calendar-month` | ||
|
||
> ⏰ Unofficial Day.js plugin to get month calendar range | ||
## Install | ||
|
||
Install `dayjs` and the plugin with your favorite package manager: | ||
|
||
```shell | ||
npm add dayjs dayjs-calendar-month | ||
``` | ||
|
||
## Usage | ||
|
||
Extend `dayjs`: | ||
|
||
```js | ||
import dayjs from "dayjs" | ||
// required to the plugin | ||
import isBetween from "dayjs/plugin/isBetween" | ||
import calendarMonth from "dayjs-calendar-month" | ||
|
||
dayjs.extend(isBetween) | ||
dayjs.extend(calendarMonth) | ||
|
||
dayjs("2020-01-01").calendarMonth() // array of dayjs instances from 2019-12-29 to 2020-02-01 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PluginFunc } from "dayjs" | ||
|
||
declare const plugin: PluginFunc | ||
export = plugin | ||
|
||
declare module "dayjs" { | ||
interface Dayjs { | ||
calendarMonth(): Dayjs[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default (o, c) => { | ||
const proto = c.prototype | ||
|
||
proto.calendarMonth = function () { | ||
const start = this.startOf("month").startOf("week") | ||
const end = this.endOf("month").endOf("week") | ||
const days = [] | ||
let i = start.clone() | ||
|
||
while (i.isBetween(start.subtract(1, "second"), end)) { | ||
days.push(i.startOf("day")) | ||
i = i.add(1, "day") | ||
} | ||
|
||
return days | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { test, expect } from "vitest" | ||
import dayjs from "dayjs" | ||
import IsBetweenPlugin from "dayjs/plugin/isBetween" | ||
import CalendarMonthPlugin from "./index" | ||
|
||
dayjs.extend(IsBetweenPlugin) | ||
dayjs.extend(CalendarMonthPlugin) | ||
|
||
test("calendar month multiple of seven", () => { | ||
expect(dayjs("2020-01-01").calendarMonth().length % 7).toBe(0) | ||
}) | ||
|
||
test("first day of calendar is the first day of the first week of month", () => { | ||
const calendar = dayjs("2020-01-01").calendarMonth() | ||
|
||
expect(calendar[0].valueOf()).toBe(dayjs("2019-12-29 00:00:00").valueOf()) | ||
}) | ||
|
||
test("last day of calendar is the last day of the last week of month", () => { | ||
const calendar = dayjs("2020-01-01").calendarMonth() | ||
|
||
expect(calendar[calendar.length - 1].valueOf()).toBe( | ||
dayjs("2020-02-01 00:00:00").valueOf() | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "dayjs-calendar-month", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"test": "vitest", | ||
"build": "vite build" | ||
}, | ||
"lint-staged": { | ||
"*.{js,json}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
}, | ||
"simple-git-hooks": { | ||
"pre-commit": "npx lint-staged" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/epszaw/dayjs-calendar-month.git" | ||
}, | ||
"keywords": [], | ||
"author": "Konstantin Epishev <konstantin@epishev.me>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/epszaw/dayjs-calendar-month/issues" | ||
}, | ||
"homepage": "https://github.com/epszaw/dayjs-calendar-month#readme", | ||
"files": [ | ||
"./dist", | ||
"package.json", | ||
"dayjs.d.ts", | ||
"README.md" | ||
], | ||
"types": "./dayjs.d.ts", | ||
"main": "./dist/dayjs-calendar-month.js", | ||
"module": "./dist/dayjs-calendar-month.mjs", | ||
"exports": { | ||
".": { | ||
"require": "./dist/dayjs-calendar-month.js", | ||
"import": "./dist/dayjs-calendar-month.mjs" | ||
} | ||
}, | ||
"devDependencies": { | ||
"lint-staged": "^13.1.2", | ||
"prettier": "^2.8.4", | ||
"simple-git-hooks": "^2.8.1", | ||
"vite": "^4.1.2", | ||
"vitest": "^0.28.5" | ||
}, | ||
"dependencies": { | ||
"dayjs": "^1.11.7" | ||
} | ||
} |
Oops, something went wrong.