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 πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

@yosefbeder/react-throwcode

v0.1.0

Published

- πŸ“¦ Small bundle-size - Only 3.84 kB (Minified + Gzipped). - 🌈 Code highlighting - Atom-light and Atom-dark themes. - [140 supported languages](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md) that can be configure

Readme

Features

  • πŸ“¦ Small bundle-size
    • Only 3.84 kB (Minified + Gzipped).
  • 🌈 Code highlighting
  • πŸ’β€β™‚οΈ Handling special characters (`,',",[,{, and ()
    • Adding the closing counterpart automatically.
    • Wrapping selected text with them.
  • ⏳ History
  • 🎨 Appearance customizations
    • Light and dark themes.
    • Line numbers.
  • πŸ“ƒ Auto-scrolling
    • Scrolls automatically to the position of the caret if it's out of the viewport.

Getting Started

Installation

npm install react-throwcode highlight.js lowlight hast-util-to-html

Simple Usage

The component imported from the package is a controlled component, and you can use it without configurations.

import { useState } from 'react';
import CodeEditor from 'react-throwcode';

import { lowlight } from 'lowlight/lib/core';
import javascript from 'highlight.js/lib/languages/typescript';

lowlight.registerLanguage(javascript, 'javascript');

function App() {
  const [code, setCode] = useState('');

  return (
    <div className="app">
      <CodeEditor
        language="javascript"
        value={code}
        onChange={text => setCode(text)}
      />
    </div>
  );
}

export default App;

Props

The data type of the options

interface CodeEditorProps {
  language: string;
  value: string;
  onChange: (content: string) => void;

  theme?: 'light' | 'dark';
  height?: number | 'auto' | string;
  spellCheck?: boolean;
  handleHistory?: boolean;
  handleSpecialCharacters?: boolean;
  highlight?: boolean;
  lineNumbers?: boolean;
  className?: string;
}

The default props

const defaultProps = {
  theme: 'light',
  height: 'auto',
  spellCheck: false,
  handleHistory: true,
  handleSpecialCharacters: true,
  highlight: true,
  lineNumbers: true,
};
  • value
    • Represents the code that is displayed.
    • If you want to update the code you just have to rewrite with setValue.
  • onChange
    • Takes a callback that receives content arg which is a string.
    • Is called whenever the content of the editor is changed whether it's changed by undoing/redoing or by the user typing.
  • theme
    • highlight.js is used as a peer dependency for highlighting.
    • I just included two themes in the library becuase I wanted it to be easier to use and the reason mentioned in caveats section.
  • language
// Note: You should import it from /lib/core
import { lowlight } from 'lowlight/lib/core';

// Import the language that you want from /lib/languages/$language-name
import typescript from 'highlight.js/lib/languages/typescript';

// Register the language
lowlight.registerLanguage('typescript', typescript);

// Add the language with the name that you registered it with
<CodeEditor
  language="typescript"
  value={code}
  onChange={text => setCode(text)}
/>;
  • height
    • You can either make it implicit by passing auto or explicit by passing a number or a string (a number with a unit).
  • spellCheck
    • Enables spell check.
  • handleHistory
    • Enables undoing and redoing.
  • handleSpecialCharacters
    • Closes quotes (```,',") and brackets ([,{,() automatically.
    • Wraps selected text with them.
  • highlight
    • Enables code highlighting.
  • lineNumbers
    • Enables line numbers.
  • className
    • Applies styles to the wrapper of the editor.

Using lowlight in other parts of your application

lowlight is a peer depedency for this library, so you should be able to use it in your app.

Unfortunatelly, when lowlight is installed in a project you can't use hljs.highlightAll function to highlight the other code blocks in your app.

I faced this problem while creating the home page of the library, so I had to come up with a solution.

// Register the language
import { lowlight } from 'lowlight/lib/core';
import typescript from 'highlight.js/lib/languages/typescript';

lowlight.registerLanguage('typescript', typescript);

// Import a theme from highlight.js themes
import 'highlight.js/styles/atom-one-light.css';

// Highlight all code blocks
document.querySelectorAll('pre > code').forEach(codeblock => {
  const language = codeblock.className.split('-')[1];
  const content = codeblock.innerText;

  // toHtml is imported from hast-util-to-html which is also a peer depedency
  codeblock.innerHTML = toHtml(lowlight.highlight(language, content));
  codeblock.classList.add('hljs');
});

Caveats

Due to the way this lib is implemented (a layer for highlighting and a layer for editing above it), You can only change the colors of the keywords, so I had to take to themes and modify them so that they don't change the style of the font.

Contribution

If you want to contribute run these commands

# Clone the repo
git clone https://github.com/yosefbeder/react-throwcode.git
# Compile the library whenever any file is changed
npm run start
cd ./example
# Start the development server of the demo version
npm run dev

LICENSE

MIT License 2021 Yosef Beder