z-namespacer

Namespaces event strings. (Works with jQuery.)

Usage no npm install needed!

<script type="module">
  import zNamespacer from 'https://cdn.skypack.dev/z-namespacer';
</script>

README

z-namespacer

Build Status npm version

Namespacer creates namespaced event strings.

Expects the returned namespaced event strings to be used with jQuery event namespaces.

Since it's a CommonJS module, it must be used alongside with Browserify, or something similar, like WebPacker.

Example, explanation

var Namespacer = require('z-namespacer');

// Creating a new object, providing the namespace
var ns = new Namespacer('namespace');

ns.get('click');
// -> 'click.namespace'

ns.get('resize scroll');
// -> 'resize.namespace scroll.namespace'

// Usage example with jQuery
$(window).on(ns.get('resize scroll'), function() {
    // Do something nasty
});

// later on
$(window).off(ns.get('resize scroll'));

License

MIT