Registry / web-framework / codemirror-formatting

codemirror-formatting

JSON →
library1.0.0jsnpmunverified

A standalone, modular packaging of the original CodeMirror formatting addon (v1.0.0), designed to simplify inclusion in module-based projects. Originally extracted from the official CodeMirror v2 demo page, this package provides basic code formatting capabilities (auto-indent and comment toggling) for CodeMirror editors. The release cadence is low; the package has been stable since 2016. Unlike the built-in formatting in CodeMirror v5+, this addon is compatible with older CodeMirror versions (2.x) and does not require a full migration. It ships as a single JavaScript file and is intended for use with browser module loaders or bundlers.

npm install codemirror-formatting
INSTALL
IMPORT
SIG · CODEMIRROR-FORMATT
C
codemirror-formatting
web-frameworkjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (formatting module)
import 'codemirror-formatting'
import formatting from 'codemirror-formatting'
The module has no default export; it patches the global CodeMirror object.
CodeMirrorCommands (if using named import)
import 'codemirror-formatting'; // then use CodeMirror.commands.indentMore, etc.
import { indentMore } from 'codemirror-formatting'
Commands are added to CodeMirror.commands; no named exports are available.
CommonJS require
require('codemirror-formatting')
Works with Node.js/bundlers. The module side-effects CodeMirror global.
TypeScript types
/// <reference types="codemirror-formatting" />
import type {} from 'codemirror-formatting'
Type definitions are not bundled; use a .d.ts file or add triple-slash reference.

Shows how to import the formatting addon and use its commands (indentMore, indentLess, autoIndent, toggleComment) on a CodeMirror editor.

// Ensure CodeMirror is loaded first. Then import the formatting addon. // It automatically extends CodeMirror.commands. import CodeMirror from 'codemirror'; import 'codemirror/lib/codemirror.css'; import 'codemirror/mode/javascript/javascript'; import 'codemirror-formatting'; const editor = CodeMirror(document.getElementById('editor'), { mode: 'javascript', lineNumbers: true }); // Use the formatting commands: editor.execCommand('indentMore'); // Indent selection editor.execCommand('indentLess'); // Unindent selection editor.execCommand('autoIndent'); // Auto-indent selection or line editor.execCommand('toggleComment'); // Toggle line comment
Debug
Known issues
breakingThis addon only works with CodeMirror versions 2.x~4.x. It does not support CodeMirror v5+ (which has built-in formatting).
fix
Upgrade to CodeMirror v5+ and use its built-in formatting commands (e.g., indentMore, indentLess).
affects: >=1.0.0
gotchaThe addon modifies CodeMirror.commands globally. If using multiple editor instances, all will be affected.
fix
Ensure this import is only done once in your application.
affects: >=0.0.0
deprecatedThis package has not been updated since 2016 and may have compatibility issues with modern bundlers.
fix
Consider using the official CodeMirror formatting addon from @codemirror/format or codemirror/addon/comment/comment.js.
affects: >=1.0.0
gotchaThe 'autoIndent' command may not work as expected if the CodeMirror mode does not support indentation.
fix
Test with your specific mode or use a mode that defines indentUnit.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'codemirror-formatting'
Package not installed or not resolved by bundler.
fix
Run npm install codemirror-formatting or add it to package.json.
Uncaught TypeError: Cannot read properties of undefined (reading 'commands')
CodeMirror is not loaded before the formatting addon is imported.
fix
Ensure CodeMirror is imported and available globally (e.g., import 'codemirror' before 'codemirror-formatting').
'indentMore' is not a known command
The formatting addon has not been applied properly, or using CodeMirror v5+ which has its own commands.
fix
Verify that the addon is imported and that you are using a compatible CodeMirror version (2.x–4.x).
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
codemirroroptionalpeer dependency: requires CodeMirror editor instance to attach formatting commands
Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
1
Resources