Skip to content

Commit

Permalink
chore: bump version to v2.7.1-m
Browse files Browse the repository at this point in the history
  • Loading branch information
joseajp committed Aug 2, 2018
1 parent a95c221 commit fc8c1bc
Show file tree
Hide file tree
Showing 22 changed files with 826 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ node_modules
.DS_Store
write-event.js
output.ics
dist/
30 changes: 30 additions & 0 deletions dist/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _v = require('uuid/v1');

var _v2 = _interopRequireDefault(_v);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _utils = require('./utils');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var now = (0, _moment2.default)().utc();

var defaults = {
title: 'Untitled event',
productId: 'adamgibbons/ics',
method: 'PUBLISH',
uid: (0, _v2.default)(),
timestamp: (0, _utils.setDateWithUTCtime)([now.get('year'), now.get('month') + 1, now.get('date'), now.get('hours'), now.get('minutes'), now.get('seconds')]),
start: (0, _utils.setDateWithUTCtime)()
};

exports.default = defaults;
124 changes: 124 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createEvent = createEvent;
exports.createEvents = createEvents;

var _v = require('uuid/v4');

var _v2 = _interopRequireDefault(_v);

var _pipeline = require('./pipeline');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function assignUniqueId(event) {
event.uid = event.uid || (0, _v2.default)();
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 createEvent(attributes, cb) {
if (!attributes) {
Error('Attributes argument is required');
}

if (!cb) {
// No callback, so return error or value in an object
var _validateEvent = (0, _pipeline.validateEvent)((0, _pipeline.buildEvent)(attributes)),
_error = _validateEvent.error,
_value = _validateEvent.value;

if (_error) return { error: _error, value: _value };

var event = '';

try {
event = (0, _pipeline.formatEvent)(_value);
} catch (error) {
return { error: error, value: null };
}

return { error: null, value: event };
}

// Return a node-style callback

var _validateEvent2 = (0, _pipeline.validateEvent)((0, _pipeline.buildEvent)(attributes)),
error = _validateEvent2.error,
value = _validateEvent2.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 (events.length === 1) {
return createEvent(events[0], cb);
}

var _events$map$map$map$r = events.map(assignUniqueId).map(applyInitialFormatting).map(reformatEventsByPosition).reduce(catenateEvents, { error: null, value: null }),
error = _events$map$map$map$r.error,
value = _events$map$map$map$r.value;

if (!cb) {
return { error: error, value: value };
}

return cb(error, value);
}
46 changes: 46 additions & 0 deletions dist/pipeline/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = buildEvent;

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _defaults = require('../defaults');

var _defaults2 = _interopRequireDefault(_defaults);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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,
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;

// fill in default values where necessary

var output = Object.assign({}, _defaults2.default, attributes);

// remove falsey values
var cleanOutput = _lodash2.default.pickBy(output, _lodash2.default.identity);

return cleanOutput;
}
87 changes: 87 additions & 0 deletions dist/pipeline/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = formatEvent;

var _utils = require('../utils');

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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,
timestamp = attributes.timestamp,
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;


var icsFormat = '';
icsFormat += 'BEGIN:VCALENDAR\r\n';
icsFormat += 'VERSION:2.0\r\n';
icsFormat += 'CALSCALE:GREGORIAN\r\n';
icsFormat += (0, _utils.foldLine)('PRODID:' + productId) + '\r\n';
icsFormat += (0, _utils.foldLine)('METHOD:' + method) + '\r\n';
icsFormat += 'X-PUBLISHED-TTL:PT1H\r\n';
icsFormat += 'BEGIN:VEVENT\r\n';
icsFormat += 'UID:' + uid + '\r\n';
icsFormat += (0, _utils.foldLine)('SUMMARY:' + (title ? (0, _utils.setSummary)(title) : title)) + '\r\n';
icsFormat += 'DTSTAMP:' + timestamp + '\r\n';

// All day events like anniversaries must be specified as VALUE type DATE
icsFormat += 'DTSTART' + (start && start.length == 3 ? ";VALUE=DATE" : "") + ':' + (0, _utils.setDate)(start, startType) + '\r\n';

// End is not required for all day events on single days (like anniversaries)
if (!(_lodash2.default.isEqual(start, end) && end && end.length == 3)) {
if (end && end.length == 3) {
icsFormat += 'DTEND;VALUE=DATE:' + (0, _utils.setDate)(end, startType) + '\r\n';
} else if (end) {
icsFormat += 'DTEND:' + (0, _utils.setDate)(end, startType) + '\r\n';
}
}

icsFormat += description ? (0, _utils.foldLine)('DESCRIPTION:' + (0, _utils.setDescription)(description)) + '\r\n' : '';
icsFormat += url ? (0, _utils.foldLine)('URL:' + url) + '\r\n' : '';
icsFormat += geo ? (0, _utils.foldLine)('GEO:' + (0, _utils.setGeolocation)(geo)) + '\r\n' : '';
icsFormat += location ? (0, _utils.foldLine)('LOCATION:' + location) + '\r\n' : '';
icsFormat += status ? (0, _utils.foldLine)('STATUS:' + status) + '\r\n' : '';
icsFormat += categories ? (0, _utils.foldLine)('CATEGORIES:' + categories) + '\r\n' : '';
icsFormat += organizer ? (0, _utils.foldLine)('ORGANIZER;' + (0, _utils.setOrganizer)(organizer)) + '\r\n' : '';

if (attendees) {
attendees.map(function (attendee) {
icsFormat += (0, _utils.foldLine)('ATTENDEE;' + (0, _utils.setContact)(attendee)) + '\r\n';
});
}

if (alarms) {
alarms.map(function (alarm) {
icsFormat += (0, _utils.setAlarm)(alarm);
});
}

icsFormat += duration ? 'DURATION:' + (0, _utils.formatDuration)(duration) + '\r\n' : '';
icsFormat += 'END:VEVENT\r\n';
icsFormat += 'END:VCALENDAR\r\n';

return icsFormat;
}
24 changes: 24 additions & 0 deletions dist/pipeline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateEvent = exports.formatEvent = exports.buildEvent = undefined;

var _build = require('./build');

var _build2 = _interopRequireDefault(_build);

var _format = require('./format');

var _format2 = _interopRequireDefault(_format);

var _validate = require('./validate');

var _validate2 = _interopRequireDefault(_validate);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.buildEvent = _build2.default;
exports.formatEvent = _format2.default;
exports.validateEvent = _validate2.default;
13 changes: 13 additions & 0 deletions dist/pipeline/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _schema = require('../schema');

var _schema2 = _interopRequireDefault(_schema);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = _schema2.default;
Loading

0 comments on commit fc8c1bc

Please sign in to comment.