diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..68d8638 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,12 @@ +name: check +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@main + - uses: actions/setup-node@main + with: + node-version: 'lts/*' + - run: yarn install + - run: make check diff --git a/.jshintrc b/.jshintrc index b6c34a0..3209b7e 100644 --- a/.jshintrc +++ b/.jshintrc @@ -4,12 +4,12 @@ "eqnull": true, "immed": true, "latedef": "nofunc", - "mocha" : true, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, "unused": true, - "browser": true + "browser": true, + "esversion": 11 } diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b5efd79..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -sudo: false -language: node_js -node_js: - - "stable" diff --git a/Makefile b/Makefile index 06a41c4..b2fe4a1 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,6 @@ lint: ./node_modules/.bin/jshint *.js test test: - ./node_modules/.bin/mocha --recursive --require should --require jsdom-global/register + node --require should --require jsdom-global/register --test .PHONY: check lint test diff --git a/Readme.md b/Readme.md index 911914a..5101b41 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ [![NPM version][npm-image]][npm-url] -[![Build Status][travis-image]][travis-url] -[![Dependency Status][gemnasium-image]][gemnasium-url] +[![Build Status][build-image]][build-url] +[![Dependency Status][deps-image]][deps-url] # events @@ -55,13 +55,13 @@ remove event listener for specific `event`, if `event` is not specified remove a MIT © [Damian Krzeminski](https://pirxpilot.me) -[npm-image]: https://img.shields.io/npm/v/@pirxpilot/events.svg +[npm-image]: https://img.shields.io/npm/v/@pirxpilot/events [npm-url]: https://npmjs.org/package/@pirxpilot/events -[travis-url]: https://travis-ci.org/pirxpilot/events -[travis-image]: https://img.shields.io/travis/pirxpilot/events.svg +[build-url]: https://github.com/pirxpilot/events/actions/workflows/check.yaml +[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/events/check.yaml?branch=main -[gemnasium-image]: https://img.shields.io/gemnasium/pirxpilot/events.svg -[gemnasium-url]: https://gemnasium.com/pirxpilot/events +[deps-image]: https://img.shields.io/librariesio/release/npm/@pirxpilot/events +[deps-url]: https://libraries.io/npm/@pirxpilot%2Fevents [component/events]: https://github.com/component/events diff --git a/index.js b/index.js index 53cd5e6..d37c702 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,24 @@ module.exports = events; function events(el, obj) { - var handlers = {}; + const handlers = {}; function bind(name, handler, opts) { if (!handler) { handler = name; } - if (typeof(handler) === 'string') { + if (typeof (handler) === 'string') { handler = obj[handler].bind(obj); } el.addEventListener(name, handler, opts); handlers[name] = { - handler: handler, - opts: opts + handler, + opts }; } function do_unbind(name) { - var h = handlers[name]; + const h = handlers[name]; if (!h) { return; } el.removeEventListener(name, h.handler, h.opts); delete handlers[name]; @@ -34,7 +34,7 @@ function events(el, obj) { } return { - bind: bind, - unbind: unbind + bind, + unbind }; } diff --git a/package.json b/package.json index 735ee89..4e5cffc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "email": "pirxpilot@furkot.com", "url": "https://pirxpilot.me" }, - "repository": "pirxpilot/events", + "repository": "github:pirxpilot/events", "license": "MIT", "keywords": [ "browser", @@ -15,10 +15,9 @@ "dom" ], "devDependencies": { - "jsdom": "~11", + "@pirxpilot/jshint": "~3", + "jsdom": "~24", "jsdom-global": "~3", - "jshint": "~2", - "mocha": "~4", "should": "~13" }, "scripts": { @@ -27,4 +26,4 @@ "files": [ "index.js" ] -} \ No newline at end of file +} diff --git a/test/events.js b/test/events.js index ea7db67..4834109 100644 --- a/test/events.js +++ b/test/events.js @@ -1,13 +1,14 @@ -// var should = require('should'); -var events = require('../'); +const { describe, it } = require('node:test'); + +const events = require('../'); describe('events', function () { it('must bind event', function () { - var clicks = 0; - var handlers = { - click: function() { clicks++; } + let clicks = 0; + const handlers = { + click() { clicks++; } }; - var div = document.createElement('div'); + const div = document.createElement('div'); events(div, handlers).bind('click'); @@ -18,11 +19,11 @@ describe('events', function () { }); it('must bind event when method name is passed', function () { - var clicks = 0; - var handlers = { - onclick: function() { clicks++; } + let clicks = 0; + const handlers = { + onclick() { clicks++; } }; - var div = document.createElement('div'); + const div = document.createElement('div'); events(div, handlers).bind('click', 'onclick'); @@ -32,15 +33,14 @@ describe('events', function () { clicks.should.eql(2); }); - it('must unbind event', function () { - var clicks = 0; - var handlers = { - click: function() { clicks++; } + let clicks = 0; + const handlers = { + click() { clicks++; } }; - var div = document.createElement('div'); + const div = document.createElement('div'); - var e = events(div, handlers); + const e = events(div, handlers); e.bind('click'); @@ -53,18 +53,17 @@ describe('events', function () { clicks.should.eql(1); }); - it('must unbind all events when no event name is passed', function () { - var clicks = 0; - var foos = 0; - var handlers = { - click: function() { clicks++; }, - foo: function() { foos++; } + let clicks = 0; + let foos = 0; + const handlers = { + click() { clicks++; }, + foo() { foos++; } }; - var div = document.createElement('div'); - var ev = new CustomEvent('foo'); + const div = document.createElement('div'); + const ev = new CustomEvent('foo'); - var e = events(div, handlers); + const e = events(div, handlers); e.bind('click'); e.bind('foo'); @@ -84,6 +83,4 @@ describe('events', function () { clicks.should.eql(1); foos.should.eql(1); }); - - });