npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

light-code-editor

v1.0.6

Published

``` yarn add light-code-editor # or npm install light-code-editor ```

Downloads

7

Readme

Lightweight Decorator for Textareas

yarn add light-code-editor
# or
npm install light-code-editor

how to user

  1. include styles "light-code-editor/styles.css"
  2. create parser
const genericParser = new Parser({
  whitespace: /\s+/,
  comment: /\/\*([^\*]|\*[^\/])*(\*\/?)?|(\/\/|#)[^\r\n]*/,
  string: /"(\\.|[^"\r\n])*"?|'(\\.|[^'\r\n])*'?/,
  number: /0x[\dA-Fa-f]+|-?(\d+\.?\d*|\.\d+)/,
  keyword: /(and|as|case|catch|class|const|def|delete|die|do|else|elseif|esac|exit|extends|false|fi|finally|for|foreach|function|global|if|new|null|or|private|protected|public|published|resource|return|self|static|struct|switch|then|this|throw|true|try|var|void|while|xor)(?!\w|=)/,
  variable: /[\$\%\@](\->|\w)+(?!\w)|\${\w*}?/,
  define: /[$A-Z_a-z0-9]+/,
  op: /[\+\-\*\/=<>!]=?|[\(\)\{\}\[\]\.\|]/,
  other: /\S+/
});
  1. style your items
.ltd .comment {
  color: red;
}

.ltd .keyword {
  color: black;
}
var textarea = $("codeArea");
textarea.value = "<!DOCTYPE html>\n<html>\n\t" + "\n</html>";
decorator = new TextareaDecorator(textarea, parser);
var textarea = $("codeArea");
textarea.value = "<!DOCTYPE html>\n<html>\n\t" + "\n</html>";
decorator = new TextareaDecorator(textarea, parser);
bindKey(textarea, {
  "Ctrl-1": e => {
    insertAtCursor("your  superb text", el);
    decorator.update();
  },
  "Shift-Ctrl-2": e => {
    alert("hello");
  }
});

see detailed examples in stories

In browser live syntax highlighting

JS

CSS

API

TextareaDecorator

  • new TextareaDecorator( textarea, parser ) Converts a HTML textarea element into an auto highlighting TextareaDecorator. parser is used to determine how to subdivide and style the content. parser can be any object which defines the tokenize and identify methods as described in the Parser API below.
  • .input The input layer of the LDT, a textarea element.
  • .output The output layer of the LDT, a pre element.
  • .update() Updates the highlighting of the LDT. It is automatically called on user input. You shouldn't need to call this unless you programmatically changed the contents of the textarea.

Parser

  • new Parser( [rules], [i] ) Creates a parser. rules is an object whose keys are CSS classes and values are the regular expressions which match each token. i is a boolean which determines if the matching is case insensitive, it defaults to false.
  • .add( rules ) Adds a mapping of CSS class names to regular expressions.
  • .tokenize( string ) Splits string into an array of tokens as defined by .rules.
  • .identify( string ) Finds the CSS class name associated with the token string.

Keybinder

This is a singleton, you do not need to instantiate this object.

  • .bindKey( element, [keymap] ) Adds Keybinder methods to element, optionally setting the element's keymap.

SelectHelper

This is a singleton, you do not need to instantiate this object.

  • .add( element ) Adds SelectHelper methods to element.
  • element.insertAtCursor( string ) Inserts string into the element before the current cursor position.