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

monaco-textmate

v3.0.1

Published

Monaco TextMate grammar helpers

Downloads

17,673

Readme

This repository is a heavily modified version of original vscode-textmate package. It's been adjusted here and there to run inside web browsers. All of the file system calls have been removed, most of the API now uses Promises and grammars can no longer be loaded synchronously.

⚠ I'd prefer to see this repository where it really belongs. I request anyone from Microsoft to adopt this package as soon as possible.

Monaco TextMate

An interpreter for grammar files as defined by TextMate that runs on the web. Supports loading grammar files from JSON or PLIST format. Cross - grammar injections are currently not supported.

Installing

npm install monaco-textmate

Using

monaco-textmate relies on onigasm package to provide oniguruma regex engine in browsers. onigasm itself relies on WebAssembly. Therefore to get monaco-textmate working in your browser, it must have WebAssembly support and onigasm loaded and ready-to-go.

Make sure the example code below runs after onigasm bootstraping sequence described here has finished.

Example below is just a demostration of available API. To wire it up with monaco-editor use monaco-editor-textmate.

import { Registry } from 'monaco-textmate'

(async function test() {
    const registry = new Registry({
        // Since we're in browser, `getFilePath` has been removed, therefore you must provide `getGrammarDefinition` hook for things to work
        getGrammarDefinition: async (scopeName) => {
            // Whenever `Registry.loadGrammar` is called first time per scope name, this function will be called asking you to provide
            // raw grammar definition. Both JSON and plist formats are accepted.
            if (scopeName === 'source.css') {
                return {
                    format: 'json', // can also be `plist`
                    content: await (await fetch(`static/grammars/css.tmGrammar.json`)).text() // when format is 'json', parsed JSON also works
                }
            }
        }
    })

    const grammar = await registry.loadGrammar('source.css')

    console.log(grammar.tokenizeLine('html, body { height: 100%; margin: 0 }'))
    // > {tokens: Array(19), ruleStack: StackElement}
})()

onigasm is peer dependency that you must install yourself

Tokenizing multiple lines

To tokenize multiple lines, you must pass in the previous returned ruleStack.

var ruleStack = null;
for (var i = 0; i < lines.length; i++) {
	var r = grammar.tokenizeLine(lines[i], ruleStack);
	console.log('Line: #' + i + ', tokens: ' + r.tokens);
	ruleStack = r.ruleStack;
}

API doc

See the main.ts file

Developing

  • Clone the repository
  • Run npm install
  • Compile in the background with npm run watch

Credits

99% of the code in this repository is extracted straight from vscode-textmate, which is MIT licensed. Other external licenses used can be found in ThirdPartyNotices.txt

License

MIT