Giter Club home page Giter Club logo

ics's Introduction

ics

The iCalendar generator

npm version Code Climate TravisCI build status Downloads

Install

npm install -S ics

Example Usage

  1. Create an iCalendar event:
import ics from 'ics'

const event = {
  start: [2018, 5, 30, 6, 30],
  duration: { hours: 6, minutes: 30 },
  title: 'Bolder Boulder',
  description: 'Annual 10-kilometer run in Boulder, Colorado',
  location: 'Folsom Field, University of Colorado (finish line)',
  url: 'http://www.bolderboulder.com/',
  geo: { lat: 40.0095, lon: 105.2669 },
  categories: ['10k races', 'Memorial Day Weekend', 'Boulder CO'],
  status: 'CONFIRMED',
  organizer: { name: 'Admin', email: '[email protected]' },
  attendees: [
    { name: 'Adam Gibbons', email: '[email protected]' },
    { name: 'Brittany Seaton', email: '[email protected]' }
  ]
}

ics.createEvent(event, (error, value) => {
  if (error) {
    console.log(error)
  }

  console.log(value)
  //  BEGIN:VCALENDAR
  //  VERSION:2.0
  //  CALSCALE:GREGORIAN
  //  PRODID:adamgibbons/ics
  //  BEGIN:VEVENT
  //  UID:070bbdd0-a6de-11e7-9552-4faa901a846b
  //  SUMMARY:Bolder Boulder
  //  DTSTAMP:20171002T012300Z
  //  DTSTART:20180530T125000Z
  //  DESCRIPTION:Annual 10-kilometer run in Boulder, Colorado
  //  URL:http://www.bolderboulder.com/
  //  GEO:40.0095;105.2669
  //  LOCATION:Folsom Field, University of Colorado (finish line)
  //  STATUS:CONFIRMED
  //  CATEGORIES:10k races,Memorial Day Weekend,Boulder CO
  //  ATTENDEE;CN=Adam Gibbons:mailto:[email protected]
  //  ATTENDEE;CN=Brittany Seaton:mailto:[email protected]
  //  BEGIN:VALARM
  //  ACTION:display
  //  DESCRIPTION:Reminder
  //  TRIGGER;VALUE=DATE-TIME:20180530T020000Z
  //  END:VALARM
  //  DURATION:PT5H
  //  END:VEVENT
  //  END:VCALENDAR


})
  1. Write an iCalendar file:
import { writeFileSync } from 'fs'
import ics from 'ics'

ics.createEvent({
  title: 'Dinner',
  description: 'Nightly thing I do',
  start: [2018, 1, 15, 6, 30],
  duration: { minutes: 50 }
}, (error, value) => {
  if (error) {
    console.log(error)
  }

  fs.writeFileSync(`${__dirname}/event.ics`, value)
})
  1. Write multiple iCalendar files:

ics.createEvents functionality is on the roadmap, but in the meanwhile, you can do this easily by following this example.

API

createEvent(attributes, [callback])

Returns an iCal-compliant text string. If callback is provided, returns a Node-style callback. If callback is not provided, returns an object with error and value properties.

attributes

Object literal containing event information. Only the start property is required. The following properties are accepted:

Property Description Example
start Required. Date and time at which the event begins. [2000, 1, 5, 10, 0] (January 5, 2000 in my timezone)
end Time at which event ends. Either end or duration is required, but not both. [2000, 1, 5, 13, 5] (January 5, 2000 at 1pm)
duration How long the event lasts. Object literal having form { weeks, days, hours, minutes, seconds } Either end or duration is required, but not both. { hours: 1, minutes: 45 } (1 hour and 45 minutes)
title Title of event. 'Code review'
description Description of event. 'A constructive roasting of those seeking to merge into master branch'
location Intended venue Mountain Sun Pub and Brewery.
geo Geographic coordinates (lat/lon) { lat: 38.9072, lon: 77.0369 }
url URL associated with event 'http://www.mountainsunpub.com/'
status Three statuses are allowed: TENTATIVE, CONFIRMED, or CANCELLED` CONFIRMED
organizer Person organizing the event {name: 'Adam Gibbons', email: '[email protected]'}
attendees Persons invited to the event [{ name: 'Mo', email: '[email protected]'}, { name: 'Bo', email: '[email protected]' }]
categories Categories associated with the event ['hacknight', 'stout month']
alarms Alerts that can be set to trigger before, during, or after the event { action: 'DISPLAY', trigger: [2000, 1, 4, 18, 30] }
productId Product which created ics, PRODID field 'adamgibbons/ics'
uid Universal unique id for event, produced by default with uuid/v1. Warning: This value must be globally unique. It is recommended that it follow the RFC 822 addr-spec (i.e. localpart@domain). Including the @domain half is a good way to ensure uniqueness. '28021620-be61-11e7-be87-5f3ab42f0785'

callback

Optional. Node-style callback.

function (err, value) {
  if (err) {
    // if iCal generation fails, err is an object containing the reason
    // if iCal generation succeeds, err is null
  }

  console.log(value) // iCal-compliant text string
}

Develop

Run mocha tests and watch for changes:

npm start

Run tests once and exit:

npm test

Build the project, compiling all ES6 files within the src directory into vanilla JavaScript in the dist directory.

npm run build

References

ics's People

Contributors

adamgibbons avatar jasonhumphrey2 avatar davidschlachter avatar kolarski avatar drewtunes avatar duvel avatar alexleventer avatar john-osullivan avatar marcbachmann avatar elreeda avatar lavluda avatar

Watchers

 avatar  avatar

Forkers

jagarcia29

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.