
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Install CodeJar 🍯 via npm:
npm i codejar
CodeJar 🍯 can be used via modules:
<script type="module">
import {CodeJar} from 'https://medv.io/codejar/codejar.js'
</script>
Create an element and init the CodeJar 🍯:
<div class="editor"></div>
<script>
let jar = CodeJar(document.querySelector('.editor'), Prism.highlightElement)
</script>
Second argument to CodeJar
is a highlighting function (in this example PrismJS), but any function may be used:
const highlight = (editor: HTMLElement) => {
const code = editor.textContent
// Do something with code and set html.
editor.innerHTML = code
}
let jar = CodeJar(editor, highlight)
Third argument to CodeJar
is options:
tab: string
replaces "tabs" with given string. Default: \t
.
tab-size
to customize size.indentOn: RegExp
allows auto indent rule to be customized. Default /[({\[]$/
.moveToNewLine: RegExp
checks in extra newline character need to be added. Default /^[)}\]]/
.spellcheck: boolean
enables spellchecking on the editor. Default false
.catchTab: boolean
catches Tab keypress events and replaces it with tab
string. Default: true
.preserveIdent: boolean
keeps indent levels on new line. Default true
.addClosing: boolean
automatically adds closing brackets, quotes. Default true
.history
records history. Default true
.window
window object. Default: window
.let options = {
tab: ' '.repeat(4), // default is '\t'
indentOn: /[(\[]$/, // default is /{$/
}
let jar = CodeJar(editor, highlight, options)
Some styles may be applied to our editor to make it better looking:
.editor {
border-radius: 6px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
font-family: 'Source Code Pro', monospace;
font-size: 14px;
font-weight: 400;
height: 340px;
letter-spacing: normal;
line-height: 20px;
padding: 10px;
tab-size: 4;
}
updateCode(string)
Updates the code.
jar.updateCode(`let foo = bar`)
updateOptions(Partial<Options>)
Updates the options.
jar.updateOptions({tab: '\t'})
onUpdate((code: string) => void)
Calls callback on code updates.
jar.onUpdate(code => {
console.log(code)
})
toString(): string
Return current code.
let code = jar.toString()
save(): string
Saves current cursor position.
let pos = jar.save()
restore(pos: Position)
Restore cursor position.
jar.restore(pos)
recordHistory()
Saves current editor state to history.
destroy()
Removes event listeners from editor.
FAQs
An embeddable code editor for the browser
The npm package codejar receives a total of 10,064 weekly downloads. As such, codejar popularity was classified as popular.
We found that codejar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.