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

monacode

v0.3.1

Published

A thin es-module wrapper around the monaco editor and prettier

Downloads

417

Readme

Monacode

A thin es-module wrapper around the monaco editor and prettier

Exploring the feasibility of importing the monaco-editor (which powers VS Code) and prettier modules directly into the browser; aiming to make it one line easy to bring a native like code editing experiences to web applications without a build step.

Ships with all the features usually found in VS Code out of the box: things like code hints, type inference, minimap, command pallet, multi-cursor select, find and replace, code folding etc.

In addition to these features, prettier has been integrated so that hitting ⌘ + s will format the code.

⚡️ Check out the hosted version at https://monacode.live

Usage

Install the module as an npm module and import it using the bare module specifier, or import it directly from unpkg:

import monacode from 'https://unpkg.com/monacode/index.min.js'; // 976Kb brotli

// Create a new editor and attach to the document body
const editor = monacode({
  container: document.body,
  value: 'const add = (x, y) => x + y;',
});

// Listen for changes within the editor
editor.getModel().onDidChangeContent((change) => {
  const newValue = editor.getValue();
  console.log(newValue);
});

It is also possible to embed the editor into your application using an iframe (see demo):

<iframe src="https://monacode.live?theme=vs-light"></iframe>

Pass config options into the iframe as URL search parameters, for example ?theme=vs-light&value=console.log('hey'). It is not currently possible to pass in nested config options but hopefully will be in the future.

API

The module exports a single default function which accepts a config object as an argument. The supplied config gets merged with a default config which itself is a subset of the options available to configure moanco editors. Some useful values to know include:

  • container: an HTML element that exists in the DOM (or a ref if using react/preact)
  • value: a string representing the initial code to be rendered within the editor
  • language: a string representing what language the editor should try syntax highlight and hint for
  • fontSize: a number indicating what pixel font size code should render at
  • theme: a string identifier of the desired theme or a url to a theme json file

Calling the default export returns an instance of the underlying monaco editor. Find out more about how to interact with the editor by reading the API documentation.

Development

Running the following command from the root of this project uses servor to start a dev server, then open your editor and browser on the appropriate localhost url.

npm start

Production

Running the following command from the root of this project uses esbuild build the source to a single index.min.js file. Currently this process takes ~1second and results in an output file weighing 4.6MB (commpresses down to less than 1MB with brotli).

npm run build

License

Licensed under the MIT License.