Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stefanwimmer128/postfix.js

Use postfix notation in JavaScript
https://github.com/stefanwimmer128/postfix.js

Last synced: 2 days ago
JSON representation

Use postfix notation in JavaScript

Awesome Lists containing this project

README

        

# postfix.js

Complex features made easy

``` bash
$ yarn add [-D] postfix.js
# or
$ npm i -D postfix.js
```

## ES6 import

``` js
import postfix, {
stackify,
} from "postfix.js";
```

## CommonJS require

``` js
var postfix = require("postfix.js").default;
stackify = require("postfix.js").stackify;
```

## UMD bundle

`dist/core.js` and `dist/core.min.js` are UMD bundles.

``` js
/* Using AMD require */
require([
"https://unpkg.com/postfix.js",
], function (postfix) {
// postfix
// postfix.stackify
});
```

``` html

```

# Usage

``` js
postfix("60 5 7 5 - * /"); // [ 6 ]
postfix("60 5 / 7 5 - *"); // [ 24 ]

postfix("1 2 x -", {
"x": stack => stack.reverse(),
}); // [ 1 ]

postfix("-1 abs", {
"abs": stackify(Math.abs),
}); // [ 1 ]
```

Nativly supported operations: `+`, `-`, `*`, `/`, `%` and `^` (`Math.pow`)