{"id":13457745,"url":"https://github.com/antonmedv/codejar","last_synced_at":"2025-05-13T17:12:51.711Z","repository":{"id":38411305,"uuid":"251604169","full_name":"antonmedv/codejar","owner":"antonmedv","description":"An embeddable code editor for the browser 🍯","archived":false,"fork":false,"pushed_at":"2024-11-11T20:44:07.000Z","size":85,"stargazers_count":1851,"open_issues_count":19,"forks_count":119,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-24T03:49:32.284Z","etag":null,"topics":["code-editor"],"latest_commit_sha":null,"homepage":"https://medv.io/codejar/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonmedv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"antonmedv"}},"created_at":"2020-03-31T13:01:35.000Z","updated_at":"2025-04-23T07:31:59.000Z","dependencies_parsed_at":"2023-02-07T11:02:12.551Z","dependency_job_id":"c965693c-d8c8-4368-a7e9-a4310067f2b5","html_url":"https://github.com/antonmedv/codejar","commit_stats":{"total_commits":97,"total_committers":23,"mean_commits":4.217391304347826,"dds":0.2989690721649485,"last_synced_commit":"8b8dbb3c99cd7b5987b1d094a45441234b386012"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonmedv%2Fcodejar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonmedv%2Fcodejar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonmedv%2Fcodejar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonmedv%2Fcodejar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonmedv","download_url":"https://codeload.github.com/antonmedv/codejar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990482,"owners_count":21995775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-editor"],"created_at":"2024-07-31T09:00:35.409Z","updated_at":"2025-05-13T17:12:46.699Z","avatar_url":"https://github.com/antonmedv.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\u003ca href=\"https://medv.io/codejar/\"\u003e\u003cimg src=\"https://medv.io/assets/codejar.svg\" width=\"72\"\u003e\u003c/a\u003e\u003c/p\u003e\n\u003ch3 align=\"center\"\u003eCodeJar – an embeddable code editor for the browser\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\u003ca href=\"https://medv.io/codejar/\"\u003e\u003cimg src=\"https://medv.io/assets/codejar/screenshot.png\" width=\"709\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n[![npm](https://img.shields.io/npm/v/codejar?color=brightgreen)](https://www.npmjs.com/package/codejar)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/codejar?label=size)](https://bundlephobia.com/result?p=codejar)\n\n## Features\n\n* Lightweight (**2.45 kB** only)\n* No dependencies\n* Preserves indentation on a new line\n* Adds closing brackets, quotes\n* Indents line with the **Tab** key\n* Supports **undo**/**redo** \n\n## Getting Started\n\nInstall CodeJar 🍯 \u0026nbsp; via npm:\n\n```bash\nnpm i codejar\n```\n\nCreate an element and init the CodeJar 🍯:\n\n```html\n\u003cdiv class=\"editor\"\u003e\u003c/div\u003e\n\u003cscript\u003e\n  let jar = CodeJar(document.querySelector('.editor'), highlight)\n\u003c/script\u003e\n```\n\nSecond argument to `CodeJar` is a highlighting function (like Prism.js, highlight.js):\n\n```ts\nconst highlight = (editor: HTMLElement) =\u003e {\n  const code = editor.textContent\n  code = code.replace('foo', '\u003cspan style=\"color: red\"\u003efoo\u003c/span\u003e')\n  editor.innerHTML = code\n}\n\nconst jar = CodeJar(editor, highlight)\n```\n\nThird argument to `CodeJar` is options:\n  - `tab: string` replaces \"tabs\" with given string. Default: `\\t`.\n    - Note: use css rule `tab-size` to customize size.\n  - `indentOn: RegExp` allows auto indent rule to be customized. Default `/[({\\[]$/`.\n  - `moveToNewLine: RegExp` checks in extra newline character need to be added. Default `/^[)}\\]]/`.\n  - `spellcheck: boolean` enables spellchecking on the editor. Default `false`.\n  - `catchTab: boolean` catches Tab keypress events and replaces it with `tab` string. Default: `true`.\n  - `preserveIdent: boolean` keeps indent levels on new line. Default `true`.\n  - `addClosing: boolean` automatically adds closing brackets, quotes. Default `true`.\n  - `history` records history. Default `true`.\n  - `window` window object. Default: `window`.\n  - `autoclose` object\n    - `open string` characters that triggers the autoclose function \n    - `close string` characters that correspond to the opening ones and close the object.\n\n\n```js\nconst options = {\n  tab: ' '.repeat(4), // default is '\\t'\n  indentOn: /[(\\[]$/, // default is /{$/\n  autoclose: { \n    open: `([{*`, // default is `([{'\"`\n    close: `)]}*` // default is `)]}'\"`\n  }\n}\n\nconst jar = CodeJar(editor, highlight, options)\n```\n\n## API\n\n#### `updateCode(string)`\n\nUpdates the code.\n\n```js\njar.updateCode(`let foo = bar`)\n```\n\n#### `updateOptions(Partial\u003cOptions\u003e)`\n\nUpdates the options.\n\n```js\njar.updateOptions({tab: '\\t'})\n```\n\n\n#### `onUpdate((code: string) =\u003e void)`\n\nCalls callback on code updates.\n\n```js\njar.onUpdate(code =\u003e {\n  console.log(code)\n})\n```\n\n#### `toString(): string`\n\nReturn current code.\n\n```js\nlet code = jar.toString()\n```\n\n#### `save(): string`\n\nSaves current cursor position.\n\n```js\nlet pos = jar.save()\n```\n\n#### `restore(pos: Position)`\n\nRestore cursor position.\n\n```js\njar.restore(pos)\n```\n\n#### `recordHistory()`\n\nSaves current editor state to history.\n\n#### `destroy()`\n\nRemoves event listeners from editor.\n\n## Related\n\n* [react-codejar](https://github.com/guilhermelimak/react-codejar) - a React wrapper for CodeJar. \n* [ngx-codejar](https://github.com/julianpoemp/ngx-codejar) - an Angular wrapper for CodeJar. \n* [codejar-linenumbers](https://github.com/julianpoemp/codejar-linenumbers) - an JS library for line numbers.\n\n## License\n\n[MIT](LICENSE)\n","funding_links":["https://github.com/sponsors/antonmedv"],"categories":["Editor Components","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonmedv%2Fcodejar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonmedv%2Fcodejar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonmedv%2Fcodejar/lists"}