# CommandCollection

class

Collection of commands. Its instance is available in [`editor.commands`](module_core_editor_editor-Editor.md#member-commands).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L16)

<a id="properties">

## Properties

<a id="member-_commands">

### `_commands: Map<string, Command>` _(private)_

Command map.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L20)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor()`

Creates collection instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L25)

<a id="function-Symbol.iterator">

### `Symbol.iterator() → Iterator<[ string, Command ]>`

Iterable interface.

Returns `[ commandName, commandInstance ]` pairs.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L95)

#### Returns

* `Iterator<[ string, Command ]>`

<a id="function-add">

### `add( commandName, command ) → void`

Registers a new command.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L34)

#### Type parameters

* `TName: extends string`

#### Parameters

* `commandName: TName`

  The name of the command.

* `command: CommandsMap[ TName ]`

#### Returns

* `void`

<a id="function-commands">

### `commands() → IterableIterator<Command>`

Returns iterator of command instances.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L86)

#### Returns

* `IterableIterator<Command>`

<a id="function-destroy">

### `destroy() → void`

Destroys all collection commands.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L102)

#### Returns

* `void`

<a id="function-execute">

### `execute( commandName, commandParams ) → ReturnType<CommandsMap[ TName ][ 'execute' ]>`

Executes a command.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L57)

#### Type parameters

* `TName: extends string`

#### Parameters

* `commandName: TName`

  The name of the command.

* `commandParams: Parameters<CommandsMap[ TName ][ 'execute' ]>`

  Command parameters.

#### Returns

* `ReturnType<CommandsMap[ TName ][ 'execute' ]>`

  The value returned by the [`command.execute()`](module_core_command-Command.md#function-execute).

<a id="function-get">

### `get( commandName ) → CommandsMap[ TName ] | undefined`

Retrieves a command from the collection.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L46)

#### Type parameters

* `TName: extends string`

#### Parameters

* `commandName: TName`

  The name of the command.

#### Returns

* `CommandsMap[ TName ] | undefined`

<a id="function-names">

### `names() → IterableIterator<string>`

Returns iterator of command names.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/commandcollection.ts#L79)

#### Returns

* `IterableIterator<string>`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
