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

moment-range

Package Overview
Dependencies
Maintainers
5
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-range - npm Package Compare versions

Comparing version 3.1.0 to 3.1.1

dist/.DS_Store

4

CHANGELOG.md

@@ -10,2 +10,6 @@ # Moment Range

## [3.1.1]
### Fixed
* Fixed intersection rules for zero-length ranges on start/end boundaries
## [3.1.0]

@@ -12,0 +16,0 @@ ### Added

193

dist/moment-range.js

@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

root["moment-range"] = factory(root["moment"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -77,3 +77,3 @@ /******/ // The module cache

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })

@@ -88,13 +88,27 @@ /************************************************************************/

module.exports = __webpack_require__(16)() ? Symbol : __webpack_require__(18);
var _undefined = __webpack_require__(5)(); // Support ES3 engines
module.exports = function (val) {
return (val !== _undefined) && (val !== null);
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
module.exports = __webpack_require__(18)() ? Symbol : __webpack_require__(20);
/***/ }),
/* 2 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ }),
/* 2 */
/* 3 */
/***/ (function(module, exports, __webpack_require__) {

@@ -118,7 +132,7 @@

var _moment = __webpack_require__(1);
var _moment = __webpack_require__(2);
var _moment2 = _interopRequireDefault(_moment);
var _es6Symbol = __webpack_require__(0);
var _es6Symbol = __webpack_require__(1);

@@ -305,12 +319,34 @@ var _es6Symbol2 = _interopRequireDefault(_es6Symbol);

var end = this.end.valueOf();
var oStart = other.start.valueOf();
var oEnd = other.end.valueOf();
var otherStart = other.start.valueOf();
var otherEnd = other.end.valueOf();
var isZeroLength = start == end;
var isOtherZeroLength = otherStart == otherEnd;
if (start <= oStart && oStart < end && end < oEnd) {
return new this.constructor(oStart, end);
} else if (oStart < start && start < oEnd && oEnd <= end) {
return new this.constructor(start, oEnd);
} else if (oStart < start && start <= end && end < oEnd) {
// Zero-length ranges
if (isZeroLength) {
var point = start;
if (point == otherStart || point == otherEnd) {
return null;
} else if (point > otherStart && point < otherEnd) {
return this;
}
} else if (isOtherZeroLength) {
var _point = otherStart;
if (_point == start || _point == end) {
return null;
} else if (_point > start && _point < end) {
return other;
}
}
// Non zero-length ranges
if (start <= otherStart && otherStart < end && end < otherEnd) {
return new this.constructor(otherStart, end);
} else if (otherStart < start && start < otherEnd && otherEnd <= end) {
return new this.constructor(start, otherEnd);
} else if (otherStart < start && start <= end && end < otherEnd) {
return this;
} else if (start <= oStart && oStart <= oEnd && oEnd <= end) {
} else if (start <= otherStart && otherStart <= otherEnd && otherEnd <= end) {
return other;

@@ -542,3 +578,3 @@ }

/***/ }),
/* 3 */
/* 4 */
/***/ (function(module, exports, __webpack_require__) {

@@ -549,6 +585,6 @@

var assign = __webpack_require__(4)
, normalizeOpts = __webpack_require__(11)
, isCallable = __webpack_require__(7)
, contains = __webpack_require__(13)
var assign = __webpack_require__(6)
, normalizeOpts = __webpack_require__(13)
, isCallable = __webpack_require__(9)
, contains = __webpack_require__(15)

@@ -614,3 +650,3 @@ , d;

/***/ }),
/* 4 */
/* 5 */
/***/ (function(module, exports, __webpack_require__) {

@@ -621,9 +657,20 @@

module.exports = __webpack_require__(5)()
// eslint-disable-next-line no-empty-function
module.exports = function () {};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
module.exports = __webpack_require__(7)()
? Object.assign
: __webpack_require__(6);
: __webpack_require__(8);
/***/ }),
/* 5 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {

@@ -636,6 +683,6 @@

var assign = Object.assign, obj;
if (typeof assign !== 'function') return false;
obj = { foo: 'raz' };
assign(obj, { bar: 'dwa' }, { trzy: 'trzy' });
return (obj.foo + obj.bar + obj.trzy) === 'razdwatrzy';
if (typeof assign !== "function") return false;
obj = { foo: "raz" };
assign(obj, { bar: "dwa" }, { trzy: "trzy" });
return (obj.foo + obj.bar + obj.trzy) === "razdwatrzy";
};

@@ -645,3 +692,3 @@

/***/ }),
/* 6 */
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

@@ -652,16 +699,17 @@

