# codemirror-console

> Add execute the code function to CodeMirror.

Latest version **3.2.0** (published 2024-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install codemirror-console
pnpm add codemirror-console
yarn add codemirror-console
bun add codemirror-console
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2024-04-16 |
| First published | 2014-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 445.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 77 |
| Author | azu |
| Maintainers | azu |
| Keywords | CodeMirror, JavaScript, browserify |

## Links

- npm: https://www.npmjs.com/package/codemirror-console
- Repository: https://github.com/azu/codemirror-console
- Homepage: https://github.com/azu/codemirror-console/
- Issues: https://github.com/azu/codemirror-console/issues
- npm.io page: https://npm.io/package/codemirror-console

## Dependencies (1)

- [codemirror](https://npm.io/package/codemirror.md) ^5.18.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2024-04-16
- 3.1.0 — 2023-06-05
- 3.0.4 — 2022-02-06
- 3.0.3 — 2022-02-06
- 3.0.2 — 2022-01-03
- 3.0.1 — 2022-01-03
- 3.0.0 — 2022-01-03
- 2.0.1 — 2018-12-29
- 2.0.0 — 2018-12-27
- 1.0.0 — 2016-09-11
- 0.1.0 — 2014-06-11
- 0.0.7 — 2014-06-11
- 0.0.5 — 2014-06-10
- 0.0.4 — 2014-06-10
- 0.0.3 — 2014-06-10
- … 1 more at https://npm.io/package/codemirror-console/versions

## README

# codemirror-console [![Build Status](https://travis-ci.org/azu/codemirror-console.svg)](https://travis-ci.org/azu/codemirror-console)

This library add `Console` to [CodeMirror](http://codemirror.net/ "CodeMirror").

This library could execute CodeMirror editor's code.

## Installation

```sh
npm install codemirror-console
```

If you want to use it as UI library, please use [codemirror-console-ui](../codemirror-console-ui/) instead of it.

## Usage

open index.html

``` js
const MirrorConsole = require("codemirror-console");
const content = document.querySelector(".content");
const editor = new MirrorConsole();
editor.setText(content.textContent);
editor.swapWithElement(content); // insert editor
const consoleMock = {
    log: function (arg) {
        function line(text) {
            var div = document.createElement("div");
            div.appendChild(document.createTextNode(text));
            return div;
        }
        document.getElementById("output").appendChild(line(arg));
    }
}
// eval code
editor.runInContext({ console: consoleMock }, function (error, result) {
    if (error) {
        console.error(error);
    }
});
editor.destroy();// remote editor
```
## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT

---
_Source: https://npm.io/package/codemirror-console · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
