generate-ical 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Lukas Wiklund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # generate-ical
2
+
3
+ This is a typed utility to generate Ical files.
4
+
5
+ ## Install
6
+
7
+ `npm install generate-ical`
@@ -0,0 +1,34 @@
1
+ type Event = {
2
+ productId: string;
3
+ startDate: Date;
4
+ title: string;
5
+ description?: {
6
+ plain: string;
7
+ html?: string;
8
+ };
9
+ location?: {
10
+ title: string;
11
+ address?: string;
12
+ geo?: {
13
+ lat: number;
14
+ lon: number;
15
+ };
16
+ };
17
+ organizer?: {
18
+ name: string;
19
+ email?: string;
20
+ mailTo?: string;
21
+ sentBy?: string;
22
+ };
23
+ url?: string;
24
+ } & ({
25
+ isAllDay: true;
26
+ endDate?: Date;
27
+ } | {
28
+ isAllDay: false;
29
+ endDate: Date;
30
+ });
31
+ export default function generateIcal(data: Event): string;
32
+ export declare function escape(string: string): string;
33
+ export declare function escapeInQuotes(string: string): string;
34
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.escapeInQuotes = exports.escape = void 0;
7
+ const uuid_random_1 = __importDefault(require("uuid-random"));
8
+ function generateIcal(data) {
9
+ const id = (0, uuid_random_1.default)();
10
+ let result = "";
11
+ function addRow(row) {
12
+ result += `${row}\r\n`;
13
+ }
14
+ addRow("BEGIN:VEVENT");
15
+ addRow(`UID:${id}`);
16
+ addRow(`SEQUENCE:0`);
17
+ addRow(`DTSTAMP:${formatDateTime(new Date())}`);
18
+ addRow(`SUMMARY:${escape(data.title)}`);
19
+ if (data.description !== undefined) {
20
+ const { plain, html } = data.description;
21
+ addRow(`DESCRIPTION:${plain}`);
22
+ if (html !== undefined) {
23
+ addRow(`X-ALT-DESC;FMTTYPE=text/html:${escape(html)}`);
24
+ }
25
+ }
26
+ if (data.isAllDay) {
27
+ addRow(`DTSTART;VALUE=DATE:${formatDate(data.startDate)}`);
28
+ if (data.endDate !== undefined) {
29
+ addRow(`DTEND;VALUE=DATE:${formatDate(data.endDate)}`);
30
+ }
31
+ }
32
+ else {
33
+ addRow(`DTSTART:${formatDateTime(data.startDate)}`);
34
+ addRow(`DTEND:${formatDateTime(data.endDate)}`);
35
+ }
36
+ if (data.location !== undefined) {
37
+ addRow(`LOCATION:${escape(data.location.title)}`);
38
+ if (data.location.address !== undefined) {
39
+ addRow(escape(data.location.address));
40
+ }
41
+ if (data.location.geo !== undefined) {
42
+ const { lat, lon } = data.location.geo;
43
+ addRow(`GEO:${escape(lat.toString())};${escape(lon.toString())}`);
44
+ }
45
+ }
46
+ if (data.organizer !== undefined) {
47
+ const { name, sentBy, email, mailTo } = data.organizer;
48
+ let string = `ORGANIZER;CN=${escapeInQuotes(name)}`;
49
+ if (sentBy !== undefined) {
50
+ string += `;SENT-BY="mailto:${escapeInQuotes(sentBy)}"`;
51
+ }
52
+ if (email !== undefined && mailTo !== undefined) {
53
+ string += `;EMAIL=${escape(email)}`;
54
+ }
55
+ if (email !== undefined) {
56
+ string += `:mailto:${escape(mailTo !== null && mailTo !== void 0 ? mailTo : email)}`;
57
+ }
58
+ addRow(string);
59
+ }
60
+ if (data.url !== undefined) {
61
+ addRow(`URL;VALUE=URI:${escape(data.url)}`);
62
+ }
63
+ return result;
64
+ }
65
+ exports.default = generateIcal;
66
+ function escape(string) {
67
+ return string.replace(/[\\;,]/g, match => "\\" + match).replace(/(?:\r\n|\r|\n)/g, "\\n");
68
+ }
69
+ exports.escape = escape;
70
+ function escapeInQuotes(string) {
71
+ return string.replace(/[\\;,"]/g, match => "\\" + match).replace(/(?:\r\n|\r|\n)/g, "\\n");
72
+ }
73
+ exports.escapeInQuotes = escapeInQuotes;
74
+ function formatDate(date) {
75
+ const year = date.getUTCFullYear().toString();
76
+ const month = `${date.getUTCMonth() + 1}`.padStart(2, "0");
77
+ const day = `${date.getUTCDate()}`.padStart(2, "0");
78
+ return `${year}${month}${day}`;
79
+ }
80
+ function formatDateTime(date) {
81
+ const hours = `${date.getUTCHours()}`.padStart(2, "0");
82
+ const minutes = `${date.getUTCMinutes()}`.padStart(2, "0");
83
+ const seconds = `${date.getUTCSeconds()}`.padStart(2, "0");
84
+ return `${formatDate(date)}T${hours}${minutes}${seconds}Z`;
85
+ }
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAwB9B,SAAwB,YAAY,CAAC,IAAW;IAC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E,GAAG,CAAC,CAAA;IAC1D,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,CAAA;AAC3D,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,28 @@
1
1
  {
2
2
  "name": "generate-ical",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "author": {
5
5
  "name": "Lukas Wiklund",
6
6
  "email": "lukas@wiklund.se",
7
7
  "url": "https://github.com/Hadermite"
8
8
  },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Hadermite/generate-ical"
12
+ },
13
+ "files": [
14
+ "./dist/**/*"
15
+ ],
9
16
  "main": "./dist/index.js",
10
17
  "scripts": {
11
- "build": "tsc"
12
- },
13
- "devDependencies": {
14
- "typescript": "^4.9.3"
18
+ "build": "tsc",
19
+ "format": "prettier --write ."
15
20
  },
16
21
  "dependencies": {
17
22
  "uuid-random": "^1.3.2"
23
+ },
24
+ "devDependencies": {
25
+ "prettier": "^2.8.0",
26
+ "typescript": "^4.9.3"
18
27
  }
19
28
  }
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "useTabs": true,
3
- "tabWidth": 4,
4
- "semi": false,
5
- "printWidth": 120,
6
- "arrowParens": "avoid"
7
- }
package/src/index.ts DELETED
@@ -1,111 +0,0 @@
1
- import uuid from "uuid-random"
2
- type Event = {
3
- productId: string
4
- startDate: Date
5
- title: string
6
- description?: { plain: string; html?: string }
7
- location?: {
8
- title: string
9
- address?: string
10
- geo?: {
11
- lat: number
12
- lon: number
13
- }
14
- }
15
- organizer?: {
16
- name: string
17
- email?: string
18
- mailTo?: string
19
- sentBy?: string
20
- }
21
- url?: string
22
- } & ({ isAllDay: true; endDate?: Date } | { isAllDay: false; endDate: Date })
23
-
24
- function generate(data: Event): string {
25
- const id = uuid()
26
- let result = ""
27
-
28
- function addRow(row: string): void {
29
- result += `${row}\r\n`
30
- }
31
-
32
- addRow("BEGIN:VEVENT")
33
- addRow(`UID:${id}`)
34
- addRow(`SEQUENCE:0`)
35
- addRow(`DTSTAMP:${formatDateTime(new Date())}`)
36
- addRow(`SUMMARY:${escape(data.title)}`)
37
-
38
- if (data.description !== undefined) {
39
- const { plain, html } = data.description
40
- addRow(`DESCRIPTION:${plain}`)
41
-
42
- if (html !== undefined) {
43
- addRow(`X-ALT-DESC;FMTTYPE=text/html:${escape(html)}`)
44
- }
45
- }
46
-
47
- if (data.isAllDay) {
48
- addRow(`DTSTART;VALUE=DATE:${formatDate(data.startDate)}`)
49
- if (data.endDate !== undefined) {
50
- addRow(`DTEND;VALUE=DATE:${formatDate(data.endDate)}`)
51
- }
52
- } else {
53
- addRow(`DTSTART:${formatDateTime(data.startDate)}`)
54
- addRow(`DTEND:${formatDateTime(data.endDate)}`)
55
- }
56
-
57
- if (data.location !== undefined) {
58
- addRow(`LOCATION:${escape(data.location.title)}`)
59
- if (data.location.address !== undefined) {
60
- addRow(escape(data.location.address))
61
- }
62
-
63
- if (data.location.geo !== undefined) {
64
- const { lat, lon } = data.location.geo
65
- addRow(`GEO:${escape(lat.toString())};${escape(lon.toString())}`)
66
- }
67
- }
68
-
69
- if (data.organizer !== undefined) {
70
- const { name, sentBy, email, mailTo } = data.organizer
71
- let string = `ORGANIZER;CN=${escapeInQuotes(name)}`
72
- if (sentBy !== undefined) {
73
- string += `;SENT-BY="mailto:${escapeInQuotes(sentBy)}"`
74
- }
75
- if (email !== undefined && mailTo !== undefined) {
76
- string += `;EMAIL=${escape(email)}`
77
- }
78
- if (email !== undefined) {
79
- string += `:mailto:${escape(mailTo ?? email)}`
80
- }
81
- addRow(string)
82
- }
83
-
84
- if (data.url !== undefined) {
85
- addRow(`URL;VALUE=URI:${escape(data.url)}`)
86
- }
87
-
88
- return result
89
- }
90
-
91
- export function escape(string: string): string {
92
- return string.replace(/[\\;,]/g, match => "\\" + match).replace(/(?:\r\n|\r|\n)/g, "\\n")
93
- }
94
-
95
- export function escapeInQuotes(string: string): string {
96
- return string.replace(/[\\;,"]/g, match => "\\" + match).replace(/(?:\r\n|\r|\n)/g, "\\n")
97
- }
98
-
99
- function formatDate(date: Date): string {
100
- const year = date.getUTCFullYear().toString()
101
- const month = `${date.getUTCMonth() + 1}`.padStart(2, "0")
102
- const day = `${date.getUTCDate()}`.padStart(2, "0")
103
- return `${year}${month}${day}`
104
- }
105
-
106
- function formatDateTime(date: Date): string {
107
- const hours = `${date.getUTCHours()}`.padStart(2, "0")
108
- const minutes = `${date.getUTCMinutes()}`.padStart(2, "0")
109
- const seconds = `${date.getUTCSeconds()}`.padStart(2, "0")
110
- return `${formatDate(date)}T${hours}${minutes}${seconds}Z`
111
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2017",
4
- "module": "None",
5
- "moduleResolution": "Node",
6
- "declaration": true,
7
- "esModuleInterop": true,
8
- "sourceMap": true,
9
- "strict": true,
10
- "outDir": "./dist"
11
- },
12
- "include": ["src"]
13
- }