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

react-ml

v0.4.1

Published

React-base, extensible user-facing language (= BBCode/WikiCode for the modern web).

Downloads

29

Readme

React ML

React-base, extensible user-facing language (think BBCode/WikiCode) for the modern web.

It allows you to enrich your user-generated content (comments, forum posts...) with custom, well-integrated features.

It compiles text written by your users to injection-safe JSX (React Elements) using rules defined by you.

Features

  • compiler works in the server or in the client so you can have a wonderful client-side editor but still compile on the server for maximum efficiency
  • completely extensible : ReactML allows you to define custom tags and associate them with custom React components
  • fast, based on React and htmldomparser2

Design goals

  • fast
  • comes with a basic set of custom tags inspired by BBCode
  • very easily extensible with you own markup
  • injection-safe (unless you want to allow tags like <script>, <iframe> or <style>, which you can)
  • allows you to generate unsafe-looking code in a safe way

Example

Using reaml-ml/app/presets/basic, the following text:

<b>Hello</b>
<div>Mess with DOM</div>
<i>World</i><script>alert("I'm evil")</script>
<link>github.com</link>
<iframe src='http://evil.me/evil.js'></iframe>
<image url='https://news.ycombinator.com/y18.gif'>HN</image>

gets compiled to

<ReactMLFragment>
  <ReactMLParagraph>
    <ReactMLBold>
      {'Hello'}
    </ReactMLBold>
  </ReactMLParagraph>
  <ReactMLParagraph>
    <ReactMLItalic>
      {'World'}
    </ReactMLItalic>
  </ReactMLParagraph>
  <ReactMLParagraph>
    <ReactMLLink url={'github.com'}>
      {'github.com'}
    </ReactMLLink>
  </ReactMLParagraph>
  <ReactMLParagraph>
    <ReactMLImage label={'HN'} url={'https://news.ycombinator.com/y18.gif'} />
  </ReactMLParagraph>
</ReactMLFragment>

which in turn will be rendered using React.render to

<div class="reactml-fragment">
  <div class="reactml-paragraph">
    <span class="reactml-b" style="font-weight:bold;">Hello</span>
  </div>
  <div class="reactml-paragraph">
    <span class="reactml-i" style="font-style:italic;">World</span>
  </div>
  <div class="reactml-paragraph">
    <a class="reactml-link" href="github.com">github.com</a>
  </div>
    <div class="reactml-paragraph">
    <img alt="HN" class="reactml-image" src="https://news.ycombinator.com/y18.gif"/>
  </div>
</div>

You can of course customize:

  • the existing components from the basic layout via CSS or overloading,
  • add or replace components with your own.

Basic usage

import ReactML from 'react-ml';

React.render(ReactML.compile('<b>Hello world</b>', ReactML.presets.basic));

Adding custom components

Components are defined by their tagname (eg. <image> has tagname image). It is then up to you to define which React Element will actually be mapped to your custom component. For example, if we wish to add a <red> component that will color its children in red, we would do the following:

compile(source, Object.assign({}, basicPreset, {
  red: (attribs, children, transformChildren) =>
    <span style={{ color: 'red' }}>
      {transformChildren(children)}
    </span>,
}));

The signature function for a component definition is:

(attribs: Object, children: Object, transformChildren: Function): React.Element

  • attribs contains the attributes of the current node, eg. attribs for <image bar='foo'> is { bar: 'foo' }
  • children contains the list of the children node,
  • transformChildren is a reference to the closured compile function to perform recursive transformation of the children list.

Each object in children can be destructured as { type, data } = child, where type can either be text, in which case the actual text content is in data, or tag, in which case data and the children object should be either ignored or passed to transformChildren.