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

rainbowbrackets

v2.0.2

Published

colorizes brackets, parentheses and braces to help track scope

Downloads

131

Readme

new hero

rainbowBrackets: a codeMirror Extension


This is a working attempt at a rainbowBracket extension for CodeMirror6.

What are rainbow brackets?

Great question! Rainbow Brackets are brackets, curly braces, or parentheses that change color with scope/depth. See intelliJ's Rainbow Bracket Extension.

Demo

rainbow-bracket-demo-npm

Live Implementation:

CodePen GPT

Table of Contents

Features

  • Depth/Scope detection
  • 7 customizable bracket classes
  • Default colors: Red Orange Yellow Green Blue Indigo Violet
  • Implementation agnostic
  • Theme agnostic

Usage/Examples

Depending on your theme and extensions, the rainbowBrackets may not apply correctly as the span structure looks something like this, where the color of the inner span will override the rainbow-bracket. Investigate with Chrome Dev Tools if you're encountering a bug.

Nearly Fixed as of 2.0.0. See updated API Reference.

<span class="rainbow-bracket-orange">
  <span class="ͼ5k">{</span> //opening bracket displaying theme color
</span>

To work around this, we can add the following CSS.

.rainbow-bracket-red > span {
  color: red;
}

.rainbow-bracket-orange > span {
  color: orange;
}

.rainbow-bracket-yellow > span {
  color: yellow;
}

.rainbow-bracket-green > span {
  color: green;
}

.rainbow-bracket-blue > span {
  color: blue;
}

.rainbow-bracket-indigo > span {
  color: indigo;
}

.rainbow-bracket-violet > span {
  color: violet;
}

This will override the inner span. Future implementations should ensure the rainbowBracket has higher precedence.

@uiw/react-codemirror

import rainbowBrackets from 'rainbowbrackets'

const cmExtensions = [/*Your Other Extensions */, rainbowBrackets()]

//...

<CodeMirror
  //other props
  extensions={cmExtensions}
>

codemirror package

coming soon...handle as you would an existing extension

vanilla javascript

coming soon...handle as you would an existing extension

API Reference

Class Structure

1.0.1
.rainbow-bracket-red {color: 'red'}
.rainbow-bracket-orange {color: 'orange'}
.rainbow-bracket-yellow {color: 'yellow'}
.rainbow-bracket-green {color: 'green'}
.rainbow-bracket-blue {color: 'blue'}
.rainbow-bracket-indigo {color: 'indigo'}
.rainbow-bracket-violet {color: 'violet'}
2.0.0
.rainbow-bracket-red: { color: 'red' }
.rainbow-bracket-red > span: { color: 'red' }
.rainbow-bracket-orange: { color: 'orange' }
.rainbow-bracket-orange > span: { color: 'orange' }
.rainbow-bracket-yellow: { color: 'yellow' }
.rainbow-bracket-yellow > span: { color: 'yellow' }
.rainbow-bracket-green: { color: 'green' }
.rainbow-bracket-green > span: { color: 'green' }
.rainbow-bracket-blue: { color: 'blue' }
.rainbow-bracket-blue > span: { color: 'blue' }
.rainbow-bracket-indigo: { color: 'indigo' }
.rainbow-bracket-indigo > span: { color: 'indigo' }
.rainbow-bracket-violet: { color: 'violet' }
.rainbow-bracket-violet > span: { color: 'violet' }

Development

git fork, clone, then navigate into this repository.

Install dependencies:

  npm install

See Contributing. TLDR: Make a branch with your feature name/bug fix, include detailed commit log and PR message.

Roadmap

  • More testing across a wide range of functions, scopes, languages, etc

FAQ

Does this work for controlled and uncontroleld CodeMirror Components?

Yes! Although it's likely there are unknown bugs I have yet to encounter.

Can I change the colors?

Yes! See the API reference above. If you want to change red to pink, simply use a little CSS:

.rainbow-bracket-red {
    color: pink;
}
/* Override may be neccessary as well*/
.rainbow-bracket-red > span {
    color: pink;
}

I'll rename these classes if enough people want color flexibility to something more intuitive.

Contributing

See contributing.md to get started.

Please adhere to this project's code of conduct.

License

MIT

Related

CodeMirror HomePage

CodeMirror Extensions

CodeMirror Extensions Forum Discussion

CodeMirror-React

IntelliJ RainbowBrackets

Closing

This extension is still experimental and it may not perfectly colorize scope. It still may be useful, or at least fun to use. Improvements are welcome. Big thank you to Marijn Haverbeke, the CodeMirror community, and all its contributors.