Comparing version 1.0.2 to 2.0.0
2.0.0 / 2018-11-29 | ||
================== | ||
* rewrite in ES6 | ||
1.0.2 / 2017-02-20 | ||
@@ -3,0 +8,0 @@ ================== |
162
index.js
@@ -1,108 +0,98 @@ | ||
var clone; | ||
const clone = require('clone-component'); | ||
if ('undefined' == typeof window) { | ||
clone = require('clone-component'); | ||
} else { | ||
clone = require('clone'); | ||
} | ||
class Bounds { | ||
module.exports = Bounds; | ||
static mixin(obj) { | ||
for (const key in Bounds.prototype) { | ||
obj[key] = Bounds.prototype[key]; | ||
} | ||
return obj; | ||
} | ||
compare(fn) { | ||
this._compare = fn; | ||
return this; | ||
} | ||
function calculateReversed(self) { | ||
return self._min | ||
&& self._max | ||
&& self.before(self._max); | ||
} | ||
distance(fn) { | ||
this._distance = fn; | ||
return this; | ||
} | ||
function Bounds(obj) { | ||
if (obj) return mixin(obj); | ||
} | ||
min(v) { | ||
if (!arguments.length) { | ||
return this._min; | ||
} | ||
this._min = v; | ||
delete this._reversed; | ||
return this; | ||
} | ||
function mixin(obj) { | ||
for (var key in Bounds.prototype) { | ||
obj[key] = Bounds.prototype[key]; | ||
max(v) { | ||
if (!arguments.length) { | ||
return this._max; | ||
} | ||
this._max = v; | ||
delete this._reversed; | ||
return this; | ||
} | ||
return obj; | ||
} | ||
Bounds.prototype.compare = function(fn) { | ||
this._compare = fn; | ||
return this; | ||
}; | ||
before(v) { | ||
return this._min && (this._compare(v, this._min) < 0); | ||
} | ||
Bounds.prototype.distance = function(fn) { | ||
this._distance = fn; | ||
return this; | ||
}; | ||
after(v) { | ||
return this._max && (this._compare(v, this._max) > 0); | ||
} | ||
Bounds.prototype.min = function(v) { | ||
if (!arguments.length) { | ||
return this._min; | ||
out(v) { | ||
return this.before(v) || this.after(v); | ||
} | ||
this._min = v; | ||
delete this._reversed; | ||
return this; | ||
}; | ||
Bounds.prototype.max = function(v) { | ||
if (!arguments.length) { | ||
return this._max; | ||
in(v) { | ||
return !this.out(v); | ||
} | ||
this._max = v; | ||
delete this._reversed; | ||
return this; | ||
}; | ||
Bounds.prototype.before = function(v) { | ||
return this._min && (this._compare(v, this._min) < 0); | ||
}; | ||
valid(v) { | ||
if (this.reversed()) { | ||
return !this.after(v) || !this.before(v); | ||
} | ||
return this.in(v); | ||
} | ||
Bounds.prototype.after = function(v) { | ||
return this._max && (this._compare(v, this._max) > 0); | ||
}; | ||
Bounds.prototype.out = function(v) { | ||
return this.before(v) || this.after(v); | ||
}; | ||
Bounds.prototype.in = function(v) { | ||
return !this.out(v); | ||
}; | ||
Bounds.prototype.valid = function(v) { | ||
if (this.reversed()) { | ||
return !this.after(v) || !this.before(v); | ||
invalid(v) { | ||
return !this.valid(v); | ||
} | ||
return this.in(v); | ||
}; | ||
Bounds.prototype.invalid = function(v) { | ||
return !this.valid(v); | ||
}; | ||
Bounds.prototype.reversed = function() { | ||
if (this._reversed === undefined) { | ||
this._reversed = calculateReversed(this); | ||
reversed() { | ||
if (this._reversed === undefined) { | ||
this._reversed = calculateReversed(this); | ||
} | ||
return this._reversed; | ||
} | ||
return this._reversed; | ||
}; | ||
Bounds.prototype.restrict = function(v) { | ||
if (this.reversed()) { | ||
if(this.after(v) && this.before(v)) { | ||
// select closer bound | ||
return (this._distance(this._max, v) < this._distance(v, this._min)) | ||
? clone(this._max) | ||
: clone(this._min); | ||
restrict(v) { | ||
if (this.reversed()) { | ||
if(this.after(v) && this.before(v)) { | ||
// select closer bound | ||
return (this._distance(this._max, v) < this._distance(v, this._min)) ? | ||
clone(this._max) : | ||
clone(this._min); | ||
} | ||
return v; | ||
} | ||
if(this.before(v)) { | ||
return clone(this._min); | ||
} | ||
if(this.after(v)) { | ||
return clone(this._max); | ||
} | ||
return v; | ||
} | ||
if(this.before(v)) { | ||
return clone(this._min); | ||
} | ||
if(this.after(v)) { | ||
return clone(this._max); | ||
} | ||
return v; | ||
}; | ||
} | ||
function calculateReversed(self) { | ||
return self._min && self._max && self.before(self._max); | ||
} | ||
module.exports = Bounds; |
{ | ||
"name": "bounds", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Mixin for checking if value is inside or outside of bounds", | ||
@@ -9,6 +9,3 @@ "main": "index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:pirxpilot/bounds.git" | ||
}, | ||
"repository": "pirxpilot/bounds", | ||
"keywords": [ | ||
@@ -21,14 +18,12 @@ "bounds", | ||
"license": "MIT", | ||
"readmeFilename": "Readme.md", | ||
"gitHead": "706dd65701bc29718f64d2fdc65cde650609ce24", | ||
"devDependencies": { | ||
"mocha": "~1.8.1", | ||
"jshint": "~0.9.1" | ||
"jshint": "~2", | ||
"mocha": "~5" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"clone-component": "~0" | ||
}, | ||
"browser": { | ||
"clone": "clone-component" | ||
"clone-component": "^0.2.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5420
5
82
1
Updatedclone-component@^0.2.2