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 🙏

© 2026 – Pkg Stats / Ryan Hefner

qwick-maffs

v0.5.0

Published

Support simple mathmatical expressions in numeric inputs. Written to be completely framework agnostic.

Readme

QwickMaffs

A small, (runtime-)dependency-free library to support simple arithmetic in input fields.

Install

QwickMaffs is available as an NPM package.

npm install qwick-maffs

Alternatively, you can find the files needed for shipping the library in the dist folder.

You can either use the UMD version for CommonJS and AMD, or an esmodule.

Usage

QwickMaffs has two functions, bind to automatically configure an input to execute math expressions, and exec to manually run a math expression.

Binding to an input

The bind function is the easy way to use QwickMaffs. It take an input and makes it so it automatically processes the any math term when the user presses enter or the input looses focus.

It also adds an undo feature, where pressing ESC during editing reverts all changes since the input gained focus.

import { bind } `qwick-maffs/input.js`;

const qmInput = bind(input, {
	// See `exec` below for more options.

	// Set to `true` to remove the undo feature of the ESC key
	noUndo: false,

	onValueChanged(val: number) {
		// Called when an expression is executed successfully
	}

	onError(err: QMError /* -> see Error handling */) {
		// Called when an invalid expression was entered
	}, 

	onUndo(prev: string) {
		// Called when the user pressed ESC and the value was reset. `prev` contains the text value
		// before the undo was executed.
	}
});

// qmInput here is the same object as input, but with addition type info for TypeScript, so it
// can type-check the custom html events

qmInput.addEventListener('qmvaluechange', (e) => {
	// Same as the `onValueChanged` callback in `bind`. The value can be accessed through
	// `e.details`
});

qmInput.addEventListener('qmerror', (e) => {
	// Same as the `onError` callback in `bind`. The error can be accessed through `e.details`
});

qmInput.addEventListener('qmundo', (e) => {
	// Same as the `onUndo` callback in `bind`. The previous value can be accessed through
	// `e.details`
});

Manual Usage

The exec function can be used to execute a math expression.

exec('4 + 4') //=> returns 8

You can also provide a set of options with to the exec call:

import { exec, Errors, DefaultOptions } `qwick-maffs`;

QwickMaffs.exec('4 + 4', {
	decimalSep: /[,.]/,     // Either a string or a regex that indicates what symbol is accepted as a decimal separator.

	supportENotation: true, // Indicates if e-notation should be allowed. If false, it will complain about e not being
	                        // an UnexpectedSymbol
	
	// Makes it exec will not return these errors. The parser will instead try to take a best guess at what the user
	// tried to accomplish.
	// E.g. MultipleNumbers will multiply the numbers, and UnbalancedParenthesis will be balanced automatically
	ignoreErrors: Errors.MultipleNumbers | Errors.UnbalancedParenthesis,
	
	// Sets the operators supported in the expression. Here, we take all default operators and add "%", which divides a
	// number by 100
	operators: [
		...DefaultOptions.operators,
		{
			op: '%',
			assoc: 'suffix',
			precedence: 3,
			apply: (x) => x / 100,
		},
	],

	// Constant values available. 
	constants: {
		...DefaultOptions.constants,
		'e': Math.E,
	},
	
	// Functions available. Functions are called by their name followed by
	// parenthesis with the parameters.
	// Here, we add `min` and `max` function.
	functions: {
		...DefaultOptions.functions,
		min: Math.min,
		max: Math.max,
	}
})

Error handling

The exec function can return an error object if the expression cannot be parsed or executed. These error objects look like this:

{
	type: 0, // An enum value. Can be one of the following from the `QwickMaffs.Errors` enum:
	         // UnbalancedParenthesis: There are too few or too many parentesis. If there are too few, pos will be at
	         //                        the end of the string.
	         //
	         // UnexpectedSymbol: A symbol that we don't know what to do with.
	         //
	         // IncorrectNumberOfParameters: The operator at the given position cannot execute, because it doesn't have
	         //                              the needed numbers.
	         //
	         // MultipleNumbers: After executing all the operators, there are more than one number left. Pos is the
	         //                  position of the second number
	         //
	         // NoNumbers: The expression or a subexpression in parentesis contains no numbers.

	pos: 0, // The position of the input string where the error occured.
	len: 0  // The length of the error
}