Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modernize'
Browse files Browse the repository at this point in the history
  • Loading branch information
pirxpilot committed Jan 31, 2024
2 parents 0604c95 + 85d97e8 commit b61693b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 'lts/*'
- run: yarn install
Expand Down
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"eqnull": true,
"immed": true,
"latedef": "nofunc",
"mocha" : true,
"newcap": true,
"noarg": true,
"sub": true,
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
check: lint test

lint:
@./node_modules/.bin/jshint index.js test
./node_modules/.bin/jshint index.js test

test:
@./node_modules/.bin/mocha \
--reporter spec
node --test

distclean:
rm -fr node_modules
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If restricted value is closed to `min` than to `max`, then the `min` is returned
MIT

[npm-url]: https://npmjs.org/package/bounds
[npm-image]: https://img.shields.io/npm/v/bounds.svg
[npm-image]: https://img.shields.io/npm/v/bounds

[build-url]: https://github.com/pirxpilot/bounds/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/workflow/status/pirxpilot/bounds/check
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/bounds/check.yaml?branch=main
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ class Bounds {
restrict(v) {
const { _min, _max } = this;
if (this.reversed()) {
if(this.after(v) && this.before(v)) {
if (this.after(v) && this.before(v)) {
// select closer bound
return (this._distance(_max, v) < this._distance(v, _min)) ?
_max:
_max :
_min;
}
return v;
}
if(this.before(v)) {
if (this.before(v)) {
return _min;
}
if(this.after(v)) {
if (this.after(v)) {
return _max;
}
return v;
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
"author": "Damian Krzeminski [email protected]",
"license": "MIT",
"devDependencies": {
"jshint": "~2",
"mocha": "~9"
"@pirxpilot/jshint": "~3"
},
"files": [
"index.js"
]
}
}
43 changes: 22 additions & 21 deletions test/bounds.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Bounds = require('../index.js');
var assert = require('assert');
const { describe, it } = require('node:test');
const assert = require('assert');

const Bounds = require('../index.js');

function numcmp(a, b) {
return a - b;
Expand All @@ -14,17 +15,17 @@ function strcmp(a, b) {
return (a < b) ? -1 : (a > b ? 1 : 0);
}

describe('Bounds', function(){
it('should consider all values as valid if no min/max specified', function(){
var b = new Bounds();
describe('Bounds', function () {
it('should consider all values as valid if no min/max specified', function () {
const b = new Bounds();
assert.ok(!b.before(2));
assert.ok(!b.after(5));
assert.ok(b.in(2002));
assert.ok(!b.out(15));
});

it('should consider values inside of the range as valid', function(){
var b = new Bounds()
it('should consider values inside of the range as valid', function () {
const b = new Bounds()
.compare(numcmp)
.min(-2)
.max(15);
Expand All @@ -39,8 +40,8 @@ describe('Bounds', function(){
assert.equal(b.max(), 15);
});

it('should consider values outside of the range as valid, when reversed', function(){
var b = new Bounds()
it('should consider values outside of the range as valid, when reversed', function () {
const b = new Bounds()
.compare(numcmp)
.max(-2)
.min(15);
Expand All @@ -51,26 +52,26 @@ describe('Bounds', function(){
assert.ok(b.valid(16));
});

it('should work if only min is specified', function(){
var b = new Bounds()
it('should work if only min is specified', function () {
const b = new Bounds()
.compare(strcmp)
.min('abc');
assert.ok(!b.valid('aac'));
assert.ok(b.valid('abc'));
assert.ok(b.valid('ade'));
});

it('should work if only max is specified', function(){
var b = new Bounds()
it('should work if only max is specified', function () {
const b = new Bounds()
.compare(strcmp)
.max('abc');
assert.ok(b.valid('aac'));
assert.ok(b.valid('abc'));
assert.ok(!b.valid('ade'));
});

it('should restrict values to min or max', function() {
var b = new Bounds()
it('should restrict values to min or max', function () {
const b = new Bounds()
.compare(strcmp)
.min('abc')
.max('pqrs');
Expand All @@ -81,8 +82,8 @@ describe('Bounds', function(){
assert.equal('pqrs', b.restrict('pqrs'));
});

it('should restrict reverse ranges to min or max', function() {
var b = new Bounds()
it('should restrict reverse ranges to min or max', function () {
const b = new Bounds()
.compare(strcmp)
.max('abc')
.min('pqrs');
Expand All @@ -93,8 +94,8 @@ describe('Bounds', function(){
});


it('should restrict to min or max depending on the distance', function(){
var b = new Bounds()
it('should restrict to min or max depending on the distance', function () {
const b = new Bounds()
.distance(numdistance)
.compare(numcmp)
.max(-2)
Expand All @@ -106,8 +107,8 @@ describe('Bounds', function(){
assert.equal(15, b.restrict(15));
});

it('should reset reversed state', function(){
var b = new Bounds();
it('should reset reversed state', function () {
const b = new Bounds();

assert.ok(!b.reversed());

Expand Down

0 comments on commit b61693b

Please sign in to comment.