npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icalendar.js

v0.3.8

Published

Modern module to parse and stringify iCalendar to Javascript.

Downloads

60

Readme

icalendar.js

Modern module to parse and stringify iCalendar to Javascript.

Features of iCalendar.js:

  • Parse an ICalendar object from a BufferArray
  • Serialize to RFC 5545 ICS format from an ICalendar object
  • Deserialize from RFC 5545 ICS format to an ICalendar object
  • Convert from an ICalendar object to JSON
  • Convert from JSON to an ICalendar object
  • Provides an API to filter components of an ICalendar object

Installing

Using npm:

$ npm add icalendar.js

On Deno

import { ICalendar } from "npm:icalendar.js";

Example

import { ICalendar } from "icalendar.js";

const res = await fetch("https:source/....ics");
const payload = await res.arrayBuffer();
const icalendar = ICalendar.from(payload);

icalendar.filterComponentsByRange(Date.UTC(2023, 2, 10), Date.UTC(2023, 2, 15));

Create a new ICalendar object and write a ICS file.

import { ICalendar, VComponent, PropertyValue } from "icalendar.js";
import * as propertyTypes from "icalendar.js/property_types";

const calendar = ICalendar.create();
const event = new VComponent("VEVENT");

calendar.components.add(event);

event.properties.set(
    "SUMMARY",
    new PropertyValue(new propertyTypes.Text(`text`))
);
event.properties.set(
    "DTSTART",
    new PropertyValue(
        new propertyTypes.Date({
            fullYear: 2023,
            month: 3,
            monthDay: 12,
        })
    )
);
event.properties.set(
    "DTEND",
    new PropertyValue(
        new propertyTypes.Date({
            fullYear: 2023,
            month: 3,
            monthDay: 13,
        })
    )
);

fs.writeFile("myfile.ics", iCalendar.toICS());

Serialize and Deserialize iCalendar Objects to JSON

To serialize an ICalendar object to JSON, you can use the JSON.stringify(icalendar) method. This will convert the ICalendar object into a JSON string, which can be stored or sent over a network.

To deserialize an ICalendar object from a JSON string, you can first use the JSON.parse(payload) method to convert the JSON string into a JavaScript object. Then, you can create a new ICalendar object from the JavaScript object using the static ICalendar.fromJSON(object) method.

This way, iCalendar.js enables bidirectional conversion between ICalendar objects and JSON, which can be useful for storage, transfer, and manipulation of data.

Parse ICS File

Sample Load:

import { ICalendar } from "icalendar.js";

const location = new URL("sample.ics", import.meta.url);
const payload = await readFile(location);
const icalendar = ICalendar.from(payload);
// =>
// ICalendar
//   kind: 'VCALENDAR',
//   properties: Map(9) {
//     'VERSION' => PropertyValue { value: '2.0', parameters: Map(0) {} },
//     'PRODID' => PropertyValue {
//       value: '-//Office Holidays Ltd.//EN',
//       parameters: Map(0) {}
//     },
//     'X-WR-CALNAME' => PropertyValue {
//       value: 'International Holidays',
//       parameters: Map(0) {}
//     },
//     'X-WR-CALDESC' => PropertyValue {
//       value: 'Public Holidays in International. Provided by http://www.officeholidays.com',
//       parameters: Map(0) {}
//     },
//     'REFRESH-INTERVAL' => PropertyValue {
//       value: 'PT48H',
//       parameters: Map(1) { 'VALUE' => 'DURATION' }
//     },
// ...

AST

Kind Allows:

  • Module
  • PropertyParameter
  • PropertyParameterName
  • PropertyParameterValue
  • AltRepParam
  • AltRepParamName
  • AltRepParamValue

Sample Parser:

const payload = new TextEncoder().encode(
    "" +
        `DESCRIPTION;ALTREP="http://www.wiz.org":The Fall'98 Wild Wizards\n` +
        ` Conference - - Las Vegas, NV, USA\n`
);
const tokens = Lexer.from(payload);
const ast = AST.from(tokens);
// =>
// {
//   kind: 'Module',
//   span: { start: 0, end: 100 },
//   nodes: [
//     {
//       kind: 'PropertyParameter',
//       span: { start: 0, end: 99 },
//       name: {
//         kind: 'PropertyParameterName',
//         span: { start: 0, end: 11 },
//         value: 'DESCRIPTION'
//       },
//       value: {
//         kind: 'PropertyParameterValue',
//         span: { start: 40, end: 99 },
//         value: "The Fall'98 Wild Wizards Conference - - Las Vegas, NV, USA"
//       },
//       altRepNodes: [
//         {
//           kind: 'AltRepParam',
// ...

Lexer

Token allows:

  • colon
  • equal
  • keyword
  • newline
  • semicolon
  • string
  • string_multiline

Sample tokenizer:

import { Lexer } from "icalendar.js/lexer";

const payload = new TextEncoder().encode(
    "" +
        `DESCRIPTION;ALTREP="http://www.wiz.org":The Fall'98 Wild Wizards\n` +
        ` Conference - - Las Vegas, NV, USA\n`
);

const tokens = Lexer.from(payload);
// =>
// [
//   {
//     kind: 'keyword',
//     span: { start: 0, end: 11 },
//     raw: Uint8Array(11) [
//       68, 69, 83, 67, 82,
//       73, 80, 84, 73, 79,
//       78
//     ],
//     value: 'DESCRIPTION'
//   },
//   {
//     kind: 'semicolon',
//     span: { start: 11, end: 12 },
//     raw: Uint8Array(1) [ 59 ]
//   },
//   {
//     kind: 'keyword',
//     span: { start: 12, end: 18 },
//     raw: Uint8Array(6) [ 65, 76, 84, 82, 69, 80 ],
//     value: 'ALTREP'
//   },
// ...

Look this full sample