## Commands You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object][1] ```js const editor = grapesjs.init({ commands: { // options } }) ``` Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance ```js const commands = editor.Commands; ``` - [add][2] - [get][3] - [has][4] ## add Add new command to the collection ### Parameters - `id` **[string][5]** Command's ID - `command` **([Object][6] \| [Function][7])** Object representing your command, By passing just a function it's intended as a stateless command (just like passing an object with only `run` method). ### Examples ```javascript commands.add('myCommand', { run(editor, sender) { alert('Hello world!'); }, stop(editor, sender) { }, }); // As a function commands.add('myCommand2', editor => { ... }); ``` Returns **this** ## get Get command by ID ### Parameters - `id` **[string][5]** Command's ID ### Examples ```javascript var myCommand = commands.get('myCommand'); myCommand.run(); ``` Returns **[Object][6]** Object representing the command ## has Check if command exists ### Parameters - `id` **[string][5]** Command's ID Returns **[Boolean][8]** [1]: https://github.com/artf/grapesjs/blob/master/src/commands/config/config.js [2]: #add [3]: #get [4]: #has [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean