Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calendarize

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calendarize - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

4

dist/index.js

@@ -1,2 +0,2 @@

module.exports = function (target) {
module.exports = function (target, offset) {
var i=0, j=0, week, out=[], date = new Date(target || new Date);

@@ -6,3 +6,3 @@ var year = date.getFullYear(), month = date.getMonth();

// day index (of week) for 1st of month
var first = new Date(year, month, 1).getDay();
var first = new Date(year, month, 1 - (offset | 0)).getDay();

@@ -9,0 +9,0 @@ // how many days there are in this month

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.calendarize=t()}(this,function(){return function(e){for(var t,n=0,o=0,f=[],r=new Date(e||new Date),a=r.getFullYear(),u=r.getMonth(),i=new Date(a,u,1).getDay(),d=new Date(a,u+1,0).getDate();n<d;){for(o=0,t=new Array(7);o<7;){for(;o<i;)t[o++]=0;t[o++]=++n>d?0:n,i=0}f.push(t)}return f}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.calendarize=t()}(this,function(){return function(e,t){for(var n,o=0,f=0,r=[],a=new Date(e||new Date),u=a.getFullYear(),i=a.getMonth(),d=new Date(u,i,1-(0|t)).getDay(),c=new Date(u,i+1,0).getDate();o<c;){for(f=0,n=new Array(7);f<7;){for(;f<d;)n[f++]=0;n[f++]=++o>c?0:o,d=0}r.push(n)}return r}});
export type Week = [number,number,number,number,number,number,number];
export default function (target?: Date | string | number): Week[];
export default function (target?: Date | string | number, offset?: number): Week[];
{
"version": "1.0.0",
"version": "1.1.0",
"name": "calendarize",
"repository": "lukeed/calendarize",
"description": "A tiny (196B) utility to generate calendar views",
"description": "A tiny (204B) utility to generate calendar views",
"module": "dist/index.mjs",

@@ -7,0 +7,0 @@ "unpkg": "dist/index.min.js",

# calendarize [![build status](https://badgen.net/github/status/lukeed/calendarize)](https://github.com/lukeed/calendarize/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/calendarize)](https://codecov.io/gh/lukeed/calendarize)
> A tiny (196B) utility to generate calendar views.
> A tiny (204B) utility to generate calendar views.
This function (optionally) accepts a date in exchange for a calendar view of that date's month.
**The output contains no labels!** This is ideal for calendar generator because it allows the developer to easily customize their labels, including full i18n/internationalization support! ([Demo](https://codepen.io/lukeed/pen/KKwrLRz))
Additionally, this module is delivered as:

@@ -28,4 +30,4 @@

const date = new Date('2019-12-20');
const view = calendarize(date);
// Week = [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
const view = calendarize(new Date('2019-12-20'));
//=> [

@@ -45,2 +47,3 @@ //=> [ 1, 2, 3, 4, 5, 6, 7],

// Week = [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
const view = calendarize('Nov 01, 2019');

@@ -57,11 +60,32 @@ //=> [

***with Weeks starting on Monday***
> **Note:** Uses the [`offset`](#offset) parameter.
```js
import calendarize from 'calendarize';
// Week = [Mon, Tue, Wed, Thu, Fri, Sat, Sun]
const view = calendarize('Nov 01, 2019', 1);
//=> [
//=> [ 0, 0, 0, 0, 1, 2, 3],
//=> [ 4, 5, 6, 7, 8, 9, 10],
//=> [11, 12, 13, 14, 15, 16, 17],
//=> [18, 19, 20, 21, 22, 23, 24],
//=> [25, 26, 27, 28, 29, 30, 0],
//=> ]
```
## API
### calendarize(date?)
### calendarize(date?, offset?)
Returns: `Array<Week>`
An Array of `Week` Arrays is returned.<br>Each `Week` is an Array of 7 numbers, each representing a numerical date.
An Array of `Week` Arrays is returned.
> **Important:** A zero (`0`) value represents a date that exists beyond the current month view.
Each `Week` is an Array of 7 numbers, wherein each **index** is the `Day` of the week and each **value** is the numerical date. <br>The index is forwarded from [`Date.getDay`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay), which means that **index: 0** is Sunday.
> **Important:** A **value** of zero (`0`) represents a date that exists beyond the current month view.
#### date

@@ -75,5 +99,38 @@ Type: `string` | `number` | `Date`<br>

#### offset
Type: `number`<br>
Default: `0`
A positive or negative day offset to modify which day of the week the calendar should start.<br>
This offset is ***relative to Sunday*** – so, by default, an offset of `0` will mean that your Weeks will start on Sundays.
> **Note:** Some parts of the globe expect calendars to start on Sunday, Saturday, or Monday: [see map](https://i.redd.it/qcz8nu53lk231.png)
***Example Offsets***
* Monday: `1`
* Tuesday: `2`
* ...
* Friday: `5` or `-2`
* Saturday: `6` or `-1`
If you use `offset: 1`, this means you want the `Week`s to start on Monday. In turn, the 0th value of each `Week` array will be Monday's date.
```js
// The first week of Jan 2020:
// start = Sunday (default)
calendarize('Jan 01, 2020');
// => [[0, 0, 0, 1, 2, 3, 4], ...]
// (days: [S, M, T, W, T, F, S])
// start = Monday (offset: 1)
calendarize('Jan 01, 2020', 1);
// => [[0, 0, 1, 2, 3, 4, 5], ...]
// (days: [M, T, W, T, F, S, S])
```
## License
MIT © [Luke Edwards](https://lukeed.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc