nw-dev-toolkit v0.4.1
NW Dev Toolkit
THIS README IS NOT COMPLETE! PLEASE BE PATIENT.
Description
NW Dev Toolkit is a toolkit for nw.js (node-webkit) development
Features
- Fully customizable!
- A recursive function to extends objects. That too create a camelCase named copy of kebab-case named properties. It's useful maintaining the readability of configurations objects.
- Predefined shortcuts that enhance the developer experience
- Refresh window (
Left Control
+R
orF5
by default) - Refresh window and clear the require cache (
Left Control
+Left Shift
+R
orF6
by default)
- Refresh window (
- A way to attach easily a shortcut to window (using DOM Level 3 KeyboardEvent code Values)
Installation
Using NPM :
In the root folder of your nw.js app.
$ npm install nw-dev-toolkit
In the node_modules
folder of your nw.js app.
Using Git :
$ git clone https://github.com/MeowWoem/nw-dev-toolkit.git
Quick start
Requirement :
Before starts you need to create an nw.js app if it is not already done (follow this guide if you need).
Then in your index.html
adds these following lines in <head>
tag before any other executable scripts :
<script>
require("nw-dev-toolkit").init(window);
</script>
Extends your objects :
You can extends your objects recursively.
var tool = require("nw-dev-toolkit"); // The tool must already be initialized
var defaultOptions = {
foobar: {
foo: "Hello",
},
"i-wanna-to-be-transformed-to-camel-case": true
};
var newOptions = {
foobar: {
bar: "World"
}
};
newOptions = tool.extend({}, defaultOptions, newOptions);
console.log(newOptions);
/*
That logs :
{
"foobar": {
"foo": "Hello",
"bar": "World"
},
"i-wanna-to-be-transformed-to-camel-case": true,
"iWannaToBeTransformedToCamelCase": true
}
*/
Load Node Module directly in DOM
Some modules, such as jQuery or bootstrap, need to include files in the DOM (JS or CSS). It is sometimes annoying to add them manually to the code, the paths to the modules are usually long. Now with our module you can replace the node "require" function by the DOMInjector API for this type of modules. The loaded modules will be automatically added to the DOM.
Examples :
var tool = require("nw-dev-toolkit"); // The tool must already be initialized
var loader = new tool.modules.DOMInjector();
loader.add("jquery", "tether");
loader.add("bootstrap");
loader.load().then(function() {
console.log("loading complete");
});
Works with shortcut :
You can easily add shortcuts using standards DOM Level 3 KeyboardEvent code Values. You can assign multiple shortcuts for the same function at once by separates key codes with comma.
Examples :
- To add a shortcut :
var tool = require("nw-dev-toolkit"); // The tool must already be initialized
var myShortcut01 = function(e) {
console.log("Shortcut 01 fired!", e);
}
tool.shortcuts.add("ControlLeft+V,ShiftLeft+V", myShortcut01);
var myShortcut02 = function(e) {
console.log("Shortcut 02 fired!", e);
}
tool.shortcuts.add("ControlLeft+V,ShiftLeft+V", myShortcut02);
- To remove them :
// Remove all shortcut with these key codes and this callback
tool.shortcuts.remove("ControlLeft+V,ShiftLeft+V", myShortcut01);
// Remove all shortcut with these key codes
tool.shortcuts.remove("ControlLeft+V,ShiftLeft+V");
// Remove all shortcut with this key code and this callback
tool.shortcuts.remove("ShiftLeft+V", myShortcut01);
// Remove all shortcut with this key code
tool.shortcuts.remove("ShiftLeft+V");