calendar-base
Advanced tools
Comparing version 0.3.0 to 1.0.0
{ | ||
"name": "calendar-base", | ||
"version": "0.3.0", | ||
"description": "Base methods for generating calendars using JavaScript.", | ||
"keywords": [ "calendar", "generation", "base", "core" ], | ||
"main": "lib/calendar-base.js", | ||
"scripts": { | ||
"build": "cat lib/calendar-base.js | umd calendar-base --commonJS | uglifyjs > dist/calendar-base.min.js", | ||
"test": "mocha --reporter spec test/index.js" | ||
}, | ||
"version": "1.0.0", | ||
"author": "Wes Souza <hey@wes.dev> (https://wes.dev/)", | ||
"license": "MIT", | ||
"keywords": [ | ||
"calendar", | ||
"generation", | ||
"base", | ||
"core" | ||
], | ||
"repository": { | ||
@@ -15,10 +17,57 @@ "type": "git", | ||
}, | ||
"tonicExampleFilename": "examples/node-js/simple-calendar.js", | ||
"author": "Wesley de Souza <npm@wesley.so>", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"module": "dist/calendar-base.esm.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsdx build --name CalendarBase --format cjs,esm,umd", | ||
"lint": "tsdx lint src test", | ||
"prepare": "yarn run build", | ||
"start": "tsdx watch", | ||
"test": "tsdx test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^2.1.0", | ||
"uglify-js": "^2.4.16", | ||
"umd": "^3.0.0" | ||
"@types/jest": "^25.1.3", | ||
"tsdx": "^0.12.3", | ||
"tslib": "^1.11.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"peerDependencies": {}, | ||
"eslintConfig": { | ||
"parser": "@typescript-eslint/parser", | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier/@typescript-eslint", | ||
"plugin:prettier/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"no-duplicate-imports": "error", | ||
"curly": "error" | ||
} | ||
}, | ||
"jest": { | ||
"globals": { | ||
"ts-jest": { | ||
"diagnostics": { | ||
"warnOnly": true | ||
} | ||
} | ||
} | ||
}, | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} | ||
} | ||
} |
110
README.md
@@ -1,51 +0,70 @@ | ||
# Calendar Base [![Build Status](https://travis-ci.org/WesleydeSouza/calendar-base.svg?branch=master)](https://travis-ci.org/WesleydeSouza/calendar-base) | ||
# Calendar Base | ||
<a href="https://github.com/WesSouza/calendar-base/actions?query=branch%3Amaster+workflow%3A%22CI%20Tests"><img src="https://github.com/WesSouza/calendar-base/workflows/CI%20Tests/badge.svg" alt="Install, lint, test and build status badge"></a> | ||
[![npm](https://nodei.co/npm/calendar-base.png)](https://nodei.co/npm/calendar-base/) | ||
Base methods for generating calendars using JavaScript. | ||
Supports IE 6+, Chrome 1+, Firefox 3+, Safari 4+. | ||
Output is ES5 compatible. | ||
## Installation | ||
```bash | ||
# using npm | ||
npm install calendar-base | ||
# or yarn | ||
yarn add calendar-base | ||
``` | ||
Or manually copy `dist/calendar-base.min.js` to your project. | ||
## Usage | ||
## Usage | ||
```js | ||
var Calendar = require('calendar-base').Calendar, | ||
cal = new Calendar(); | ||
const Calendar = require('calendar-base').Calendar; | ||
const cal = new Calendar(); | ||
cal.getCalendar(2015, 0); | ||
// Returns an Array with the calendar for January 2015. | ||
cal.getCalendar(2020, 0); | ||
/* | ||
Returns an Array with the calendar for January 2020, including empty spaces for | ||
days from the previous and next months: | ||
[ | ||
false, | ||
false, | ||
{ day: 1, weekDay: 3, month: 0, year: 2020 }, | ||
{ day: 2, weekDay: 4, month: 0, year: 2020 }, | ||
{ day: 3, weekDay: 5, month: 0, year: 2020 }, | ||
{ day: 4, weekDay: 6, month: 0, year: 2020 }, | ||
{ day: 5, weekDay: 0, month: 0, year: 2020 }, | ||
... | ||
] | ||
*/ | ||
``` | ||
Usage with AMD and global variables is available through `dist/calendar-base.min.js`. | ||
[Check an online example](https://npm.runkit.com/calendar-base) or browse the | ||
[`examples`](./examples/) folder for some simple use cases. | ||
[Check an online example](https://tonicdev.com/npm/calendar-base) or browse the `examples` folder for some simple use cases. | ||
### Date object notation | ||
Every returned day or date argument follows this notation: | ||
```js | ||
{ | ||
day: 14, | ||
month: 9, | ||
year: 1986, | ||
weekDay: 4, | ||
selected: false, | ||
siblingMonth: false, | ||
weekNumber: 42 | ||
day: 14, | ||
month: 9, | ||
year: 1986, | ||
weekDay: 4, | ||
selected: false, | ||
siblingMonth: false, | ||
weekNumber: 42 | ||
} | ||
``` | ||
Properties `month` and `weekDay` respect JavaScript’s [`Date.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype). | ||
Properties `month` and `weekDay` respect JavaScript’s | ||
[`Date.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype). | ||
Only `day`, `month`, and `year` are necessary as input parameters for methods that require a date. | ||
Only `day`, `month`, and `year` are necessary as input parameters for methods | ||
that require a date. | ||
#### `Calendar(options)` | ||
@@ -57,9 +76,10 @@ | ||
* `startDate`: current selected starting date (default `undefined`) | ||
* `endDate`: current selected ending date (default `undefined`) | ||
* `siblingMonths`: whether to include the previous and next months’ days before and after the current month when generating a calendar (default `false`) | ||
* `weekNumbers`: whether to include the week number on each day | ||
* `weekStart`: day of the week, respects [`Date.prototype.getDay`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) (default `0`, Sunday) | ||
- `startDate`: current selected starting date (default `undefined`) | ||
- `endDate`: current selected ending date (default `undefined`) | ||
- `siblingMonths`: whether to include the previous and next months’ days before | ||
and after the current month when generating a calendar (default `false`) | ||
- `weekNumbers`: whether to include the week number on each day | ||
- `weekStart`: day of the week, respects | ||
[`Date.prototype.getDay`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) (default `0`, Sunday) | ||
#### `Calendar.diff(dateOne, dateTwo)` | ||
@@ -74,3 +94,2 @@ | ||
#### `Calendar.interval(dateOne, dateTwo)` | ||
@@ -85,3 +104,2 @@ | ||
#### `Calendar.compare(leftDate, rightDate)` | ||
@@ -92,3 +110,3 @@ | ||
- `-1` if `leftDate` < `rightDate` | ||
- `0` if `leftDate` == `rightDate` | ||
- `0` if `leftDate` == `rightDate` | ||
- `1` if `leftDate` > `rightDate` | ||
@@ -103,3 +121,2 @@ | ||
#### `Calendar.daysInMonth(year, month)` | ||
@@ -114,3 +131,2 @@ | ||
#### `Calendar.isLeapYear(year)` | ||
@@ -125,3 +141,2 @@ | ||
#### `Calendar.calculateWeekNumber(date)` | ||
@@ -136,8 +151,10 @@ | ||
#### `Calendar.prototype.getCalendar(year, month)` | ||
Returns an `Array` of dates with the days from the given month, always starting at the configured week day. | ||
Returns an `Array` of dates with the days from the given month, always starting | ||
at the configured week day. | ||
If sibling months is disabled, paddings are added as `false` to align the week days, otherwise the respective days from the previous or next months are included. | ||
If sibling months is disabled, paddings are added as `false` to align the week | ||
days, otherwise the respective days from the previous or next months are | ||
included. | ||
@@ -154,3 +171,2 @@ ```js | ||
#### `Calendar.prototype.setDate(date)` | ||
@@ -160,3 +176,2 @@ | ||
#### `Calendar.prototype.setStartDate(date)` | ||
@@ -170,3 +185,2 @@ | ||
#### `Calendar.prototype.setEndDate(date)` | ||
@@ -180,6 +194,6 @@ | ||
#### `Calendar.prototype.isDateSelected(date)` | ||
Checks wheter the given date is inside the selected dates interval, returns a `Boolean`. | ||
Checks whether the given date is inside the selected dates interval, returns a | ||
`Boolean`. | ||
@@ -191,10 +205,10 @@ ```js | ||
## Important note on week numbers | ||
Week numbers are calculated based on the ISO 8601 standard, which assumes calculations based on weeks starting on Mondays. Be extra careful displaying the week number if your calendar doesn't start on a Monday. | ||
Week numbers are calculated based on the ISO 8601 standard, which assumes | ||
calculations based on weeks starting on Mondays. Be extra careful displaying the | ||
week number if your calendar doesn't start on a Monday. | ||
## License | ||
MIT, http://wesleydesouza.mit-license.org/ | ||
MIT, https://wes.dev/LICENSE.txt |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
128190
16
1018
1
202
4
1
2