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

nano-editor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nano-editor

Super small and simple code editor inspired by CodeFlask.js.

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
increased by260%
Maintainers
1
Weekly downloads
 
Created
Source

nanoEditor

Super small and simple code editor inspired by CodeFlask.js.

Demo
  • Includes Typescript typings.
  • Plays nice with babel/ES5 projects.
  • Only Just 11kb gzipped (including PrismJS dependency and styles).
  • Supports HTML, JSX, JSON, Typescript, CSS, LESS & SASS out of the box.
  • Line number support is also included in the bundle.

Install (Browser)

  1. Include the editor CDN in your <head> tag.
<script src="https://cdn.jsdelivr.net/npm/nano-editor@1.2.3/dist/nanoEditor.min.js"></script>
  1. Include a theme from cdnjs for PrismJS 1.9.0 in your head tag.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.9.0/themes/prism.min.css" />

Install (Webpack / Browserify / etc)

  1. Install this lib from npm.
npm i nano-editor --save
  1. Import the lib and a prismjs theme into your project.
import { nanoEditor } from "nano-editor";
import "prismjs/themes/prism.css";

Usage / API

The new nanoEditor() method accepts three arguments:

  1. Element: Id or HTML element to attach the editor to.
  2. Type: The type of code being displayed, defalts to markdown.
  3. Line Numbers: Pass in true to see line numbers.

Once you've setup an instance, there are a few public methods you can use:

.onChange(changeFunction: (value: string) => void)

Accepts a single function as it's argument, the function will get called each time the editor is updated. The function will also have the editor's value passed into it.

.setLanguage(language: string)

Change the language of the editor.

.setValue(value: string)

Sets the contents of the editor.

.canEdit(yesOrNo: boolean)

Set the element as editable or not.

.container

The HTML element the editor is attached to.

Example

<div id="#code">
    alert("Dont taze me bro.");
</div>
<script>
    const editor = new nanoEditor("#code", "javascript", true);
    editor.setValue("alert(\"Don't move BRO!\")");
</script>

Keywords

FAQs

Package last updated on 29 Dec 2017

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