# CharacterCount

Exposes character and word counts through editor.storage.characterCount and can limit input. Customize the default string-length and space-separated counters when needed.

Exposes character and word counts through editor.storage.characterCount and can limit input. Customize the default string-length and space-separated counters when needed.

`@quirekit/extensions` · **MIT**

## Editor compatibility
Layer：**Shared document capability**
| Editor | Status | Assembly and boundaries |
| --- | --- | --- |
| Classic | Requires integration | Connect the services, targets and lifecycle described on this page and validate the selected View and document model. Core contracts are reusable, but there is no universal product installation without host ports. |
| Block | Supported | [createBlockEditorPreset](/en/plugins/reference/create-block-editor-preset) — The default createBlockEditor preset installs this capability. Configure the corresponding preset child; graphic editing uses the preset's workspace ports, while persistence and assets remain host-owned. Avoid duplicate extensions. |

“Supported” means the product assembly above exists; interaction, host services and file formats retain their own conditions. See [status and integration rules](/en/plugins/compatibility). Licensing is shown separately.

## Installation

```sh
pnpm add @quirekit/extensions@alpha
```

Install in Editor extensions. The host supplies a view, container and persistence; see [Quick start](/en/guide/quick-start).

```ts
import { CharacterCount } from '@quirekit/extensions'

const counter = CharacterCount.configure({ limit: 5000 })
```

Use compatible versions available from your distribution source. This site uses the Alpha workspace. License labels come from package metadata; see [support and licensing](/en/support).

## Integration by editor

These snippets use an existing host element named element. The host owns container sizing and persistence; call instance.destroy() on teardown. Avoid duplicating preset capabilities and supply required host ports before installation.

### Classic

Connect the services, targets and lifecycle described on this page and validate the selected View and document model. Core contracts are reusable, but there is no universal product installation without host ports.

### Block

The default createBlockEditor preset installs this capability. Configure the corresponding preset child; graphic editing uses the preset's workspace ports, while persistence and assets remain host-owned. Avoid duplicate extensions.

[createBlockEditorPreset](/en/plugins/reference/create-block-editor-preset)

```ts
import { createBlockEditor } from '@quirekit/block-editor'
import '@quirekit/block-editor/styles.css'

const instance = createBlockEditor({
  element,
  preset: { characterCount: { limit: 5000 } },
  content: { type: 'doc', content: [{ type: 'paragraph' }] },
})
```

## Configuration

These are extension-level defaults. Presets can override them; they are distinct from current document attributes. See [configuration](/en/plugins/configuration).

### limit

Maximum allowed character count. `null`, `undefined`, and `0` disable the limit.

Type：`number | null | undefined`

Default：`null`

### mode

Counting mode used by the `characters()` storage helper.

Type：`"nodeSize" | "textSize"`

Default：`"textSize"`

### textCounter

Counts text characters.

Type：`(text: string): number`

Default：`(text: string) => text.length`

### wordCounter

Counts words.

Type：`(text: string): number`

Default：`(text: string) => text.split(" ").filter((word) => word !== "").length`

## Commands and runtime

This entry declares no directly enumerable commands. Children supply bundle commands; product plugins use contributions or document services.

limit participates in transaction filtering and may trim initially oversized content. Inspect imported documents before enabling a limit when lossless opening is required.

## Next steps

Return to [all plugins](/en/plugins), or read [configuration](/en/plugins/configuration) to distinguish options, attributes and commands.

See [extension development](/en/build/extension) for custom capabilities and [Build a product](/en/build) for complete hosting.
