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

moment-range

Package Overview
Dependencies
Maintainers
1
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 0.1.7 to 1.0.0

Gruntfile.coffee

29

bower.json

@@ -1,17 +0,22 @@

{ "name": "moment-range"
, "version": "0.1.7"
, "main": "./lib/moment-range.js"
, "ignore": [
{
"name": "moment-range",
"version": "1.0.0",
"main": "./lib/moment-range.js",
"ignore": [
"**/.*",
"node_modules",
"components"
]
, "dependencies":
{ "moment": ">= 1"
],
"dependencies": {
"momentjs": ">= 1"
},
"devDependencies": {
"coffee-script": "~1",
"mocha": "1.3.0",
"should": "0.6.3",
"grunt": "~0.4.1",
"grunt-umd": "~1.3.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-mocha-test": "~0.7.0"
}
, "devDependencies":
{ "coffee-script": "~1.6"
, "mocha": "1.3.0"
, "should": "0.6.3"
}
}

@@ -1,116 +0,129 @@

// Generated by CoffeeScript 1.6.3
(function() {
var DateRange, moment;
(function(root, factory) {
if(typeof exports === 'object') {
module.exports = factory(require('moment'));
}
else if(typeof define === 'function' && define.amd) {
define('moment-range', ['moment'], factory);
}
else {
root.moment = factory(root.moment);
}
}(this, function(moment) {
/**
* DateRange class to store ranges and query dates.
* @typedef {!Object}
*
*/
moment = (typeof require !== "undefined" && require !== null) && !require.amd ? require("moment") : this.moment;
var DateRange;
DateRange = (function() {
/**
* DateRange class to store ranges and query dates.
* @typedef {!Object}
* DateRange instance.
* @param {(Moment|Date)} start Start of interval.
* @param {(Moment|Date)} end End of interval.
* @constructor
*
*/
function DateRange(start, end) {
this.start = moment(start);
this.end = moment(end);
}
DateRange = (function() {
/**
* DateRange instance.
* @param {(Moment|Date)} start Start of interval.
* @param {(Moment|Date)} end End of interval.
* @constructor
*
*/
/**
* Determine if the current interval contains a given moment/date/range.
* @param {(Moment|Date|DateRange)} other Date to check.
* @return {!boolean}
*
*/
function DateRange(start, end) {
this.start = moment(start);
this.end = moment(end);
DateRange.prototype.contains = function(other) {
if (other instanceof DateRange) {
return this.start < other.start && this.end > other.end;
} else {
return (this.start <= other && other <= this.end);
}
};
/**
* Determine if the current interval contains a given moment/date.
* @param {(Moment|Date)} moment Date to check.
* @return {!boolean}
*
*/
/**
* @private
*
*/
DateRange.prototype.contains = function(moment) {
return (this.start <= moment && moment <= this.end);
};
DateRange.prototype._by_string = function(interval, hollaback) {
var current, _results;
current = moment(this.start);
_results = [];
while (this.contains(current)) {
hollaback.call(this, current.clone());
_results.push(current.add(interval, 1));
}
return _results;
};
DateRange.prototype._by_string = function(interval, hollaback) {
var current, _results;
current = moment(this.start);
_results = [];
while (this.contains(current)) {
hollaback.call(this, current.clone());
_results.push(current.add(interval, 1));
}
return _results;
};
/**
* @private
*
*/
DateRange.prototype._by_range = function(range_interval, hollaback) {
var i, l, _i, _results;
l = Math.round(this / range_interval);
if (l === Infinity) {
return this;
}
_results = [];
for (i = _i = 0; 0 <= l ? _i <= l : _i >= l; i = 0 <= l ? ++_i : --_i) {
_results.push(hollaback.call(this, moment(this.start.valueOf() + range_interval.valueOf() * i)));
}
return _results;
};
/**
* Determine if the current date range overlaps a given date range.
* @param {DateRange} range Date range to check.
* @return {!boolean}
*
*/
DateRange.prototype._by_range = function(range_interval, hollaback) {
var i, l, _i, _results;
l = Math.round(this / range_interval);
if (l === Infinity) {
return this;
}
_results = [];
for (i = _i = 0; 0 <= l ? _i <= l : _i >= l; i = 0 <= l ? ++_i : --_i) {
_results.push(hollaback.call(this, moment(this.start.valueOf() + range_interval.valueOf() * i)));
}
return _results;
};
/**
* Determine if the current date range overlaps a given date range.
* @param {!DateRange} range Date range to check.
* @return {!boolean}
*
*/
DateRange.prototype.overlaps = function(range) {
return this.start < range.end && this.end > range.start;
};
/**
* Iterate over the date range by a given date range, executing a function
* for each sub-range.
* @param {!DateRange|String} range Date range to be used for iteration or shorthand string (shorthands: http://momentjs.com/docs/#/manipulating/add/)
* @param {!function(Moment)} hollaback Function to execute for each sub-range.
* @return {!boolean}
*
*/
DateRange.prototype.overlaps = function(range) {
var _ref, _ref1;
if ((this.start < (_ref = range.start) && _ref < this.end)) {
return true;
} else if ((range.start < (_ref1 = this.start) && _ref1 < range.end)) {
return true;
} else {
return false;
}
};
/**
* Iterate over the date range by a given date range, executing a function
* for each sub-range.
* @param {!DateRange|String} range Date range to be used for iteration
* or shorthand string (shorthands:
* http://momentjs.com/docs/#/manipulating/add/)
* @param {!function(Moment)} hollaback Function to execute for each sub-range.
* @return {!boolean}
*
*/
DateRange.prototype.by = function(range, hollaback) {
if (typeof range === 'string') {
this._by_string(range, hollaback);
} else {
this._by_range(range, hollaback);
}
return this;
};
/**
* Date range in milliseconds. Allows basic coercion math of date ranges.
* @return {!number}
*
*/
DateRange.prototype.by = function(range, hollaback) {
if (typeof range === 'string') {
this._by_string(range, hollaback);
} else {
this._by_range(range, hollaback);
}
return this;
};
DateRange.prototype.valueOf = function() {
return this.end - this.start;
};
return DateRange;
})();
/**
* Build a date range.
* @param {(Moment|Date)} start Start of range.
* @param {(Moment|Date)} end End of range.
* @this {Moment}
* @return {!DateRange}
* Date range in milliseconds. Allows basic coercion math of date ranges.
* @return {!number}
*

@@ -120,11 +133,9 @@ */

moment.fn.range = function(start, end) {
return new DateRange(start, end);
DateRange.prototype.valueOf = function() {
return this.end - this.start;
};
/**
* Check if the current moment is within a given date range.
* @param {!DateRange} range Date range to check.
* @this {Moment}
* @return {!boolean}
* Date range toDate
* @return {!Array}
*

@@ -134,10 +145,42 @@ */

moment.fn.within = function(range) {
return range.contains(this._d);
DateRange.prototype.toDate = function() {
return [this.start.toDate(), this.end.toDate()];
};
if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
module.exports = moment;
return DateRange;
})();
/**
* Build a date range.
* @param {(Moment|Date)} start Start of range.
* @param {(Moment|Date)} end End of range.
* @this {Moment}
* @return {!DateRange}
*
*/
moment.fn.range = function(start, end) {
if (['year', 'month', 'week', 'day', 'hour', 'minute', 'second'].indexOf(start) > -1) {
return new DateRange(moment(this).startOf(start), moment(this).endOf(start));
} else {
return new DateRange(start, end);
}
};
}).call(this);
/**
* Check if the current moment is within a given date range.
* @param {!DateRange} range Date range to check.
* @this {Moment}
* @return {!boolean}
*
*/
moment.fn.within = function(range) {
return range.contains(this._d);
};
return moment;
}));

@@ -1,28 +0,35 @@

{ "name": "moment-range"
, "description": "Fancy date ranges for Moment.js"
, "author": "Gianni Chiappetta <gianni@runlevel6.org> (http://gf3.ca)"
, "homepage": "https://github.com/gf3/moment-range"
, "bugs": "https://github.com/gf3/moment-range/issues"
, "main": "./lib/moment-range"
, "directories": { "lib" : "./lib" }
, "version": "0.1.7"
, "engines":
{ "node": "*"
{
"name": "moment-range",
"description": "Fancy date ranges for Moment.js",
"author": "Gianni Chiappetta <gianni@runlevel6.org> (http://gf3.ca)",
"homepage": "https://github.com/gf3/moment-range",
"bugs": "https://github.com/gf3/moment-range/issues",
"main": "./lib/moment-range",
"directories": {
"lib": "./lib"
},
"version": "1.0.0",
"engines": {
"node": "*"
},
"dependencies": {
"moment": ">= 1"
},
"devDependencies": {
"coffee-script": "~1",
"mocha": "1.3.0",
"should": "0.6.3",
"grunt": "~0.4.1",
"grunt-umd": "~1.3.0",
"grunt-contrib-coffee": "~0.7.0",
"grunt-mocha-test": "~0.7.0"
},
"repository": {
"type": "git",
"url": "https://git@github.com/gf3/moment-range.git"
},
"license": {
"type": "Public Domain",
"url": "https://github.com/gf3/moment-range/raw/master/UNLICENSE"
}
, "dependencies":
{ "moment": ">= 1"
}
, "devDependencies":
{ "coffee-script": "~1.6"
, "mocha": "1.3.0"
, "should": "0.6.3"
}
, "repository":
{ "type": "git"
, "url": "https://git@github.com/gf3/moment-range.git"
}
, "license":
{ "type": "Public Domain"
, "url": "https://github.com/gf3/moment-range/raw/master/UNLICENSE"
}
}

@@ -28,3 +28,3 @@ moment-range

### Contains / Within
### Contains / Within / Overlaps

@@ -34,7 +34,8 @@ Check to see if your range contains a date/moment:

``` javascript
var start = new Date(2012, 4, 1)
, end = new Date(2012, 4, 23)
, lol = new Date(2012, 4, 15)
, wat = new Date(2012, 2, 27)
, range = moment().range(start, end);
var start = new Date(2012, 4, 1)
, end = new Date(2012, 4, 23)
, lol = new Date(2012, 4, 15)
, wat = new Date(2012, 2, 27)
, range = moment().range(start, end)
, range2 = moment().range(lol, wat);

@@ -56,5 +57,11 @@ range.contains(lol); // true

Does it overlap another range?
``` javascript
range.overlaps(range2); // true
```
### Iterate
Iterate over your date range by another range:
Iterate over your date range by an amount of time or another range:

@@ -69,4 +76,16 @@ ``` javascript

range1.by('days', function(moment) {
// Do something with `moment`
});
```
Any of the units accepted by [moment.js' `add`
method](http://momentjs.com/docs/#/manipulating/add/) may be used.
You can also iterate by another range:
``` javascript
range1.by(range2, function(moment) {
// Do something with `moment`
acc.push(moment);
});

@@ -119,3 +138,3 @@

``` json
{ "moment-range": "~0.1" }
{ "moment-range": "~1" }
```

@@ -137,3 +156,3 @@

``` bash
$ git clone https://git@github.com/gf3/moment-range.git
git clone https://git@github.com/gf3/moment-range.git
```

@@ -144,9 +163,9 @@

``` bash
$ npm install
npm install
```
Run the tests:
Do all the things! (including the tests)
``` bash
$ ./node_modules/.bin/cake test
$ grunt
```

@@ -153,0 +172,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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