Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codemirror/lang-javascript

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lang-javascript

JavaScript language support for the CodeMirror code editor

  • 6.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @codemirror/lang-javascript?

@codemirror/lang-javascript is a language support package for CodeMirror 6 that provides syntax highlighting, code folding, and other language-specific features for JavaScript. It is part of the CodeMirror 6 ecosystem, which is a versatile text editor implemented in JavaScript for the browser.

What are @codemirror/lang-javascript's main functionalities?

Syntax Highlighting

This code sets up a basic CodeMirror editor with JavaScript syntax highlighting. The `javascript` function from `@codemirror/lang-javascript` is used to enable JavaScript language support.

import { javascript } from '@codemirror/lang-javascript';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const state = EditorState.create({
  doc: 'const x = 10;',
  extensions: [basicSetup, javascript()]
});

const view = new EditorView({
  state,
  parent: document.body
});

Code Folding

This code demonstrates how to set up code folding in a CodeMirror editor with JavaScript language support. The `foldGutter` extension is used alongside `@codemirror/lang-javascript`.

import { javascript } from '@codemirror/lang-javascript';
import { foldGutter } from '@codemirror/fold';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const state = EditorState.create({
  doc: 'function foo() {\n  console.log("bar");\n}',
  extensions: [basicSetup, javascript(), foldGutter()]
});

const view = new EditorView({
  state,
  parent: document.body
});

Linting

This code sets up a custom linter in a CodeMirror editor with JavaScript language support. The `linter` function from `@codemirror/lint` is used to create a custom linting extension.

import { javascript } from '@codemirror/lang-javascript';
import { linter } from '@codemirror/lint';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from '@codemirror/basic-setup';

const myLinter = linter(view => {
  let diagnostics = [];
  // Custom linting logic here
  return diagnostics;
});

const state = EditorState.create({
  doc: 'const x = 10;',
  extensions: [basicSetup, javascript(), myLinter]
});

const view = new EditorView({
  state,
  parent: document.body
});

Other packages similar to @codemirror/lang-javascript

Keywords

FAQs

Package last updated on 20 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc