# mathtokenizer

> Math expression tokenizer

Latest version **1.1.0** (published 2021-05-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install mathtokenizer
pnpm add mathtokenizer
yarn add mathtokenizer
bun add mathtokenizer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-05-19 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ilyas Touyle |
| Maintainers | ilyastouyle |
| Keywords | tokenizer |

## Links

- npm: https://www.npmjs.com/package/mathtokenizer
- Repository: https://github.com/ilyastouyle/mathTokenizer
- Homepage: https://github.com/ilyastouyle/mathTokenizer#readme
- Issues: https://github.com/ilyastouyle/mathTokenizer/issues
- npm.io page: https://npm.io/package/mathtokenizer

## Recent versions

- 1.1.0 (latest) — 2021-05-19
- 1.0.8 — 2021-05-11
- 1.0.7 — 2021-05-10
- 1.0.6 — 2021-05-05
- 1.0.5 — 2021-04-29
- 1.0.4 — 2021-04-28
- 1.0.3 — 2021-04-26
- 1.0.2 — 2021-04-25
- 1.0.1 — 2021-04-25
- 1.0.0 — 2021-04-25

## README

# Math Tokenizer

## Install

	npm install mathtokenizer


## Math expression tokenizer for expression validation
	token: class for token object {type, value}
	tokenize: function that takes in math expression and returns 
	array with tokens, also takes in an optional integer [0-2] variable for choosing 
	only a delimiter as a function delimiter. Default is 3, which doesn't force any 
	particular delimiter and recognizes as function any alphanumerical
	expression **right before** the opening delimiter. 

> tokenize(__expr__, __index(optional)__) 

| 	Index 	| 			  Delimiter 			|
| 	:---:	| 				:---:				|
| 	0		| 				  (					|
| 	1		|				  {					|
|	2		|				  [					|
|	3		|	Default	no particular delimiter |

	In the new version (^1.1.0), it's no longer lparenthesis or rparenthesis, it's rather
	ldelimiter, rdelimiter.

### Example1:
	let tokenizer = require('mathtokenizer')
	let A = tokenizer.tokenize("sin(-3x)")
	console.log(A)
	/*Code produced:
		[
		  token { type: 'function', value: 'sin' },
		  token { type: 'ldelimiter', value: '(' },
		  token { type: 'unary_operator', value: '-' },
		  token { type: 'number', value: '3' },
		  token { type: 'operator', value: '*' },
		  token { type: 'variable', value: 'x' },
		  token { type: 'rdelimiter', value: ')' }
		]
	*/

### Example2:
	let tokenizer = require('mathtokenizer')
	let A = tokenizer.tokenize("f1(x+2)")
	console.log(A)
	/*Code produced:
		[
		  token { type: 'function', value: 'f1' },
		  token { type: 'ldelimiter', value: '(' },
		  token { type: 'variable', value: 'x' },
		  token { type: 'operator', value: '+' },
		  token { type: 'number', value: '2' },
		  token { type: 'rdelimiter', value: ')' }
		]
	*/

### Example3:
#### Same as in example2, but this time with the optional argument being assigned the value 1: curly braces

	let tokenizer = require('mathtokenizer')
	let A = tokenizer.tokenize("f1(x+2)", 1) //Optional argument is given 1
	console.log(A)
	/*Code produced:
		[
		  token { type: 'variable', value: 'f1' }, //f1 is recognized as a variable this time because it's followed by a parenthesis and not a curly brace
		  token { type: 'operator', value: '*' },
		  token { type: 'ldelimiter', value: '(' },
		  token { type: 'variable', value: 'x' },
		  token { type: 'operator', value: '+' },
		  token { type: 'number', value: '2' },
		  token { type: 'rdelimiter', value: ')' }
		]
	*/

---
_Source: https://npm.io/package/mathtokenizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
