# ViewTokenList

class

Token list. Allows handling (adding, removing, retrieving) a set of tokens (for example class names).

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

<a id="properties">

## Properties

<a id="member-isEmpty">

### `isEmpty: boolean` _(readonly)_

Returns true if token list has no tokens set.

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

<a id="member-size">

### `size: number` _(readonly)_

Number of tokens.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L32)

<a id="member-_set">

### `_set: Set<string>` _(private)_

The set of tokens.

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

<a id="methods">

## Methods

<a id="function-clear">

### `clear() → void`

Removes all tokens.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L88)

#### Returns

* `void`

<a id="function-has">

### `has( name ) → boolean`

Checks if a given token is set.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L39)

#### Parameters

* `name: string`

#### Returns

* `boolean`

<a id="function-isSimilar">

### `isSimilar( other ) → boolean`

Returns `true` if both attributes have the same tokens.

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

#### Parameters

* `other: ViewTokenList`

#### Returns

* `boolean`

<a id="function-keys">

### `keys() → Array<string>`

Returns all tokens.

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

#### Returns

* `Array<string>`

<a id="function-remove">

### `remove( tokens ) → void`

Removes given token.

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

#### Parameters

* `tokens: ArrayOrItem<string>`

#### Returns

* `void`

<a id="function-set">

### `set( tokens ) → void`

Sets a given token without affecting other tokens.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L68)

#### Parameters

* `tokens: ArrayOrItem<string>`

#### Returns

* `void`

<a id="function-setTo">

### `setTo( value ) → this`

Resets the value to the given one.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L53)

#### Parameters

* `value: string`

#### Returns

* `this`

<a id="function-toString">

### `toString() → string`

Returns a normalized tokens string.

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

#### Returns

* `string`

<a id="function-_canMergeFrom">

### `_canMergeFrom() → boolean` _(internal)_

Used by [`_canMergeAttributesFrom`](module_engine_view_element-ViewElement.md#function-_canMergeAttributesFrom) to verify if the given attribute can be merged without conflicts into the attribute.

This method is indirectly used by the [`ViewDowncastWriter`](module_engine_view_downcastwriter-ViewDowncastWriter.md) while downcasting an [`ViewAttributeElement`](module_engine_view_attributeelement-ViewAttributeElement.md) to merge it with other `AttributeElement`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L190)

#### Returns

* `boolean`

<a id="function-_clone">

### `_clone() → this` _(internal)_

Clones the attribute value.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L121)

#### Returns

* `this`

<a id="function-_getConsumables">

### `_getConsumables( name? ) → Array<string>` _(internal)_

Returns a list of consumables for the attribute.

Could be filtered by the given token name.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L177)

#### Parameters

* `name?: string`

#### Returns

* `Array<string>`

<a id="function-_getTokensMatch">

### `_getTokensMatch( tokenPattern ) → Array<string> | undefined` _(internal)_

Used by the [Matcher](module_engine_view_matcher-Matcher.md) to collect matching attribute tokens.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L136)

#### Parameters

* `tokenPattern: string | true | RegExp`

  The matched token name pattern.

#### Returns

* `Array<string> | undefined`

  An array of matching tokens.

<a id="function-_isMatching">

### `_isMatching( other ) → boolean` _(internal)_

Used by [`_canSubtractAttributesOf`](module_engine_view_element-ViewElement.md#function-_canSubtractAttributesOf) to verify if the given attribute can be fully subtracted from the attribute.

This method is indirectly used by the [`ViewDowncastWriter`](module_engine_view_downcastwriter-ViewDowncastWriter.md) while down-casting an [`ViewAttributeElement`](module_engine_view_attributeelement-ViewAttributeElement.md) to unwrap the ViewAttributeElement.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L219)

#### Parameters

* `other: ViewTokenList`

#### Returns

* `boolean`

<a id="function-_mergeFrom">

### `_mergeFrom( other ) → void` _(internal)_

Used by [`_mergeAttributesFrom`](module_engine_view_element-ViewElement.md#function-_mergeAttributesFrom) to merge a given attribute into the attribute.

This method is indirectly used by the [`ViewDowncastWriter`](module_engine_view_downcastwriter-ViewDowncastWriter.md) while down-casting an [`ViewAttributeElement`](module_engine_view_attributeelement-ViewAttributeElement.md) to merge it with other ViewAttributeElement.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/tokenlist.ts#L202)

#### Parameters

* `other: ViewTokenList`

#### Returns

* `void`

---

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