Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,5 @@ # calendario | ||
[![NPM Version](https://img.shields.io/npm/v/express.svg?style=flat)](https://www.npmjs.org/package/calendario) | ||
[![Build Status](https://api.travis-ci.org/raphamorim/calendario.svg)](https://travis-ci.org/raphamorim/calendario) | ||
## Instalação | ||
@@ -16,3 +19,3 @@ | ||
Atualmente as fontes suportam apenas eventos nacionais (com excessão do Brasil). Na próxima release será adicionado mais fontes nacionais e regionais. | ||
Atualmente as fontes suportam apenas eventos nacionais (com excessão do Brasil e Estados Unidos). Na próxima release será adicionado mais fontes nacionais e regionais. | ||
@@ -24,2 +27,3 @@ **Disponível para:** | ||
- Estados Unidos da America `.use('US')` | ||
- [Ver uso para estados americanos](US/states.md) | ||
@@ -33,2 +37,9 @@ Você pode definir a fonte que irá utilizar usando `use()` | ||
Definindo a fonte para um estado específico | ||
```javascript | ||
var calendario = require('calendario'); | ||
calendario.use('US-NY'); | ||
``` | ||
Você também pode criar suas próprias fontes, passando um array de objetos: | ||
@@ -52,2 +63,9 @@ | ||
Você também pode criar suas próprias fontes, passando um arquivo `ics` | ||
```javascript | ||
var calendario = require('calendario'); | ||
calendario.use('BR', {file: 'pt-br.ics', parser: 'ics'}); | ||
``` | ||
## Métodos | ||
@@ -64,3 +82,3 @@ | ||
calendario.isWorkday(new Date('2015-05-01')); // false | ||
calendario.isWorkday(new Date('2015-05-01')); // true | ||
calendario.isWorkday(new Date('2015-05-02')); // true | ||
``` | ||
@@ -119,6 +137,6 @@ | ||
var calendario = require('calendario'); | ||
calendario.use('EN'); | ||
calendario.use('US'); | ||
calendario.use('BR'); | ||
calendario.sourceList(); // ['EN', 'BR'] | ||
calendario.sourceList(); // ['US', 'BR'] | ||
``` | ||
@@ -168,2 +186,3 @@ | ||
- Eventos nacionais: Google Calendar; ID: `en.usa#holiday@group.v.calendar.google.com` | ||
- Eventos estaduais: [Wikipedia](http://en.wikipedia.org/wiki/Public_holidays_in_the_United_States#Legal_holidays_by_states_and_political_divisions_of_the_United_States) | ||
@@ -170,0 +189,0 @@ ## Contribuindo |
module.exports = require('./src/calendario.js'); | ||
var calendario = require('./src/calendario.js'); |
{ | ||
"name": "calendario", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.1.0", | ||
"description": "Check if a day is a workday or holiday", | ||
"main": "index.js", | ||
@@ -13,3 +13,5 @@ "scripts": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"calendar", "holidays", "workdays", "ics", "ical" | ||
], | ||
"author": "Raphael Amorim", | ||
@@ -23,3 +25,6 @@ "license": "MIT", | ||
"mocha": "^2.2.1" | ||
}, | ||
"dependencies": { | ||
"ical2json": "^0.2.0" | ||
} | ||
} |
# calendario | ||
> Verify workdays, holidays, weekends or create events and make your own events | ||
> Check if a day is a workday or holiday. | ||
[![NPM Version](https://img.shields.io/npm/v/express.svg?style=flat)](https://www.npmjs.org/package/calendario) | ||
[![Build Status](https://api.travis-ci.org/raphamorim/calendario.svg)](https://travis-ci.org/raphamorim/calendario) | ||
Available too: [brazilian portuguese](docs/PT-BR.md). | ||
@@ -17,3 +20,3 @@ | ||
Currently there are only **national** calendars (except for Brazil calendar). In next release will be added regional support. | ||
Currently there are only **national** calendars (except for Brazil and U.S.A). In next release will be added regional support. | ||
@@ -25,2 +28,3 @@ **Available for:** | ||
- United States of America `.use('US')` | ||
- [See usage for U.S. states and territories](docs/US/states.md) | ||
@@ -34,2 +38,9 @@ You can set the calendar using `use()` | ||
Setting the calendar for a specific state | ||
```javascript | ||
var calendario = require('calendario'); | ||
calendario.use('US-NY'); | ||
``` | ||
You can create your owns calendars, passing a array of objects like these: | ||
@@ -53,2 +64,10 @@ | ||
You can create your own calendar, passing a `ics` file | ||
```javascript | ||
var calendario = require('calendario'); | ||
calendario.use('BR', {file: 'pt-br.ics', parser: 'ics'}); | ||
``` | ||
## Methods | ||
@@ -65,3 +84,3 @@ | ||
calendario.isWorkday(new Date('2015-05-01')); // false | ||
calendario.isWorkday(new Date('2015-05-01')); // true | ||
calendario.isWorkday(new Date('2015-05-02')); // true | ||
``` | ||
@@ -120,6 +139,6 @@ | ||
var calendario = require('calendario'); | ||
calendario.use('EN'); | ||
calendario.use('US'); | ||
calendario.use('BR'); | ||
calendario.sourceList(); // ['EN', 'BR'] | ||
calendario.sourceList(); // ['US', 'BR'] | ||
``` | ||
@@ -149,5 +168,5 @@ | ||
#### clean | ||
#### clear | ||
Clean and remove all previously defined sources: | ||
Clear and remove all previously defined sources: | ||
@@ -157,3 +176,3 @@ ```javascript | ||
calendario.use('BR'); // Sources: ['BR'] | ||
calendario.clean(); // Sources: [] | ||
calendario.clear(); // Sources: [] | ||
``` | ||
@@ -171,2 +190,3 @@ | ||
- National Events: Google Calendar; ID: `en.usa#holiday@group.v.calendar.google.com` | ||
- Regional Events: [Wikipedia](http://en.wikipedia.org/wiki/Public_holidays_in_the_United_States#Legal_holidays_by_states_and_political_divisions_of_the_United_States) | ||
@@ -173,0 +193,0 @@ ## Contributing |
'use strict'; | ||
var Range = require('../lib/range'); | ||
var Range = require('./range'), | ||
ical = require('ical2json'), | ||
fs = require('fs'); | ||
@@ -20,3 +22,3 @@ function Calendario() { | ||
name = name.join('-'); | ||
this.addSource(name, source); | ||
this.useObjectSource(name, source); | ||
} else { | ||
@@ -27,5 +29,6 @@ this.useDefaultSource(name); | ||
if (source instanceof Array) { | ||
this.addSource(name, source); | ||
this.useObjectSource(name, source); | ||
} else { | ||
this.parseSource(name, source); | ||
} | ||
// this.parseSource(name, source); | ||
} | ||
@@ -35,6 +38,10 @@ } | ||
Calendario.prototype.parseSource = function(name, source) { | ||
// some function | ||
var data = fs.readFileSync(source.file, 'utf-8'); | ||
if (source.parser === 'ics') { | ||
data = ical.convert(data); | ||
this.useDefaultSource(name, data); | ||
} | ||
} | ||
Calendario.prototype.addSource = function(name, source) { | ||
Calendario.prototype.useObjectSource = function(name, source) { | ||
var events = new Array(), | ||
@@ -56,7 +63,8 @@ ev = new Object(); | ||
Calendario.prototype.useDefaultSource = function(name) { | ||
Calendario.prototype.useDefaultSource = function(name, data) { | ||
var events = [], | ||
date; | ||
var data = require('../calendars/' + name + '/' + name + '.json'); | ||
if (!data) | ||
data = require('../calendars/' + name + '/' + name + '.json'); | ||
@@ -81,3 +89,3 @@ data = data['VCALENDAR'][0]['VEVENT']; | ||
Calendario.prototype.clean = function() { | ||
Calendario.prototype.clear = function() { | ||
this.sources = []; | ||
@@ -84,0 +92,0 @@ } |
@@ -9,3 +9,3 @@ var assert = require('assert'), | ||
it('should get data about christmas event', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('US'); | ||
@@ -28,3 +28,3 @@ var christmas = calendario.aboutDay(new Date('2015-12-25 00:00:00')); | ||
it('should get a empty array', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('US'); | ||
@@ -42,3 +42,3 @@ var nonEvent = calendario.aboutDay(new Date('2015-10-05 00:00:00')); | ||
it('should get data about christmas event', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
@@ -61,3 +61,3 @@ var christmas = calendario.aboutDay(new Date('2015-12-25 00:00:00')); | ||
it('should get a empty array', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
@@ -64,0 +64,0 @@ var nonEvent = calendario.aboutDay(new Date('2015-10-05 00:00:00')); |
@@ -9,3 +9,3 @@ var assert = require('assert'), | ||
it('should get false', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('US'); | ||
@@ -20,3 +20,3 @@ var thanksgiving = calendario.isWorkday(new Date('2015-11-26 10:00')); | ||
it('should get false', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('US'); | ||
@@ -31,3 +31,3 @@ var christmas = calendario.isWorkday(new Date('2015-12-25 23:00')); | ||
it('should get true', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('US'); | ||
@@ -44,3 +44,3 @@ var workday = calendario.isWorkday(new Date('2015-10-05 05:00')); | ||
it('should get false', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
@@ -55,3 +55,3 @@ var independence = calendario.isWorkday(new Date('2015-09-07 10:00')); | ||
it('should get false', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
@@ -66,3 +66,3 @@ var christmas = calendario.isWorkday(new Date('2015-12-25 12:00')); | ||
it('should get true', function(done) { | ||
calendario.clean(); | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
@@ -69,0 +69,0 @@ var workday = calendario.isWorkday(new Date('2015-10-05 15:00')); |
@@ -5,28 +5,105 @@ var assert = require('assert'), | ||
describe('Verify Sources', function() { | ||
context("use('US') -> United States National", function() { | ||
it('should return US source', function(done) { | ||
calendario.clean(); | ||
calendario.use('US'); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
context("using default sources", function() { | ||
context("use('US') -> United States National", function() { | ||
it('should return US source', function(done) { | ||
calendario.clear(); | ||
calendario.use('US'); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
assert.deepEqual(sourceList, ['US']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
assert.deepEqual(sourceList, ['US']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
}); | ||
}); | ||
context("use('BR') -> Brazil National", function() { | ||
it('should return BR source', function(done) { | ||
calendario.clear(); | ||
calendario.use('BR'); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
assert.deepEqual(sourceList, ['BR']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
context("use('BR') -> Brazil National", function() { | ||
it('should return BR source', function(done) { | ||
calendario.clean(); | ||
calendario.use('BR'); | ||
context("using array of objects", function() { | ||
it('should return a valid source', function(done) { | ||
calendario.clear(); | ||
var arrayOfEvents = [ | ||
{ | ||
date: new Date('2020-11-25'), | ||
workday: true, | ||
summary: "Mozilla Summit" | ||
}, | ||
{ | ||
date: new Date('2021-1-20'), | ||
workday: true, | ||
summary: "Mozilla another event" | ||
} | ||
]; | ||
calendario.use('MozillaCalendar', arrayOfEvents); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
assert.deepEqual(sourceList, ['BR']); | ||
assert.deepEqual(sourceList, ['MOZILLACALENDAR']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList, arrayOfEvents); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
context("using ICS file", function() { | ||
context("use `pt-br.ics` as source", function() { | ||
it('should return BR source', function(done) { | ||
calendario.clear(); | ||
calendario.use('BR', {file: 'test/fixtures/pt-br.ics', parser: 'ics'}); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
assert.deepEqual(sourceList, ['BR']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
}); | ||
}) | ||
context("use `en-usa.ics` as source", function() { | ||
it('should return US source', function(done) { | ||
calendario.clear(); | ||
calendario.use('US', {file: 'test/fixtures/en-usa.ics', parser: 'ics'}); | ||
var sourceList = calendario.sourceList(), | ||
eventList = calendario.eventList(); | ||
assert.deepEqual(sourceList, ['US']); | ||
assert.deepEqual(typeof(eventList), 'object'); | ||
assert.deepEqual(eventList instanceof Array, true); | ||
done(); | ||
}); | ||
}) | ||
context("use non-existent file as source", function() { | ||
it('should throw a error', function(done) { | ||
calendario.clear(); | ||
var params = {file: 'non-sense.non-sense', parser: 'ics'}; | ||
function testNonExistentFile() { | ||
try { | ||
calendario.use('US', params); | ||
return true; | ||
} catch(e) { | ||
throw new Error(e); | ||
} | ||
} | ||
assert.throws(testNonExistentFile, Error); | ||
done(); | ||
}); | ||
}) | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
254462
103
4328
197
1
3
+ Addedical2json@^0.2.0
+ Addedcommander@2.6.0(transitive)
+ Addedical2json@0.2.0(transitive)