var keys = __webpack_require__(8)
, value = __webpack_require__(12)
var keys = __webpack_require__(10)
, value = __webpack_require__(14)
, max = Math.max;
, max = Math.max;
module.exports = function (dest, src/*, …srcn*/) {
var error, i, l = max(arguments.length, 2), assign;
module.exports = function (dest, src /*, …srcn*/) {
var error, i, length = max(arguments.length, 2), assign;
dest = Object(value(dest));
assign = function (key) {
try { dest[key] = src[key]; } catch (e) {
try {
dest[key] = src[key];
} catch (e) {
if (!error) error = e;
}
};
for (i = 1; i < l; ++i) {
for (i = 1; i < length; ++i) {
src = arguments[i];

@@ -676,3 +724,3 @@ keys(src).forEach(assign);

/***/ }),
/* 7 */
/* 9 */
/***/ (function(module, exports, __webpack_require__) {

@@ -685,7 +733,9 @@

module.exports = function (obj) { return typeof obj === 'function'; };
module.exports = function (obj) {
return typeof obj === "function";
};
/***/ }),
/* 8 */
/* 10 */
/***/ (function(module, exports, __webpack_require__) {

@@ -696,9 +746,9 @@

module.exports = __webpack_require__(9)()
module.exports = __webpack_require__(11)()
? Object.keys
: __webpack_require__(10);
: __webpack_require__(12);
/***/ }),
/* 9 */
/* 11 */
/***/ (function(module, exports, __webpack_require__) {

@@ -711,5 +761,7 @@

try {
Object.keys('primitive');
Object.keys("primitive");
return true;
} catch (e) { return false; }
} catch (e) {
return false;
}
};

@@ -719,3 +771,3 @@

/***/ }),
/* 10 */
/* 12 */
/***/ (function(module, exports, __webpack_require__) {

@@ -726,6 +778,8 @@

var isValue = __webpack_require__(0);
var keys = Object.keys;
module.exports = function (object) {
return keys(object == null ? object : Object(object));
return keys(isValue(object) ? Object(object) : object);
};

@@ -735,3 +789,3 @@

/***/ }),
/* 11 */
/* 13 */
/***/ (function(module, exports, __webpack_require__) {

@@ -742,2 +796,4 @@

var isValue = __webpack_require__(0);
var forEach = Array.prototype.forEach, create = Object.create;

@@ -750,6 +806,7 @@

module.exports = function (options/*, …options*/) {
// eslint-disable-next-line no-unused-vars
module.exports = function (opts1 /*, …options*/) {
var result = create(null);
forEach.call(arguments, function (options) {
if (options == null) return;
if (!isValue(options)) return;
process(Object(options), result);

@@ -762,3 +819,3 @@ });

/***/ }),
/* 12 */
/* 14 */
/***/ (function(module, exports, __webpack_require__) {

@@ -769,4 +826,6 @@

var isValue = __webpack_require__(0);
module.exports = function (value) {
if (value == null) throw new TypeError("Cannot use null or undefined");
if (!isValue(value)) throw new TypeError("Cannot use null or undefined");
return value;

@@ -777,3 +836,3 @@ };

/***/ }),
/* 13 */
/* 15 */
/***/ (function(module, exports, __webpack_require__) {

@@ -784,9 +843,9 @@

module.exports = __webpack_require__(14)()
module.exports = __webpack_require__(16)()
? String.prototype.contains
: __webpack_require__(15);
: __webpack_require__(17);
/***/ }),
/* 14 */
/* 16 */
/***/ (function(module, exports, __webpack_require__) {

@@ -797,7 +856,7 @@

var str = 'razdwatrzy';
var str = "razdwatrzy";
module.exports = function () {
if (typeof str.contains !== 'function') return false;
return ((str.contains('dwa') === true) && (str.contains('foo') === false));
if (typeof str.contains !== "function") return false;
return (str.contains("dwa") === true) && (str.contains("foo") === false);
};

@@ -807,3 +866,3 @@

/***/ }),
/* 15 */
/* 17 */
/***/ (function(module, exports, __webpack_require__) {

@@ -822,3 +881,3 @@

/***/ }),
/* 16 */
/* 18 */
/***/ (function(module, exports, __webpack_require__) {

@@ -847,3 +906,3 @@

/***/ }),
/* 17 */
/* 19 */
/***/ (function(module, exports, __webpack_require__) {

@@ -864,3 +923,3 @@

/***/ }),
/* 18 */
/* 20 */
/***/ (function(module, exports, __webpack_require__) {

@@ -873,4 +932,4 @@

var d = __webpack_require__(3)
, validateSymbol = __webpack_require__(19)
var d = __webpack_require__(4)
, validateSymbol = __webpack_require__(21)

@@ -991,3 +1050,3 @@ , create = Object.create, defineProperties = Object.defineProperties

/***/ }),
/* 19 */
/* 21 */
/***/ (function(module, exports, __webpack_require__) {

@@ -998,3 +1057,3 @@

var isSymbol = __webpack_require__(17);
var isSymbol = __webpack_require__(19);

@@ -1001,0 +1060,0 @@ module.exports = function (value) {

@@ -753,2 +753,40 @@ /**

});
it('should not overlap zero-length ranges on the start date when `adjacent` is `false`', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const range1 = moment.range(a, a);
const range2 = moment.range(a, b);
expect(range1.overlaps(range2)).to.be(false);
expect(range1.overlaps(range2, { adjacent: false })).to.be(false);
});
it('should overlap zero-length ranges on the start date when `adjacent` is `true`', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const range1 = moment.range(a, a);
const range2 = moment.range(a, b);
expect(range1.overlaps(range2, { adjacent: true })).to.be(true);
});
it('should not overlap zero-length ranges on the end date when `adjacent` is `false`', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const range1 = moment.range(a, b);
const range2 = moment.range(b, b);
expect(range1.overlaps(range2)).to.be(false);
expect(range1.overlaps(range2, { adjacent: false })).to.be(false);
});
it('should overlap zero-length ranges on the end date when `adjacent` is `true`', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const range1 = moment.range(a, b);
const range2 = moment.range(b, b);
expect(range1.overlaps(range2, { adjacent: true })).to.be(true);
});
});

@@ -858,2 +896,38 @@

});
it('should return `null` with [---{}] non-overlaps where (a=[], b={})', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const dr1 = moment.range(a, b);
const dr2 = moment.range(b, b);
expect(dr1.intersect(dr2)).to.be(null);
});
it('should return `null` with [{}---] non-overlaps where (a=[], b={})', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const dr1 = moment.range(a, b);
const dr2 = moment.range(a, a);
expect(dr1.intersect(dr2)).to.be(null);
});
it('should return `null` with {---[]} non-overlaps where (a=[], b={})', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const dr1 = moment.range(b, b);
const dr2 = moment.range(a, b);
expect(dr1.intersect(dr2)).to.be(null);
});
it('should return `null` with {[]---} non-overlaps where (a=[], b={})', function() {
const a = moment.utc('2018-02-01T03:00:00');
const b = moment.utc('2018-02-01T13:00:00');
const dr1 = moment.range(a, a);
const dr2 = moment.range(a, b);
expect(dr1.intersect(dr2)).to.be(null);
});
});

@@ -860,0 +934,0 @@

@@ -157,15 +157,40 @@ import moment from 'moment';

const end = this.end.valueOf();
const oStart = other.start.valueOf();
const oEnd = other.end.valueOf();
const otherStart = other.start.valueOf();
const otherEnd = other.end.valueOf();
const isZeroLength = (start == end);
const isOtherZeroLength = (otherStart == otherEnd);
if ((start <= oStart) && (oStart < end) && (end < oEnd)) {
return new this.constructor(oStart, end);
// Zero-length ranges
if (isZeroLength) {
const point = start;
if ((point == otherStart) || (point == otherEnd)) {
return null;
}
else if ((point > otherStart) && (point < otherEnd)) {
return this;
}
}
else if ((oStart < start) && (start < oEnd) && (oEnd <= end)) {
return new this.constructor(start, oEnd);
else if (isOtherZeroLength) {
const point = otherStart;
if ((point == start) || (point == end)) {
return null;
}
else if ((point > start) && (point < end)) {
return other;
}
}
else if ((oStart < start) && (start <= end) && (end < oEnd)) {
// Non zero-length ranges
if ((start <= otherStart) && (otherStart < end) && (end < otherEnd)) {
return new this.constructor(otherStart, end);
}
else if ((otherStart < start) && (start < otherEnd) && (otherEnd <= end)) {
return new this.constructor(start, otherEnd);
}
else if ((otherStart < start) && (start <= end) && (end < otherEnd)) {
return this;
}
else if ((start <= oStart) && (oStart <= oEnd) && (oEnd <= end)) {
else if ((start <= otherStart) && (otherStart <= otherEnd) && (otherEnd <= end)) {
return other;

@@ -172,0 +197,0 @@ }

@@ -31,3 +31,3 @@ {

"jsnext:main": "lib/moment-range.js",
"version": "3.1.0",
"version": "3.1.1",
"engines": {

@@ -34,0 +34,0 @@ "node": "*"

Sorry, the diff of this file is not supported yet

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