Skip to content

JJ/stack-key-value

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stack-data

NPM version Build Status Coveralls Status Dependency Status DevDependency Status

Simple object stack implementation on ES6

It is based on stack-data, with the added capability to work as a hash

Install

npm install --save stack-object

Usage

2 ways for adding element in stack:

  • in constructor new Stack({ "foo": 1},{"2":3},{"bar":[3,[4, 5],6]);
  • via push(elem) method
// Examples of using stack-data

//Added stack elements in constructor
let preInitStack = new Stack({ "foo": 1},{"2":3},{"bar":[3,[4, 5],6]);
preInitStack.size;       //5

//Added elements classically via push()
let stack = new Stack();
stack.size;              //0
stack.push(1).push({ "yahoo": "2"} );
stack.size;              //2
stack.pop();             //"2"
stack.size;              //1
stack.peek();            //1
stack.size;              //1

API

push(elem)

push - Pushes object into stack. Throws an StackException when parameter is empty and and "NotAKeyValue" if it is not a key-value pair.

elem

Required
Type: Object

elem - object which will be putted into stack

pop()

pop - Takes top element from the stack. Throws an StackException when the stack is empty.

peek()

peek - Peeks at the top element of the stack. Throws an StackException when the stack is empty.

size

size - Returns the size of the stack.

License

MIT © Aleksandr Filatov greybax@gmail.com

About

Simple stack imlementation on ES6

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%