Format API package for the roosterjs rich-text editor (v9.51.0, stable). Provides content model-level formatting operations like toggleBold, toggleItalic, setFontSize, insertTable, and changeHeading. Part of the roosterjs 9.x ecosystem, which reworked the editor around a middle-layer Content Model for consistent behavior. Active development with frequent releases (~monthly). Differentiator: framework-independent, operates on its own content model rather than directly on DOM, enabling undo/redo and structured editing. Requires roosterjs-content-model-core and roosterjs-content-model-types as peer dependencies.
npm install roosterjs-content-model-apiVerified import paths — ran on the pinned version, not inferred.
Creates an editor instance and demonstrates basic formatting APIs: toggleBold, toggleItalic, setFontSize, insertTable.
Upgrade to roosterjs-content-model-api and use the new functions (e.g., toggleBold instead of toggleBold on Editor).
If you need to know the current state, use the editor's isBold() or track formatting via plugins.
Pass fontSize as a string with unit (e.g., '14px', '1.2em', '12pt').
Ensure there is a selection/cursor position before calling insertTable.
Use a bundler that supports ESM and tree-shaking.
npm install roosterjs-content-model-api --save
import { toggleBold } from 'roosterjs-content-model-api';import { setFontSize } from 'roosterjs-content-model-api';