New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pretty-jcal

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty-jcal

jCal to readable JSON 2-way-convert

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

pretty-jcal

Introduction

RFC7265 JSON Format for iCalendar (jCal) is a great to handle iCalendar content in Javascript.

This repo provide a JSON format converter to allow 2-way-convert between the prettyJCAL and jCal.

Installation

yarn add pretty-jcal

or

npm i pretty-jcal

Reason

When dealing with iCalendar(ics) files, we often want a js object representation of the ical object. It's natural for us to use jCal. However, there's a problem.

Example jCal JSON:

[
  "vcalendar",
  [
    ["calscale", {}, "text", "GREGORIAN"],
    ["prodid", {}, "text", "-//Example Inc.//Example Calendar//EN"],
    ["version", {}, "text", "2.0"]
  ],
  [
    [
      "vevent",
      [
        ["dtstamp", {}, "date-time", "2008-02-05T19:12:24Z"],
        ["dtstart", {}, "date", "2008-10-06"],
        ["summary", {}, "text", "Planning meeting"],
        ["uid", {}, "text", "4088E990AD89CB3DBB484909"]
      ],
      []
    ]
  ]
]

While it's compact and efficient, you cannot figure out what is what and you would end up writing code like: calendar[1][2][3] + component[2][3] which is borderline unreadable and unmaintainable.

Solution

We can transform the jCal JSON to make it more like a normal JSON, while it's more verbose, it's much easier to write readable and maintainable code.

Example PrettyJCAL JSON:

{
  "name": "vcalendar",
  "properties": [
    {
      "name": "calscale",
      "type": "text",
      "value": "GREGORIAN"
    },
    {
      "name": "prodid",
      "type": "text",
      "value": "-//Example Inc.//Example Calendar//EN"
    },
    {
      "name": "version",
      "type": "text",
      "value": "2.0"
    }
  ],
  "components": [
    {
      "name": "vevent",
      "properties": [
        {
          "name": "dtstamp",
          "type": "date-time",
          "value": "2008-02-05T19:12:24Z"
        },
        {
          "name": "dtstart",
          "type": "date",
          "value": "2008-10-06"
        },
        {
          "name": "summary",
          "type": "text",
          "value": "Planning meeting"
        },
        {
          "name": "uid",
          "type": "text",
          "value": "4088E990AD89CB3DBB484909"
        }
      ],
      "components": []
    }
  ]
}

Features

  • Readable JSON format with full information about each node, follows JSON convention which only use array when there's multiple objects of same type.
  • jCal PrettyJCAL 2-way-convert, with no loss in information.
  • Built-in Typescript typings, make sure your code strongly typed and safe.

Usage

Caveat

The typescript typing does not verify against jCal standard, it's up to user to make sure only valid properties and components were used.

Function nameParameter typeReturn value typeDescription
jcal2prettyJCALJCALComponentNodePrettyJCALComponentNodeConvert standard jCal to prettyJCAL JSON format
prettyJCAL2jcalPrettyJCALComponentNodeJCALComponentNodeConvert prettyJCAL JSON format to standard jCal

JCALComponentNode (Array type)

PropertyDescription
0Component name
1Component properties
2Children components

JCALPropertyNode (Array type)

PropertyDescription
0name of the property
1parameters of this property
2type of the property value
3property value

PrettyJCALComponentNode (Object type)

PropertyDescription
NameComponent name
propertiesComponent properties
componentsChildren components

PrettyJCALPropertyNode (Object type)

PropertyDescription
namename of the property
parametersparameters of this property
typetype of the property value
valueproperty value

License

MIT

Keywords

FAQs

Package last updated on 02 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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