Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onsetsu/stack-es2015-module
The stack data type as es2015 module
https://github.com/onsetsu/stack-es2015-module
Last synced: 27 days ago
JSON representation
The stack data type as es2015 module
- Host: GitHub
- URL: https://github.com/onsetsu/stack-es2015-module
- Owner: onsetsu
- License: mit
- Created: 2016-06-30T17:23:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-15T13:27:46.000Z (almost 5 years ago)
- Last Synced: 2024-04-23T22:10:02.318Z (7 months ago)
- Language: JavaScript
- Size: 92.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stack-es2015-module [![Build Status](https://travis-ci.org/onsetsu/stack-es2015-module.svg?branch=master)](https://travis-ci.org/onsetsu/stack-es2015-module)
A simple stack data structure provided as es2015 module.## Installation
As npm for Node.js:
```
$ npm install stack-es2015-module --save
```Or download the [bundle](https://raw.githubusercontent.com/onsetsu/stack-es2015-module/master/dist/stack-es2015-modules.js) file.
## Building
```
$ npm run-script build
```creates the *bundle* file in the `dist` folder.
## Testing
As npm package:
```
$ npm test
```## Example
```js
import Stack from 'stack-es2015-module';let stack = new Stack();
stack.push(42);
stack.push(17);
stack.top(); // 17
stack.pop();
stack.top(); // 42
stack.withElement(33, () => {
stack.top(); // 33
});
```## API
### Stack()
Initializes a new empty `Stack`.
### Stack#top()
Returns the top element of the stack.
### Stack#pop()
Pops the top element of the stack.
### Stack#push(element)
Pushes the `element` at the top of the stack.
### Stack#withElement(element, callback, context)
Pushes the `element` at the top of the stack and executes the `callback` with the optional `context`.
After successfully returning from the `callback` or upon an uncatched error, the top element is poped from the stack.## Licence
MIT