Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

availability

Package Overview
Dependencies
Maintainers
1
Versions
944
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

availability - npm Package Compare versions

Comparing version 2.1.81 to 2.1.82

dist/AvailabilityIterator.js

1041

dist/index.js

@@ -1,1035 +0,20 @@

(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
"use strict";
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Status = exports.DisjunctiveAvailabilityIterator = exports.AvailabilityIterator = undefined;
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
var _AvailabilityIterator = require("./AvailabilityIterator");
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
var _DisjunctiveAvailabilityIterator = require("./DisjunctiveAvailabilityIterator");
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
var _Status = require("./Status");
/******/ // Flag the module as loaded
/******/ module.loaded = true;
var Status = _interopRequireWildcard(_Status);
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Status = exports.DisjunctiveAvailabilityIterator = exports.AvailabilityIterator = undefined;
var _AvailabilityIterator = __webpack_require__(2);
var _DisjunctiveAvailabilityIterator = __webpack_require__(12);
var _Status = __webpack_require__(6);
var Status = _interopRequireWildcard(_Status);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
exports.AvailabilityIterator = _AvailabilityIterator.AvailabilityIterator;
exports.DisjunctiveAvailabilityIterator = _DisjunctiveAvailabilityIterator.DisjunctiveAvailabilityIterator;
exports.Status = Status;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AvailabilityIterator = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _MergingStatusIterator = __webpack_require__(3);
var _TimeWindowsIterator = __webpack_require__(4);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var AvailabilityIterator = exports.AvailabilityIterator = function () {
function AvailabilityIterator(_ref) {
var availability = _ref.availability;
var cal = _ref.cal;
_classCallCheck(this, AvailabilityIterator);
availability = availability || null; // availability.Availability
cal = cal || null; // Moment with tz
this._it = new _MergingStatusIterator.MergingStatusIterator({
it: new _TimeWindowsIterator.TimeWindowsIterator({
availability: availability,
cal: cal
})
});
}
/** @return Boolean */
_createClass(AvailabilityIterator, [{
key: "hasNext",
value: function hasNext() {
return this._it.hasNext();
}
/** @return Status */
}, {
key: "next",
value: function next() {
return this._it.next();
}
}]);
return AvailabilityIterator;
}();
/***/ },
/* 3 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var MergingStatusIterator = exports.MergingStatusIterator = function () {
function MergingStatusIterator(_ref) {
var it = _ref.it;
var maxIterations = _ref.maxIterations;
_classCallCheck(this, MergingStatusIterator);
it = it || null; // Iterator<Status>
maxIterations = maxIterations || null; // Int
this._it = it;
this._maxIterations = maxIterations;
this._nextStatus = this._it !== null && this._it.hasNext() ? this._it.next() : null;
}
_createClass(MergingStatusIterator, [{
key: "hasNext",
value: function hasNext() {
return this._nextStatus != null;
}
/** @return Status */
}, {
key: "next",
value: function next() {
var mergedStatus = this._nextStatus;
var iteration = 0;
while (true) {
if (!this._it.hasNext()) {
this._nextStatus = null;
break;
}
this._nextStatus = this._it.next();
if (!this._statusEqualsIgnoreUntil(this._nextStatus, mergedStatus)) {
break;
}
mergedStatus.until = this._nextStatus.until;
if (this._maxIterations !== null && iteration++ >= this._maxIterations) {
break;
}
}
return mergedStatus;
}
}, {
key: "_stringMapEquals",
value: function _stringMapEquals(map1, map2) {
if (!map1) {
return map2 ? false : true;
} else if (!map2) {
return false;
}
for (var key in map1) {
if (map1[key] !== map2[key]) {
return false;
}
}
for (var _key in map2) {
if (map2[_key] !== map1[_key]) {
return false;
}
}
return true;
}
}, {
key: "_statusEqualsIgnoreUntil",
value: function _statusEqualsIgnoreUntil(status1, status2) {
return status1.status === status2.status && status1.reason === status2.reason && this._stringMapEquals(status1.comment, status2.comment);
}
}]);
return MergingStatusIterator;
}();
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TimeWindowsIterator = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _WeeklyTimeWindowsIterator = __webpack_require__(5);
var _DateTimeWindowsIterator = __webpack_require__(9);
var _Status = __webpack_require__(6);
var Status = _interopRequireWildcard(_Status);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TimeWindowsIterator = exports.TimeWindowsIterator = function () {
function TimeWindowsIterator(_ref) {
var availability = _ref.availability;
var cal = _ref.cal;
_classCallCheck(this, TimeWindowsIterator);
availability = availability || {}; // availability.Availability
cal = cal || null; // Moment with tz
this._regularIt = new _WeeklyTimeWindowsIterator.WeeklyTimeWindowsIterator({
cal: cal,
weekly: availability.weekly
});
this._exceptionsIt = new _DateTimeWindowsIterator.DateTimeWindowsIterator({
cal: cal,
timeWindows: availability.exceptions
});
// TimeWindow iterators always return at least one element
this._regularStatus = this._regularIt.next();
this._exceptionStatus = this._exceptionsIt.next();
this._hasNext = true;
}
/** @return Boolean */
_createClass(TimeWindowsIterator, [{
key: "hasNext",
value: function hasNext() {
return this._hasNext;
}
/** @return Status */
}, {
key: "next",
value: function next() {
// Future has no exceptions?
if (this._exceptionStatus.status === Status.STATUS_UNKNOWN && !this._exceptionStatus.until) {
// Continue with regular statuses
var lastRegularStatus = this._regularStatus;
if (this._regularIt.hasNext()) {
this._regularStatus = this._regularIt.next();
} else {
this._hasNext = false;
}
return lastRegularStatus;
}
// So we do have real exceptions to deal with
// Real exceptions take precedent
if (Status.STATUS_UNKNOWN !== this._exceptionStatus.status) {
// If the exception is indefinite, it trumps everything else
if (!this._exceptionStatus.until) {
this._hasNext = false;
return this._exceptionStatus;
}
var lastExceptionStatus = this._exceptionStatus;
this._exceptionStatus = this._exceptionsIt.next(); // we know there are still real exceptions later
while (this._regularStatus.until && this._regularStatus.until <= lastExceptionStatus.until) {
this._regularStatus = this._regularIt.next();
}
return lastExceptionStatus;
}
// No real exception this time
if (!this._regularStatus.until || this._regularStatus.until > this._exceptionStatus.until) {
var _lastExceptionStatus = this._exceptionStatus;
this._exceptionStatus = this._exceptionsIt.next(); // we know there are still real exceptions later
return {
status: this._regularStatus.status,
until: _lastExceptionStatus.until
};
} else if (this._regularStatus.until < this._exceptionStatus.until) {
var _lastRegularStatus = this._regularStatus;
this._regularStatus = this._regularIt.next(); // we know there are still regular statuses later
return _lastRegularStatus;
} else {
this._exceptionStatus = this._exceptionsIt.next(); // we know there are still real exceptions later
var _lastRegularStatus2 = this._regularStatus;
this._regularStatus = this._regularIt.next(); // we know there are still regular statuses later
return _lastRegularStatus2;
}
}
}]);
return TimeWindowsIterator;
}();
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WeeklyTimeWindowsIterator = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Status = __webpack_require__(6);
var Status = _interopRequireWildcard(_Status);
var _Period = __webpack_require__(7);
var _WeeklyTimeWindow = __webpack_require__(8);
var WeeklyTimeWindow = _interopRequireWildcard(_WeeklyTimeWindow);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var WeeklyTimeWindowsIterator = exports.WeeklyTimeWindowsIterator = function () {
function WeeklyTimeWindowsIterator(_ref) {
var weekly = _ref.weekly;
var cal = _ref.cal;
_classCallCheck(this, WeeklyTimeWindowsIterator);
weekly = weekly || []; // List<WeeklyTimeWindow>
cal = cal || null; // Moment with tz
this._cal = cal.clone(); // "cal" is modified later, this allows the caller to reuse his version of it
this._hasNext = true;
this._timeWindows = [];
this._isFirstAndLastSame = null;
if (weekly.length === 0) {
this._timeWindows.push({
minuteOfWeek: 0,
durationMins: WeeklyTimeWindow.WEEK,
status: Status.STATUS_AVAILABLE
});
this._isFirstAndLastSame = true;
} else {
var minuteOfWeek = 0;
for (var i = 0, l = weekly.length; i < l; ++i) {
var timeWindow = weekly[i];
if (timeWindow.minuteOfWeek > minuteOfWeek) {
this._timeWindows.push({
minuteOfWeek: minuteOfWeek,
durationMins: timeWindow.minuteOfWeek - minuteOfWeek,
status: Status.STATUS_UNAVAILABLE
});
}
this._timeWindows.push({
minuteOfWeek: timeWindow.minuteOfWeek,
durationMins: timeWindow.durationMins,
status: Status.STATUS_AVAILABLE
});
minuteOfWeek = this._endMinuteOfWeek(timeWindow);
}
if (minuteOfWeek < WeeklyTimeWindow.WEEK) {
this._timeWindows.push({
minuteOfWeek: minuteOfWeek,
durationMins: WeeklyTimeWindow.WEEK - minuteOfWeek,
status: Status.STATUS_UNAVAILABLE
});
}
var firstWindow = this._timeWindows[0];
var lastWindow = this._timeWindows[this._timeWindows.length - 1];
this._isFirstAndLastSame = firstWindow.status === lastWindow.status;
}
this._isConstant = this._timeWindows.length === 1;
}
/**
* @param timeWindow WeeklyTimeWindow
* @return Integer
*/
_createClass(WeeklyTimeWindowsIterator, [{
key: "_endMinuteOfWeek",
value: function _endMinuteOfWeek(timeWindow) {
return timeWindow.minuteOfWeek + timeWindow.durationMins;
}
/** @return Boolean */
}, {
key: "hasNext",
value: function hasNext() {
return this._hasNext;
}
/** @return Status */
}, {
key: "next",
value: function next() {
if (this._isConstant) {
this._hasNext = false;
return {
status: this._timeWindows[0].status,
until: null
};
}
var minuteOfWeek = this._minutesFromStartOfWeek(this._cal);
var currentWindow = this._timeWindows[this._find(minuteOfWeek)];
var newMinuteOfWeek = this._endMinuteOfWeek(currentWindow);
if (newMinuteOfWeek === WeeklyTimeWindow.WEEK) {
newMinuteOfWeek = this._isFirstAndLastSame ? this._endMinuteOfWeek(this._timeWindows[0]) : 0;
}
newMinuteOfWeek = this._advanceCalendar(minuteOfWeek, newMinuteOfWeek);
return {
status: currentWindow.status,
until: this._cal.valueOf()
};
}
/**
* @param oldMinuteOfWeek Integer
* @param newMinuteOfWeek Integer
* @return Integer
*/
}, {
key: "_advanceCalendar",
value: function _advanceCalendar(oldMinuteOfWeek, newMinuteOfWeek) {
var minutesToAdvance = newMinuteOfWeek - oldMinuteOfWeek;
if (minutesToAdvance < 0) {
minutesToAdvance += WeeklyTimeWindow.WEEK;
}
// The craziness ahead is required to support DST (causing some dates to be invalid)
var targetDate = new _Period.Period({
days: this._cal.date(),
hours: this._cal.hour(),
minutes: this._cal.minute()
}).plusMinutes(minutesToAdvance).normalizedStandard();
while (true) {
this._cal.date(targetDate.getDays());
this._cal.hour(targetDate.getHours());
this._cal.minute(targetDate.getMinutes());
this._cal.second(0);
this._cal.millisecond(0);
if (this._cal.hour() === targetDate.getHours() && this._cal.minute() === targetDate.getMinutes()) {
break;
}
targetDate = targetDate.plusMinutes(1).normalizedStandard();
++newMinuteOfWeek;
}
return newMinuteOfWeek;
}
/**
* @param minuteOfWeek Integer
* @return Integer index in _timeWindows member
*/
}, {
key: "_find",
value: function _find(minuteOfWeek) {
// _timeWindows are assumed to be sorted, so we can use binary search
var low = 0;
var high = this._timeWindows.length;
while (low < high) {
var mid = low + high >>> 1;
var midValue = this._endMinuteOfWeek(this._timeWindows[mid]);
if (midValue <= minuteOfWeek) {
low = mid + 1;
} else {
high = mid;
}
}
return low;
}
/**
* @param cal Moment with tz
* @return Integer
*/
}, {
key: "_minutesFromStartOfWeek",
value: function _minutesFromStartOfWeek(cal) {
return (cal.day() - WeeklyTimeWindow.SUNDAY) * WeeklyTimeWindow.DAY + cal.hour() * WeeklyTimeWindow.HOUR + cal.minute();
}
}]);
return WeeklyTimeWindowsIterator;
}();
/***/ },
/* 6 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var STATUS_UNAVAILABLE = exports.STATUS_UNAVAILABLE = "unavailable";
var STATUS_AVAILABLE = exports.STATUS_AVAILABLE = "available";
var STATUS_UNKNOWN = exports.STATUS_UNKNOWN = "unknown";
/***/ },
/* 7 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Period = exports.Period = function () {
function Period(_ref) {
var days = _ref.days;
var hours = _ref.hours;
var minutes = _ref.minutes;
_classCallCheck(this, Period);
this.days = days || 0;
this.hours = hours || 0;
this.minutes = minutes || 0;
}
_createClass(Period, [{
key: "getDays",
value: function getDays() {
return this.days;
}
}, {
key: "getHours",
value: function getHours() {
return this.hours;
}
}, {
key: "getMinutes",
value: function getMinutes() {
return this.minutes;
}
}, {
key: "toStandardMinutes",
value: function toStandardMinutes() {
return (this.days * 24 + this.hours) * 60 + this.minutes;
}
}, {
key: "plus",
value: function plus(_ref2) {
var days = _ref2.days;
var hours = _ref2.hours;
var minutes = _ref2.minutes;
return new Period({
days: this.days + (days || 0),
hours: this.hours + (hours || 0),
minutes: this.minutes + (minutes || 0)
});
}
}, {
key: "plusMinutes",
value: function plusMinutes(minutesDiff) {
return this.plus({
minutes: minutesDiff
});
}
}, {
key: "normalizedStandard",
value: function normalizedStandard() {
var normalizedDays = this.days;
var normalizedHours = this.hours;
var normalizedMinutes = this.minutes;
var extraHours = Math.floor(normalizedMinutes / 60);
normalizedMinutes -= 60 * extraHours;
normalizedHours += extraHours;
var extraDays = Math.floor(normalizedHours / 24);
normalizedHours -= 24 * extraDays;
normalizedDays += extraDays;
return new Period({
days: normalizedDays,
hours: normalizedHours,
minutes: normalizedMinutes
});
}
}]);
return Period;
}();
/***/ },
/* 8 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var HOUR = exports.HOUR = 60;
var DAY = exports.DAY = HOUR * 24;
var WEEK = exports.WEEK = DAY * 7;
var SUNDAY = exports.SUNDAY = DAY * 0;
var MONDAY = exports.MONDAY = DAY * 1;
var TUESDAY = exports.TUESDAY = DAY * 2;
var WEDNESDAY = exports.WEDNESDAY = DAY * 3;
var THURSDAY = exports.THURSDAY = DAY * 4;
var FRIDAY = exports.FRIDAY = DAY * 5;
var SATURDAY = exports.SATURDAY = DAY * 6;
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DateTimeWindowsIterator = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _Status = __webpack_require__(6);
var Status = _interopRequireWildcard(_Status);
var _DateTimeWindowsUtils = __webpack_require__(10);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DateTimeWindowsIterator = exports.DateTimeWindowsIterator = function () {
function DateTimeWindowsIterator(_ref) {
var timeWindows = _ref.timeWindows;
var cal = _ref.cal;
_classCallCheck(this, DateTimeWindowsIterator);
timeWindows = timeWindows || []; // List<DateTimeWindow>
cal = cal || null; // Moment with tz
this._timeWindows = timeWindows;
this._tz = cal.tz();
this._index = null;
this._lastWindowUntilForever = null;
if (this._timeWindows.length > 0) {
this._index = (0, _DateTimeWindowsUtils.findInsertionIndex)(this._timeWindows, cal.valueOf(), this._tz);
this._lastWindowUntilForever = !timeWindows[this._timeWindows.length - 1].end;
} else {
this._index = new _DateTimeWindowsUtils.Index(0, true);
this._lastWindowUntilForever = false;
}
}
/** @return Boolean */
_createClass(DateTimeWindowsIterator, [{
key: "hasNext",
value: function hasNext() {
if (this._index.index < this._timeWindows.length) {
return true;
}
return this._index.isDummyBefore && !this._lastWindowUntilForever;
}
/** @return Status */
}, {
key: "next",
value: function next() {
var result = void 0;
if (this._index.index === this._timeWindows.length) {
result = {
status: Status.STATUS_UNKNOWN,
until: null
};
} else {
var nextTimeWindow = this._timeWindows[this._index.index];
if (!this._index.isDummyBefore) {
result = {
status: nextTimeWindow.available ? Status.STATUS_AVAILABLE : Status.STATUS_UNAVAILABLE,
until: (0, _DateTimeWindowsUtils.getTime)(nextTimeWindow.end, this._tz),
reason: nextTimeWindow.reason,
comment: nextTimeWindow.comment
};
} else {
result = {
status: Status.STATUS_UNKNOWN,
until: (0, _DateTimeWindowsUtils.getTime)(nextTimeWindow.start, this._tz)
};
}
}
this._index.advance();
return result;
}
}]);
return DateTimeWindowsIterator;
}();
/***/ },
/* 10 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Index = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.findInsertionIndex = findInsertionIndex;
exports.getTime = getTime;
exports.strictlyBefore = strictlyBefore;
var _momentTimezone = __webpack_require__(11);
var _momentTimezone2 = _interopRequireDefault(_momentTimezone);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Index = exports.Index = function () {
/**
* @param index Integer
* @param isDummyBefore Boolean
*/
function Index(index, isDummyBefore) {
_classCallCheck(this, Index);
this.index = index;
this.isDummyBefore = isDummyBefore;
}
_createClass(Index, [{
key: "advance",
value: function advance() {
if (this.isDummyBefore) {
this.isDummyBefore = false;
} else {
this.isDummyBefore = true;
++this.index;
}
}
}]);
return Index;
}();
/**
* @param timeWindows List<DateTimeWindow>
* @param timestamp Long
* @param tz Timezone
* @return Index
*/
function findInsertionIndex(timeWindows, timestamp, tz) {
// TODO: use binary search
for (var i = 0, l = timeWindows.length; i < l; ++i) {
var timeWindow = timeWindows[i];
var c = compare(timestamp, timeWindow, tz);
if (c < 0) {
return new Index(i, true);
}if (c === 0) {
return new Index(i, false);
}
}
return new Index(timeWindows.length, true);
}
/**
* @param date availability.Date
* @return Long
*/
function getTime(date, tz) {
if (!date) {
return null;
}
return _momentTimezone2.default.tz([date.year, date.month - 1, date.day, date.hour, date.minute], tz).valueOf();
}
function strictlyBefore(window1EndTs, window2StartTs) {
if (window1EndTs === null || window2StartTs === null) {
return false;
}
return window1EndTs <= window2StartTs;
}
function compare(timestamp, timeWindow, tz) {
if (strictlyBefore(timestamp + 1000, getTime(timeWindow.start, tz))) {
return -1;
} else if (strictlyBefore(getTime(timeWindow.end, tz), timestamp)) {
return 1;
} else {
return 0;
}
}
/***/ },
/* 11 */
/***/ function(module, exports) {
module.exports = require("moment-timezone");
/***/ },
/* 12 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DisjunctiveAvailabilityIterator = exports.DisjunctiveTimeWindowsIterator = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _AvailabilityIterator = __webpack_require__(2);
var _MergingStatusIterator = __webpack_require__(3);
var _DateTimeWindowsUtils = __webpack_require__(10);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DisjunctiveTimeWindowsIterator = exports.DisjunctiveTimeWindowsIterator = function () {
function DisjunctiveTimeWindowsIterator(_ref) {
var _this = this;
var availabilities = _ref.availabilities;
var cal = _ref.cal;
_classCallCheck(this, DisjunctiveTimeWindowsIterator);
availabilities = availabilities || []; // List<availability.Availability>
cal = cal || null; // Moment with tz
this._now = cal.valueOf();
this._nextStatus = null;
this._wrapped = [];
availabilities.forEach(function (availability) {
var it = new _AvailabilityIterator.AvailabilityIterator({ availability: availability, cal: cal });
_this._wrapped.push({
it: it,
nextStatus: it.next() // There's always at least one status
});
});
this._advanceNextStatus();
}
/** @return Boolean */
_createClass(DisjunctiveTimeWindowsIterator, [{
key: "hasNext",
value: function hasNext() {
return this._nextStatus !== null;
}
/** @return Status */
}, {
key: "next",
value: function next() {
var nextStatus = this._nextStatus;
this._advanceNextStatus();
return nextStatus;
}
}, {
key: "_advanceNextStatus",
value: function _advanceNextStatus() {
// Last status?
if (this._nextStatus !== null && this._nextStatus.until === null) {
this._nextStatus = null;
return;
}
// Advance
var earliestUnavailableUntil = null;
for (var i = 0, l = this._wrapped.length; i < l; ++i) {
var wrapped = this._wrapped[i];
while (wrapped.nextStatus !== null && (0, _DateTimeWindowsUtils.strictlyBefore)(wrapped.nextStatus.until, this._now)) {
wrapped.nextStatus = wrapped.it.hasNext() ? wrapped.it.next() : null;
}
if (wrapped.nextStatus !== null) {
if (wrapped.nextStatus.status === "available") {
this._now = wrapped.nextStatus.until;
this._nextStatus = wrapped.nextStatus;
return;
} else {
if (wrapped.nextStatus.until !== null) {
earliestUnavailableUntil = earliestUnavailableUntil !== null ? Math.min(earliestUnavailableUntil, wrapped.nextStatus.until) : wrapped.nextStatus.until;
}
}
}
}
this._now = earliestUnavailableUntil;
this._nextStatus = {
status: "unavailable",
until: earliestUnavailableUntil
};
}
}]);
return DisjunctiveTimeWindowsIterator;
}();
var DisjunctiveAvailabilityIterator = exports.DisjunctiveAvailabilityIterator = function () {
function DisjunctiveAvailabilityIterator(_ref2) {
var availabilities = _ref2.availabilities;
var cal = _ref2.cal;
_classCallCheck(this, DisjunctiveAvailabilityIterator);
availabilities = availabilities || []; // List<availability.Availability>
cal = cal || null; // Moment with tz
this._it = new _MergingStatusIterator.MergingStatusIterator({
it: new DisjunctiveTimeWindowsIterator({ availabilities: availabilities, cal: cal }),
maxIterations: 1000
});
}
/** @return Boolean */
_createClass(DisjunctiveAvailabilityIterator, [{
key: "hasNext",
value: function hasNext() {
return this._it.hasNext();
}
/** @return Status */
}, {
key: "next",
value: function next() {
return this._it.next();
}
}]);
return DisjunctiveAvailabilityIterator;
}();
/***/ }
/******/ ])));
exports.AvailabilityIterator = _AvailabilityIterator.AvailabilityIterator;
exports.DisjunctiveAvailabilityIterator = _DisjunctiveAvailabilityIterator.DisjunctiveAvailabilityIterator;
exports.Status = Status;
{
"name": "availability",
"version": "2.1.81",
"version": "2.1.82",
"description": "Wix Restaurants Availability Utils Module",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"test": "mocha --compilers js:babel-register",
"prepublish": "npm test && webpack",
"prepublish": "npm test && babel src --out-dir dist",
"build": ":",

@@ -32,4 +32,3 @@ "release": "wnpm-release -- --no-shrinkwrap"

"devDependencies": {
"@wix/wnpm-ci": "*",
"babel": "^6.5.2",
"babel-cli": "^6.7.7",
"babel-core": "^6.7.4",

@@ -42,9 +41,10 @@ "babel-eslint": "^6.0.4",

"chai": "^3.5.0",
"mocha": "^2.4.5",
"eslint": "^2.9.0",
"eslint-plugin-react": "^5.0.1",
"mocha": "^2.4.5",
"moment": "^2.13.0",
"moment-timezone": "^0.5.3",
"webpack": "^1.12.0"
"moment-timezone": "^0.5.3"
},
"optionalDependencies": {
"@wix/wnpm-ci": "*"
},
"publishConfig": {

@@ -51,0 +51,0 @@ "registry": "https://registry.npmjs.org/"

"use strict"
import {MergingStatusIterator} from "./MergingStatusIterator.js"
import {TimeWindowsIterator} from "./TimeWindowsIterator.js"
import {MergingStatusIterator} from "./MergingStatusIterator"
import {TimeWindowsIterator} from "./TimeWindowsIterator"

@@ -6,0 +6,0 @@ export class AvailabilityIterator {

"use strict"
import * as Status from "./Status.js"
import {Index, findInsertionIndex, getTime} from "./DateTimeWindowsUtils.js"
import * as Status from "./Status"
import {Index, findInsertionIndex, getTime} from "./DateTimeWindowsUtils"

@@ -6,0 +6,0 @@ export class DateTimeWindowsIterator {

"use strict"
import {AvailabilityIterator} from "./AvailabilityIterator.js"
import {MergingStatusIterator} from "./MergingStatusIterator.js"
import {strictlyBefore} from "./DateTimeWindowsUtils.js"
import {AvailabilityIterator} from "./AvailabilityIterator"
import {MergingStatusIterator} from "./MergingStatusIterator"
import {strictlyBefore} from "./DateTimeWindowsUtils"

@@ -7,0 +7,0 @@ export class DisjunctiveTimeWindowsIterator {

"use strict"
import {WeeklyTimeWindowsIterator} from "./WeeklyTimeWindowsIterator.js"
import {DateTimeWindowsIterator} from "./DateTimeWindowsIterator.js"
import * as Status from "./Status.js"
import {WeeklyTimeWindowsIterator} from "./WeeklyTimeWindowsIterator"
import {DateTimeWindowsIterator} from "./DateTimeWindowsIterator"
import * as Status from "./Status"

@@ -7,0 +7,0 @@ export class TimeWindowsIterator {

"use strict"
import * as Status from "./Status.js"
import {Period} from "./Period.js"
import * as WeeklyTimeWindow from "./WeeklyTimeWindow.js"
import * as Status from "./Status"
import {Period} from "./Period"
import * as WeeklyTimeWindow from "./WeeklyTimeWindow"

@@ -7,0 +7,0 @@ export class WeeklyTimeWindowsIterator {

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