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

@tblt/react-equation

v1.0.1

Published

A react renderer for ASTs generated by equation-parser/equation-resolver

Downloads

1

Readme

react-equation – Parse, evaluate and render equation from plain text

A react render-layer for equation-parser and equation-resolver.

Quick-start

Install the package. Optionally add equation-resolver as a direct dependency, if you want functions and variables.

npm install -S react-equation equation-resolver

or

yarn add react-equation equation-resolver

Start rendering equations

import React from 'react'
import ReactDOM from 'react-dom'
import { Equation, EquationEvaluate, EquationOptions, defaultErrorHandler } from 'react-equation'
import { defaultVariables, defaultFunctions } from 'equation-resolver'

ReactDOM.render((
    <>
        <EquationOptions
            variables={defaultVariables}
            functions={defaultFunctions}
            errorHandler={defaultErrorHandler}
        >
            <Equation
                value='5m + 1/2m * sin(π) + (22 m^2) / (2m)'
            />
            <EquationEvaluate
                value='5m + 1/2m * sin(π) + (22 m^2) / (2m)'
            />
        </EquationOptions>
    </>
), document.getElementById("root"));

More in-depth examples: https://codesandbox.io/s/react-equation-example-t0oe8

Components

All the included components are split up in the interest of allowing tree-shaking to reduce the bundle-size by avoiding either the parser, the resolver or both, depending on needs.

All the components can have variables, functions, simplifyableUnits, errorHandler, className and style. These props can also be passed along through the EquationOptions context-provider.

Equation

Parse the string provided as value and render it. No evaluation is done.

Example:

<Equation
    value='2 + a'
/>
// Renders a prettified 2 + a

EquationEvaluate

Parse the string provided as value, evaluate it and render the formatted equation.

Example:

<EquationEvaluate
    value='2 + a'
    variables={{ a: { type: 'number', value: 5 }}}
/>
// Renders a prettified 2 + a = 7

EquationPreparsed

Render a pre-parsed equation provided as value. No evaluation is done.

Example:

<EquationPreparsed
    value={{ type: 'plus', a: { type: 'number', value: '2' }, b: { type: 'variable', name: 'a' } }}
/>
// Renders a prettified 2 + a

EquationEvaluatePreparsed

Evaluate a pre-parsed equation provided as value and render the formatted equation.

Example:

<EquationEvaluatePreparsed
    value={{ type: 'plus', a: { type: 'number', value: '2' }, b: { type: 'variable', name: 'a' } }}
    variables={{ a: { type: 'number', value: 5 }}}
/>
// Renders a prettified 2 + a = 7

Error handling

An error handler should be added either to the Equation-components or to EquationOptions, otherwise the raw errorType of the error is shown. If english errors suffice, simply import defaultErrorHandler. If custom errors (for instance for localisation), see ./src/errorHandler.ts for easy implementation.