Socket
Socket
Sign inDemoInstall

ics

Package Overview
Dependencies
6
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.6.0 to 3.6.1

26

dist/defaults.js

@@ -6,18 +6,14 @@ "use strict";

});
exports.headerDefaults = exports.eventDefaults = void 0;
exports["default"] = void 0;
var _nanoid = require("nanoid");
var headerDefaults = function headerDefaults() {
return {
productId: 'adamgibbons/ics',
method: 'PUBLISH'
};
var _utils = require("./utils");
var defaults = {
title: 'Untitled event',
productId: 'adamgibbons/ics',
method: 'PUBLISH',
uid: (0, _nanoid.nanoid)(),
timestamp: (0, _utils.formatDate)(null, 'utc'),
start: (0, _utils.formatDate)(null, 'utc')
};
exports.headerDefaults = headerDefaults;
var eventDefaults = function eventDefaults() {
return {
title: 'Untitled event',
uid: (0, _nanoid.nanoid)(),
timestamp: Date.now()
};
};
exports.eventDefaults = eventDefaults;
var _default = defaults;
exports["default"] = _default;

@@ -9,15 +9,66 @@ "use strict";

exports.createEvents = createEvents;
var _nanoid = require("nanoid");
var _pipeline = require("./pipeline");
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function buildHeaderAndValidate(header) {
return (0, _pipeline.validateHeader)((0, _pipeline.buildHeader)(header));
function assignUniqueId(event) {
event.uid = event.uid || (0, _nanoid.nanoid)();
return event;
}
function buildHeaderAndEventAndValidate(event) {
return (0, _pipeline.validateHeaderAndEvent)(_objectSpread(_objectSpread({}, (0, _pipeline.buildHeader)(event)), (0, _pipeline.buildEvent)(event)));
function validateAndBuildEvent(event) {
return (0, _pipeline.validateEvent)((0, _pipeline.buildEvent)(event));
}
function applyInitialFormatting(_ref) {
var error = _ref.error,
value = _ref.value;
if (error) {
return {
error: error,
value: null
};
}
return {
error: null,
value: (0, _pipeline.formatEvent)(value)
};
}
function reformatEventsByPosition(_ref2, idx, list) {
var error = _ref2.error,
value = _ref2.value;
if (error) return {
error: error,
value: value
};
if (idx === 0) {
// beginning of list
return {
value: value.slice(0, value.indexOf('END:VCALENDAR')),
error: null
};
}
if (idx === list.length - 1) {
// end of list
return {
value: value.slice(value.indexOf('BEGIN:VEVENT')),
error: null
};
}
return {
error: null,
value: value.slice(value.indexOf('BEGIN:VEVENT'), value.indexOf('END:VEVENT') + 12)
};
}
function catenateEvents(accumulator, _ref3, idx) {
var error = _ref3.error,
value = _ref3.value;
if (error) {
accumulator.error = error;
accumulator.value = null;
return accumulator;
}
if (accumulator.value) {
accumulator.value = accumulator.value.concat(value);
return accumulator;
}
accumulator.value = value;
return accumulator;
}
function convertTimestampToArray(timestamp) {

@@ -35,54 +86,78 @@ var inputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'local';

function createEvent(attributes, cb) {
return createEvents([attributes], cb);
}
function createEvents(events, headerAttributesOrCb, cb) {
var resolvedHeaderAttributes = _typeof(headerAttributesOrCb) === 'object' ? headerAttributesOrCb : {};
var resolvedCb = arguments.length === 3 ? cb : typeof headerAttributesOrCb === 'function' ? headerAttributesOrCb : null;
var run = function run() {
if (!events) {
if (!attributes) {
Error('Attributes argument is required');
}
assignUniqueId(attributes);
if (!cb) {
// No callback, so return error or value in an object
var _validateAndBuildEven = validateAndBuildEvent(attributes),
_error = _validateAndBuildEven.error,
_value = _validateAndBuildEven.value;
if (_error) return {
error: _error,
value: _value
};
var event = '';
try {
event = (0, _pipeline.formatEvent)(_value);
} catch (error) {
return {
error: new Error('one argument is required'),
error: error,
value: null
};
}
var _ref = events.length === 0 ? buildHeaderAndValidate(resolvedHeaderAttributes) : buildHeaderAndEventAndValidate(_objectSpread(_objectSpread({}, events[0]), resolvedHeaderAttributes)),
headerError = _ref.error,
headerValue = _ref.value;
if (headerError) {
return {
error: headerError,
value: null
};
}
var value = '';
value += (0, _pipeline.formatHeader)(headerValue);
for (var i = 0; i < events.length; i++) {
var _buildHeaderAndEventA = buildHeaderAndEventAndValidate(events[i]),
eventError = _buildHeaderAndEventA.error,
eventValue = _buildHeaderAndEventA.value;
if (eventError) return {
error: eventError,
value: null
};
value += (0, _pipeline.formatEvent)(eventValue);
}
value += (0, _pipeline.formatFooter)();
return {
error: null,
value: value
value: event
};
};
var returnValue;
try {
returnValue = run();
} catch (e) {
returnValue = {
error: e,
}
// Return a node-style callback
var _validateAndBuildEven2 = validateAndBuildEvent(attributes),
error = _validateAndBuildEven2.error,
value = _validateAndBuildEven2.value;
if (error) return cb(error);
return cb(null, (0, _pipeline.formatEvent)(value));
}
function createEvents(events, cb) {
if (!events) {
return {
error: Error('one argument is required'),
value: null
};
}
if (!resolvedCb) {
return returnValue;
if (events.length === 0) {
var _createEvent = createEvent({
start: [2000, 10, 5, 5, 0],
duration: {
hours: 1
}
}),
_error2 = _createEvent.error,
dummy = _createEvent.value;
if (_error2) return {
error: _error2,
value: null
};
return {
error: null,
value: dummy.slice(0, dummy.indexOf('BEGIN:VEVENT')) + dummy.slice(dummy.indexOf('END:VEVENT') + 10 + 2)
};
}
return resolvedCb(returnValue.error, returnValue.value);
if (events.length === 1) {
return createEvent(events[0], cb);
}
var _events$map$map$map$m = events.map(assignUniqueId).map(validateAndBuildEvent).map(applyInitialFormatting).map(reformatEventsByPosition).reduce(catenateEvents, {
error: null,
value: null
}),
error = _events$map$map$map$m.error,
value = _events$map$map$map$m.value;
if (!cb) {
return {
error: error,
value: value
};
}
return cb(error, value);
}

@@ -6,5 +6,5 @@ "use strict";

});
exports.buildEvent = buildEvent;
exports.buildHeader = buildHeader;
var _defaults = require("../defaults");
exports["default"] = buildEvent;
var _defaults = _interopRequireDefault(require("../defaults"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

@@ -14,18 +14,35 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function removeUndefined(input) {
return Object.entries(input).reduce(function (clean, entry) {
return typeof entry[1] !== 'undefined' ? Object.assign(clean, _defineProperty({}, entry[0], entry[1])) : clean;
}, {});
}
function buildHeader() {
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
// fill in default values where necessary
var output = Object.assign({}, (0, _defaults.headerDefaults)(), attributes);
return removeUndefined(output);
}
function buildEvent() {
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var title = attributes.title,
productId = attributes.productId,
method = attributes.method,
uid = attributes.uid,
sequence = attributes.sequence,
start = attributes.start,
startType = attributes.startType,
duration = attributes.duration,
end = attributes.end,
description = attributes.description,
url = attributes.url,
geo = attributes.geo,
location = attributes.location,
status = attributes.status,
categories = attributes.categories,
organizer = attributes.organizer,
attendees = attributes.attendees,
alarms = attributes.alarms,
recurrenceRule = attributes.recurrenceRule,
created = attributes.created,
lastModified = attributes.lastModified,
calName = attributes.calName,
htmlContent = attributes.htmlContent;
// fill in default values where necessary
var output = Object.assign({}, (0, _defaults.eventDefaults)(), attributes);
return removeUndefined(output);
var output = Object.assign({}, _defaults["default"], attributes);
// remove undefined values
return Object.entries(output).reduce(function (clean, entry) {
return typeof entry[1] !== 'undefined' ? Object.assign(clean, _defineProperty({}, entry[0], entry[1])) : clean;
}, {});
}

@@ -6,29 +6,9 @@ "use strict";

});
exports.formatEvent = formatEvent;
exports.formatFooter = formatFooter;
exports.formatHeader = formatHeader;
exports["default"] = formatEvent;
var _utils = require("../utils");
var _encodeNewLines = _interopRequireDefault(require("../utils/encode-new-lines"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function formatHeader() {
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var productId = attributes.productId,
method = attributes.method,
calName = attributes.calName;
var icsFormat = '';
icsFormat += 'BEGIN:VCALENDAR\r\n';
icsFormat += 'VERSION:2.0\r\n';
icsFormat += 'CALSCALE:GREGORIAN\r\n';
icsFormat += (0, _utils.foldLine)("PRODID:".concat((0, _encodeNewLines["default"])(productId))) + '\r\n';
icsFormat += (0, _utils.foldLine)("METHOD:".concat((0, _encodeNewLines["default"])(method))) + '\r\n';
icsFormat += calName ? (0, _utils.foldLine)("X-WR-CALNAME:".concat((0, _encodeNewLines["default"])(calName))) + '\r\n' : '';
icsFormat += "X-PUBLISHED-TTL:PT1H\r\n";
return icsFormat;
}
function formatFooter() {
return "END:VCALENDAR\r\n";
}
function formatEvent() {
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var title = attributes.title,
productId = attributes.productId,
method = attributes.method,
uid = attributes.uid,

@@ -61,11 +41,19 @@ sequence = attributes.sequence,

lastModified = attributes.lastModified,
calName = attributes.calName,
htmlContent = attributes.htmlContent;
var icsFormat = '';
icsFormat += 'BEGIN:VCALENDAR\r\n';
icsFormat += 'VERSION:2.0\r\n';
icsFormat += 'CALSCALE:GREGORIAN\r\n';
icsFormat += (0, _utils.foldLine)("PRODID:".concat(productId)) + '\r\n';
icsFormat += (0, _utils.foldLine)("METHOD:".concat(method)) + '\r\n';
icsFormat += calName ? (0, _utils.foldLine)("X-WR-CALNAME:".concat(calName)) + '\r\n' : '';
icsFormat += "X-PUBLISHED-TTL:PT1H\r\n";
icsFormat += 'BEGIN:VEVENT\r\n';
icsFormat += (0, _utils.foldLine)("UID:".concat((0, _encodeNewLines["default"])(uid))) + '\r\n';
icsFormat += title ? (0, _utils.foldLine)("SUMMARY:".concat((0, _encodeNewLines["default"])((0, _utils.setSummary)(title)))) + '\r\n' : '';
icsFormat += (0, _utils.foldLine)("DTSTAMP:".concat((0, _encodeNewLines["default"])((0, _utils.formatDate)(timestamp)))) + '\r\n';
icsFormat += "UID:".concat(uid, "\r\n");
icsFormat += (0, _utils.foldLine)("SUMMARY:".concat(title ? (0, _utils.setSummary)(title) : title)) + '\r\n';
icsFormat += "DTSTAMP:".concat(timestamp, "\r\n");
// All day events like anniversaries must be specified as VALUE type DATE
icsFormat += (0, _utils.foldLine)("DTSTART".concat(start && start.length == 3 ? ";VALUE=DATE" : "", ":").concat((0, _encodeNewLines["default"])((0, _utils.formatDate)(start, startOutputType || startType, startInputType)))) + '\r\n';
icsFormat += "DTSTART".concat(start && start.length == 3 ? ";VALUE=DATE" : "", ":").concat((0, _utils.formatDate)(start, startOutputType || startType, startInputType), "\r\n");

@@ -77,31 +65,29 @@ // End is not required for all day events on single days (like anniversaries)

if (end) {
icsFormat += (0, _utils.foldLine)("DTEND".concat(end.length === 3 ? ";VALUE=DATE" : "", ":").concat((0, _encodeNewLines["default"])((0, _utils.formatDate)(end, endOutputType || startOutputType || startType, endInputType || startInputType)))) + '\r\n';
icsFormat += "DTEND".concat(end.length === 3 ? ";VALUE=DATE" : "", ":").concat((0, _utils.formatDate)(end, endOutputType || startOutputType || startType, endInputType || startInputType), "\r\n");
}
}
icsFormat += typeof sequence !== 'undefined' ? "SEQUENCE:".concat(sequence, "\r\n") : '';
icsFormat += description ? (0, _utils.foldLine)("DESCRIPTION:".concat((0, _encodeNewLines["default"])((0, _utils.setDescription)(description)))) + '\r\n' : '';
icsFormat += url ? (0, _utils.foldLine)("URL:".concat((0, _encodeNewLines["default"])(url))) + '\r\n' : '';
icsFormat += description ? (0, _utils.foldLine)("DESCRIPTION:".concat((0, _utils.setDescription)(description))) + '\r\n' : '';
icsFormat += url ? (0, _utils.foldLine)("URL:".concat(url)) + '\r\n' : '';
icsFormat += geo ? (0, _utils.foldLine)("GEO:".concat((0, _utils.setGeolocation)(geo))) + '\r\n' : '';
icsFormat += location ? (0, _utils.foldLine)("LOCATION:".concat((0, _encodeNewLines["default"])((0, _utils.setLocation)(location)))) + '\r\n' : '';
icsFormat += status ? (0, _utils.foldLine)("STATUS:".concat((0, _encodeNewLines["default"])(status))) + '\r\n' : '';
icsFormat += categories ? (0, _utils.foldLine)("CATEGORIES:".concat((0, _encodeNewLines["default"])(categories.join(',')))) + '\r\n' : '';
icsFormat += location ? (0, _utils.foldLine)("LOCATION:".concat((0, _utils.setLocation)(location))) + '\r\n' : '';
icsFormat += status ? (0, _utils.foldLine)("STATUS:".concat(status)) + '\r\n' : '';
icsFormat += categories ? (0, _utils.foldLine)("CATEGORIES:".concat(categories)) + '\r\n' : '';
icsFormat += organizer ? (0, _utils.foldLine)("ORGANIZER;".concat((0, _utils.setOrganizer)(organizer))) + '\r\n' : '';
icsFormat += busyStatus ? (0, _utils.foldLine)("X-MICROSOFT-CDO-BUSYSTATUS:".concat((0, _encodeNewLines["default"])(busyStatus))) + '\r\n' : '';
icsFormat += transp ? (0, _utils.foldLine)("TRANSP:".concat((0, _encodeNewLines["default"])(transp))) + '\r\n' : '';
icsFormat += classification ? (0, _utils.foldLine)("CLASS:".concat((0, _encodeNewLines["default"])(classification))) + '\r\n' : '';
icsFormat += created ? 'CREATED:' + (0, _encodeNewLines["default"])((0, _utils.formatDate)(created)) + '\r\n' : '';
icsFormat += lastModified ? 'LAST-MODIFIED:' + (0, _encodeNewLines["default"])((0, _utils.formatDate)(lastModified)) + '\r\n' : '';
icsFormat += htmlContent ? (0, _utils.foldLine)("X-ALT-DESC;FMTTYPE=text/html:".concat((0, _encodeNewLines["default"])(htmlContent))) + '\r\n' : '';
icsFormat += busyStatus ? (0, _utils.foldLine)("X-MICROSOFT-CDO-BUSYSTATUS:".concat(busyStatus)) + '\r\n' : '';
icsFormat += transp ? (0, _utils.foldLine)("TRANSP:".concat(transp)) + '\r\n' : '';
icsFormat += classification ? (0, _utils.foldLine)("CLASS:".concat(classification)) + '\r\n' : '';
icsFormat += created ? 'CREATED:' + (0, _utils.formatDate)(created) + '\r\n' : '';
icsFormat += lastModified ? 'LAST-MODIFIED:' + (0, _utils.formatDate)(lastModified) + '\r\n' : '';
icsFormat += htmlContent ? (0, _utils.foldLine)("X-ALT-DESC;FMTTYPE=text/html:".concat(htmlContent)) + '\r\n' : '';
if (attendees) {
attendees.forEach(function (attendee) {
icsFormat += (0, _utils.foldLine)("ATTENDEE;".concat((0, _encodeNewLines["default"])((0, _utils.setContact)(attendee)))) + '\r\n';
attendees.map(function (attendee) {
icsFormat += (0, _utils.foldLine)("ATTENDEE;".concat((0, _utils.setContact)(attendee))) + '\r\n';
});
}
icsFormat += recurrenceRule ? (0, _utils.foldLine)("RRULE:".concat((0, _encodeNewLines["default"])(recurrenceRule))) + '\r\n' : '';
icsFormat += exclusionDates ? (0, _utils.foldLine)("EXDATE:".concat((0, _encodeNewLines["default"])(exclusionDates.map(function (a) {
return (0, _utils.formatDate)(a);
}).join(',')))) + '\r\n' : '';
icsFormat += duration ? (0, _utils.foldLine)("DURATION:".concat((0, _utils.formatDuration)(duration))) + '\r\n' : '';
icsFormat += recurrenceRule ? "RRULE:".concat(recurrenceRule, "\r\n") : '';
icsFormat += exclusionDates ? "EXDATE:".concat(exclusionDates, "\r\n") : '';
icsFormat += duration ? "DURATION:".concat((0, _utils.formatDuration)(duration), "\r\n") : '';
if (alarms) {
alarms.forEach(function (alarm) {
alarms.map(function (alarm) {
icsFormat += (0, _utils.setAlarm)(alarm);

@@ -111,3 +97,4 @@ });

icsFormat += "END:VEVENT\r\n";
icsFormat += "END:VCALENDAR\r\n";
return icsFormat;
}

@@ -9,43 +9,20 @@ "use strict";

get: function get() {
return _build.buildEvent;
return _build["default"];
}
});
Object.defineProperty(exports, "buildHeader", {
enumerable: true,
get: function get() {
return _build.buildHeader;
}
});
Object.defineProperty(exports, "formatEvent", {
enumerable: true,
get: function get() {
return _format.formatEvent;
return _format["default"];
}
});
Object.defineProperty(exports, "formatFooter", {
Object.defineProperty(exports, "validateEvent", {
enumerable: true,
get: function get() {
return _format.formatFooter;
return _validate["default"];
}
});
Object.defineProperty(exports, "formatHeader", {
enumerable: true,
get: function get() {
return _format.formatHeader;
}
});
Object.defineProperty(exports, "validateHeader", {
enumerable: true,
get: function get() {
return _validate.validateHeader;
}
});
Object.defineProperty(exports, "validateHeaderAndEvent", {
enumerable: true,
get: function get() {
return _validate.validateHeaderAndEvent;
}
});
var _build = require("./build");
var _format = require("./format");
var _validate = require("./validate");
var _build = _interopRequireDefault(require("./build"));
var _format = _interopRequireDefault(require("./format"));
var _validate = _interopRequireDefault(require("./validate"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -6,12 +6,6 @@ "use strict";

});
var _schema = require("../schema");
Object.keys(_schema).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _schema[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _schema[key];
}
});
});
exports["default"] = void 0;
var _schema = _interopRequireDefault(require("../schema"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _default = _schema["default"];
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateHeader = validateHeader;
exports.validateHeaderAndEvent = validateHeaderAndEvent;
exports["default"] = validateEvent;
var yup = _interopRequireWildcard(require("yup"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
// yup url validation blocks localhost, so use a more flexible regex instead

@@ -22,20 +16,6 @@ // taken from https://github.com/jquense/yup/issues/224#issuecomment-417172609

var urlRegex = /^(?:([a-z0-9+.-]+):\/\/)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/;
var dateTimeSchema = function dateTimeSchema(_ref) {
var required = _ref.required;
return yup.lazy(function (value) {
if (typeof value === 'number') {
return yup.number().integer().min(0);
}
if (typeof value === 'string') {
return yup.string().required();
}
if (!required && typeof value === 'undefined') {
return yup.mixed().oneOf([undefined]);
}
return yup.array().required().min(3).max(7).of(yup.lazy(function (item, options) {
var itemIndex = options.parent.indexOf(options.value);
return [yup.number().integer(), yup.number().integer().min(1).max(12), yup.number().integer().min(1).max(31), yup.number().integer().min(0).max(23), yup.number().integer().min(0).max(60), yup.number().integer().min(0).max(60)][itemIndex];
}));
});
};
var dateTimeSchema = yup.array().min(3).max(7).of(yup.lazy(function (item, options) {
var itemIndex = options.parent.indexOf(options.value);
return [yup.number().integer(), yup.number().integer().min(1).max(12), yup.number().integer().min(1).max(31), yup.number().integer().min(0).max(23), yup.number().integer().min(0).max(60), yup.number().integer().min(0).max(60)][itemIndex];
}));
var durationSchema = yup.object().shape({

@@ -67,3 +47,3 @@ before: yup["boolean"](),

var alarmSchema = yup.object().shape({
action: yup.string().matches(/^(audio|display|email)$/).required(),
action: yup.string().matches(/audio|display|email/).required(),
trigger: yup.mixed().required(),

@@ -80,28 +60,18 @@ description: yup.string(),

}).noUnknown();
var headerShape = {
var schema = yup.object().shape({
summary: yup.string(),
timestamp: yup.mixed(),
title: yup.string(),
productId: yup.string(),
method: yup.string(),
calName: yup.string()
};
var headerSchema = yup.object().shape(headerShape).noUnknown();
var eventShape = {
summary: yup.string(),
timestamp: dateTimeSchema({
required: false
}),
title: yup.string(),
uid: yup.string(),
uid: yup.string().required(),
sequence: yup.number().integer().max(2147483647),
start: dateTimeSchema({
required: true
}),
start: dateTimeSchema.required(),
duration: durationSchema,
startType: yup.string().matches(/^(utc|local)$/),
startInputType: yup.string().matches(/^(utc|local)$/),
startOutputType: yup.string().matches(/^(utc|local)$/),
end: dateTimeSchema({
required: false
}),
endInputType: yup.string().matches(/^(utc|local)$/),
endOutputType: yup.string().matches(/^(utc|local)$/),
startType: yup.string().matches(/utc|local/),
startInputType: yup.string().matches(/utc|local/),
startOutputType: yup.string().matches(/utc|local/),
end: dateTimeSchema,
endInputType: yup.string().matches(/utc|local/),
endOutputType: yup.string().matches(/utc|local/),
description: yup.string(),

@@ -114,3 +84,3 @@ url: yup.string().matches(urlRegex),

location: yup.string(),
status: yup.string().matches(/^(TENTATIVE|CANCELLED|CONFIRMED)$/i),
status: yup.string().matches(/TENTATIVE|CANCELLED|CONFIRMED/i),
categories: yup.array().of(yup.string()),

@@ -121,17 +91,10 @@ organizer: organizerSchema,

recurrenceRule: yup.string(),
busyStatus: yup.string().matches(/^(TENTATIVE|FREE|BUSY|OOF)$/i),
transp: yup.string().matches(/^(TRANSPARENT|OPAQUE)$/i),
busyStatus: yup.string().matches(/TENTATIVE|FREE|BUSY|OOF/i),
transp: yup.string().matches(/TRANSPARENT|OPAQUE/i),
classification: yup.string(),
created: dateTimeSchema({
required: false
}),
lastModified: dateTimeSchema({
required: false
}),
exclusionDates: yup.array().of(dateTimeSchema({
required: true
})),
created: dateTimeSchema,
lastModified: dateTimeSchema,
calName: yup.string(),
htmlContent: yup.string()
};
var headerAndEventSchema = yup.object().shape(_objectSpread(_objectSpread({}, headerShape), eventShape)).test('xor', "object should have end or duration (but not both)", function (val) {
}).test('xor', "object should have end or duration (but not both)", function (val) {
var hasEnd = !!val.end;

@@ -141,5 +104,5 @@ var hasDuration = !!val.duration;

}).noUnknown();
function validateHeader(candidate) {
function validateEvent(candidate) {
try {
var value = headerSchema.validateSync(candidate, {
var value = schema.validateSync(candidate, {
abortEarly: false,

@@ -158,19 +121,2 @@ strict: true

}
}
function validateHeaderAndEvent(candidate) {
try {
var value = headerAndEventSchema.validateSync(candidate, {
abortEarly: false,
strict: true
});
return {
error: null,
value: value
};
} catch (error) {
return {
error: Object.assign({}, error),
value: undefined
};
}
}

@@ -20,5 +20,2 @@ "use strict";

var inputType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'local';
if (typeof args === 'string') {
return args;
}
if (Array.isArray(args) && args.length === 3) {

@@ -48,5 +45,2 @@ var _args = _slicedToArray(args, 3),

}
} else if (!Array.isArray(args)) {
// it's a unix time stamp (ms)
outDate = new Date(args);
}

@@ -53,0 +47,0 @@ if (outputType === 'local') {

@@ -6,8 +6,2 @@ "use strict";

});
Object.defineProperty(exports, "encodeParamValue", {
enumerable: true,
get: function get() {
return _encodeParamValue["default"];
}
});
Object.defineProperty(exports, "foldLine", {

@@ -83,3 +77,2 @@ enumerable: true,

var _setLocation = _interopRequireDefault(require("./set-location"));
var _encodeParamValue = _interopRequireDefault(require("./encode-param-value"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -9,3 +9,2 @@ "use strict";

var _foldLine = _interopRequireDefault(require("./fold-line"));
var _encodeNewLines = _interopRequireDefault(require("./encode-new-lines"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -29,7 +28,7 @@ function setDuration(_ref) {

var formattedString = '';
if (Array.isArray(trigger) || typeof trigger === 'number' || typeof trigger === 'string') {
formattedString = "TRIGGER;VALUE=DATE-TIME:".concat((0, _encodeNewLines["default"])((0, _formatDate["default"])(trigger)), "\r\n");
if (Array.isArray(trigger)) {
formattedString = "TRIGGER;VALUE=DATE-TIME:".concat((0, _formatDate["default"])(trigger), "\r\n");
} else {
var alert = trigger.before ? '-' : '';
formattedString = "TRIGGER:".concat((0, _encodeNewLines["default"])(alert + setDuration(trigger)), "\r\n");
formattedString = "TRIGGER:".concat(alert + setDuration(trigger), "\r\n");
}

@@ -52,10 +51,10 @@ return formattedString;

var formattedString = 'BEGIN:VALARM\r\n';
formattedString += (0, _foldLine["default"])("ACTION:".concat((0, _encodeNewLines["default"])(setAction(action)))) + '\r\n';
formattedString += (0, _foldLine["default"])("ACTION:".concat(setAction(action))) + '\r\n';
formattedString += repeat ? (0, _foldLine["default"])("REPEAT:".concat(repeat)) + '\r\n' : '';
formattedString += description ? (0, _foldLine["default"])("DESCRIPTION:".concat((0, _encodeNewLines["default"])(description))) + '\r\n' : '';
formattedString += description ? (0, _foldLine["default"])("DESCRIPTION:".concat(description)) + '\r\n' : '';
formattedString += duration ? (0, _foldLine["default"])("DURATION:".concat(setDuration(duration))) + '\r\n' : '';
var attachInfo = attachType ? attachType : 'FMTTYPE=audio/basic';
formattedString += attach ? (0, _foldLine["default"])((0, _encodeNewLines["default"])("ATTACH;".concat(attachInfo, ":").concat(attach))) + '\r\n' : '';
formattedString += trigger ? (0, _encodeNewLines["default"])(setTrigger(trigger)) : '';
formattedString += summary ? (0, _foldLine["default"])("SUMMARY:".concat((0, _encodeNewLines["default"])(summary))) + '\r\n' : '';
formattedString += attach ? (0, _foldLine["default"])("ATTACH;".concat(attachInfo, ":").concat(attach)) + '\r\n' : '';
formattedString += trigger ? setTrigger(trigger) : '';
formattedString += summary ? (0, _foldLine["default"])("SUMMARY:".concat(summary)) + '\r\n' : '';
formattedString += 'END:VALARM\r\n';

@@ -62,0 +61,0 @@ return formattedString;

@@ -7,4 +7,2 @@ "use strict";

exports["default"] = setContact;
var _encodeParamValue = _interopRequireDefault(require("./encode-param-value"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function setContact(_ref) {

@@ -24,3 +22,3 @@ var name = _ref.name,

if (cutype) {
formattedParts.push("CUTYPE=".concat((0, _encodeParamValue["default"])(cutype)));
formattedParts.push("CUTYPE=".concat(cutype));
}

@@ -31,13 +29,13 @@ if (xNumGuests !== undefined) {

if (role) {
formattedParts.push("ROLE=".concat((0, _encodeParamValue["default"])(role)));
formattedParts.push("ROLE=".concat(role));
}
if (partstat) {
formattedParts.push("PARTSTAT=".concat((0, _encodeParamValue["default"])(partstat)));
formattedParts.push("PARTSTAT=".concat(partstat));
}
if (dir) {
formattedParts.push("DIR=".concat((0, _encodeParamValue["default"])(dir)));
formattedParts.push("DIR=".concat(dir));
}
formattedParts.push('CN='.concat((0, _encodeParamValue["default"])(name || 'Unnamed attendee')));
formattedParts.push('CN='.concat(name || 'Unnamed attendee'));
var formattedAttendee = formattedParts.join(';').concat(email ? ":mailto:".concat(email) : '');
return formattedAttendee;
}

@@ -7,4 +7,2 @@ "use strict";

exports["default"] = setOrganizer;
var _encodeParamValue = _interopRequireDefault(require("./encode-param-value"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function setOrganizer(_ref) {

@@ -16,8 +14,8 @@ var name = _ref.name,

var formattedOrganizer = '';
formattedOrganizer += dir ? "DIR=".concat((0, _encodeParamValue["default"])(dir), ";") : '';
formattedOrganizer += sentBy ? "SENT-BY=".concat((0, _encodeParamValue["default"])("MAILTO:".concat(sentBy)), ";") : '';
formattedOrganizer += dir ? "DIR=\"".concat(dir, "\";") : '';
formattedOrganizer += sentBy ? "SENT-BY=\"MAILTO:".concat(sentBy, "\";") : '';
formattedOrganizer += 'CN=';
formattedOrganizer += (0, _encodeParamValue["default"])(name || 'Organizer');
formattedOrganizer += name || 'Organizer';
formattedOrganizer += email ? ":MAILTO:".concat(email) : '';
return formattedOrganizer;
}

@@ -1,3 +0,1 @@

export type DateTime = DateArray | number | string;
export type DateArray =

@@ -72,3 +70,3 @@ | [number, number, number, number, number]

duration?: DurationObject;
trigger?: DurationObject | DateTime;
trigger?: DurationObject; // @todo DateArray | DurationObject;
repeat?: number;

@@ -79,10 +77,4 @@ attachType?: string;

export type HeaderAttributes = {
productId?: string;
method?: string;
calName?: string;
}
export type EventAttributes = {
start: DateTime;
start: DateArray;
startInputType?: 'local' | 'utc';

@@ -113,14 +105,14 @@ startOutputType?: 'local' | 'utc';

productId?: HeaderAttributes['productId'];
productId?: string;
uid?: string;
method?: HeaderAttributes['method'];
method?: string;
recurrenceRule?: string;
exclusionDates?: string;
sequence?: number;
calName?: HeaderAttributes['calName'];
calName?: string;
classification?: classificationType;
created?: DateTime;
lastModified?: DateTime;
created?: DateArray;
lastModified?: DateArray;
htmlContent?: string;
} & ({ end: DateTime } | { duration: DurationObject });
} & ({ end: DateArray } | { duration: DurationObject });

@@ -136,5 +128,5 @@ export type ReturnObject = { error?: Error; value?: string };

export function createEvents(events: EventAttributes[], callback: NodeCallback): void;
export function createEvents(events: EventAttributes[], headerAttributes?: HeaderAttributes): ReturnObject;
export function createEvents(events: EventAttributes[], headerAttributes: HeaderAttributes, callback: NodeCallback): void;
export function createEvents(events: EventAttributes[]): ReturnObject;
export function convertTimestampToArray(timestamp: Number, inputType: String): DateArray;
{
"name": "ics",
"version": "3.6.0",
"version": "3.6.1",
"description": "iCal (ics) file generator",

@@ -5,0 +5,0 @@ "exports": {

@@ -124,16 +124,14 @@ ics

// PRODID:adamgibbons/ics
// METHOD:PUBLISH
// X-PUBLISHED-TTL:PT1H
// BEGIN:VEVENT
// UID:pP83XzQPo5RlvjDCMIINs
// UID:mPfHOGi_sif_xO493Mgi6
// SUMMARY:Lunch
// DTSTAMP:20230917T142209Z
// DTSTART:20180115T121500Z
// DTSTAMP:20180210T093900Z
// DTSTART:20180115T191500Z
// DURATION:PT45M
// END:VEVENT
// BEGIN:VEVENT
// UID:gy5vfUVv6wjyBeNkkFmBX
// UID:ho-KcKyhNaQVDqJCcGfXD
// SUMMARY:Dinner
// DTSTAMP:20230917T142209Z
// DTSTART:20180115T121500Z
// DTSTAMP:20180210T093900Z
// DTSTART:20180115T191500Z
// DURATION:PT1H30M

@@ -151,4 +149,4 @@ // END:VEVENT

let start = moment().format('YYYY-M-D-H-m').split("-").map((a) => parseInt(a))
let end = moment().add({'hours':2, "minutes":30}).format("YYYY-M-D-H-m").split("-").map((a) => parseInt(a))
let start = moment().format('YYYY-M-D-H-m').split("-")
let end = moment().add({'hours':2, "minutes":30}).format("YYYY-M-D-H-m").split("-")

@@ -174,3 +172,3 @@ alarms.push({

events.push(event)
console.log(ics.createEvents(events).value)
console.log(ics.createEvents(events))

@@ -180,19 +178,25 @@ // BEGIN:VCALENDAR

// CALSCALE:GREGORIAN
// PRODID:myCalendarId
// PRODID:MyCalendarId
// METHOD:PUBLISH
// X-PUBLISHED-TTL:PT1H
// BEGIN:VEVENT
// UID:123@ics.com
// UID:123@MyCalendarIdics.com
// SUMMARY:test here
// DTSTAMP:20230917T142621Z
// DTSTART:20230917T152600
// DTEND:20230917T175600
// DTSTAMP:20180409T072100Z
// DTSTART:20180409
// DTEND:20180409
// BEGIN:VALARM
// ACTION:DISPLAY
// DESCRIPTION:Reminder
// TRIGGER:-PT2H30M
// END:VALARM
// BEGIN:VALARM
// ACTION:AUDIO
// REPEAT:2
// DESCRIPTION:Reminder
// ATTACH;VALUE=URI:Glass
// TRIGGER:-PT2H30M\nEND:VALARM
// TRIGGER:PT2H
// END:VALARM
// END:VEVENT
// END:VCALENDAR
```

@@ -249,5 +253,2 @@

Only the `start` property is required.
Note all date/time fields can be the array form, or a number representing the unix timestamp in milliseconds (e.g. `getTime()` on a `Date`).
The following properties are accepted:

@@ -257,6 +258,6 @@

| ------------- | ------------- | ----------
| start | **Required**. Date and time at which the event begins. | `[2000, 1, 5, 10, 0]` (January 5, 2000) or a `number`
| start | **Required**. Date and time at which the event begins. | `[2000, 1, 5, 10, 0]` (January 5, 2000)
| startInputType | Type of the date/time data in `start`:<br>`local` (default): passed data is in local time.<br>`utc`: passed data is UTC |
| startOutputType | Format of the start date/time in the output:<br>`utc` (default): the start date will be sent in UTC format.<br>`local`: the start date will be sent as "floating" (form #1 in [RFC 5545](https://tools.ietf.org/html/rfc5545#section-3.3.5)) |
| 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) or a `number`
| 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)
| endInputType | Type of the date/time data in `end`:<br>`local`: passed data is in local time.<br>`utc`: passed data is UTC.<br>The default is the value of `startInputType` |

@@ -279,3 +280,3 @@ | endOutputType | Format of the start date/time in the output:<br>`utc`: the start date will be sent in UTC format.<br>`local`: the start date will be sent as "floating" (form #1 in [RFC 5545](https://tools.ietf.org/html/rfc5545#section-3.3.5)).<br>The default is the value of `startOutputType` |

| recurrenceRule | A recurrence rule, commonly referred to as an RRULE, defines the repeat pattern or rule for to-dos, journal entries and events. If specified, RRULE can be used to compute the recurrence set (the complete set of recurrence instances in a calendar component). You can use a generator like this [one](https://www.textmagic.com/free-tools/rrule-generator). | `FREQ=DAILY`
| exclusionDates | Array of date-time exceptions for recurring events, to-dos, journal entries, or time zone definitions. | `[[2000, 1, 5, 10, 0], [2000, 2, 5, 10, 0]]` OR `[1694941727477, 1694945327477]`
| exclusionDates| This property defines the list of DATE-TIME exceptions for recurring events, to-dos, journal entries, or time zone definitions. Uses a comma-delimited list of [Date-Time](https://tools.ietf.org/html/rfc5545#section-3.3.5) values. See [EXDATE spec](https://tools.ietf.org/html/rfc5545#section-3.8.5.1).|`'20230620T131500Z,20230621T131500'` (June 20th, 2023 at 1:15pm UTC and June 21st, 2000 at 1:15pm LOCAL)
| sequence | For sending an update for an event (with the same uid), defines the revision sequence number. | `2`

@@ -285,4 +286,4 @@ | busyStatus | Used to specify busy status for Microsoft applications, like Outlook. See [Microsoft spec](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/cd68eae7-ed65-4dd3-8ea7-ad585c76c736). | `'BUSY'` OR `'FREE'` OR `'TENTATIVE`' OR `'OOF'`

| classification | This property defines the access classification for a calendar component. See [iCalender spec](https://icalendar.org/iCalendar-RFC-5545/3-8-1-3-classification.html). | `'PUBLIC'` OR `'PRIVATE'` OR `'CONFIDENTIAL`' OR any non-standard string
| created | Date-time representing event's creation date. Provide a date-time in local time | `[2000, 1, 5, 10, 0]` or a `number`
| lastModified | Date-time representing date when event was last modified. Provide a date-time in local time | [2000, 1, 5, 10, 0] or a `number`
| created | Date-time representing event's creation date. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| lastModified | Date-time representing date when event was last modified. Provide a date-time in UTC | [2000, 1, 5, 10, 0] (January 5, 2000 GMT +00:00)
| calName | Specifies the _calendar_ (not event) name. Used by Apple iCal and Microsoft Outlook; see [Open Specification](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcical/1da58449-b97e-46bd-b018-a1ce576f3e6d) | `'Example Calendar'` |

@@ -318,8 +319,6 @@ | htmlContent | Used to include HTML markup in an event's description. Standard DESCRIPTION tag should contain non-HTML version. | `<!DOCTYPE html><html><body><p>This is<br>test<br>html code.</p></body></html>` |

### `createEvents(events[, headerParams, callback])`
### `createEvents(events[, callback])`
Generates an iCal-compliant VCALENDAR string with multiple VEVENTS.
`headerParams` may be omitted, and in this case they will be read from the first event.
If a callback is not provided, returns an object having the form `{ error, value }`, where value is an iCal-compliant text string

@@ -326,0 +325,0 @@ if `error` is `null`.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc