Gathering detailed insights and metrics for easy-stack
Gathering detailed insights and metrics for easy-stack
Gathering detailed insights and metrics for easy-stack
Gathering detailed insights and metrics for easy-stack
npm install easy-stack
Typescript
Module System
Min. Node Version
Node Version
NPM Version
100
Supply Chain
99.4
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
254,335,562
Last Day
93,441
Last Week
792,756
Last Month
4,171,430
Last Year
49,987,621
6 Stars
7 Commits
1 Forks
3 Watching
1 Branches
1 Contributors
Latest Version
1.0.1
Package Id
easy-stack@1.0.1
Size
4.38 kB
NPM Version
6.14.8
Node Version
14.11.0
Publised On
11 Nov 2020
Cumulative downloads
Total Downloads
Last day
-50.7%
93,441
Compared to previous day
Last week
-19.5%
792,756
Compared to previous week
Last month
2.2%
4,171,430
Compared to previous month
Last year
-6.5%
49,987,621
Compared to previous year
No dependencies detected.
JS Stacks are different from queues because they are LIFO (last in first out) unlike a queue which is FIFO (first in first out). While a Queue executes in order, a stack executes whatever was most recently added to the stack, much like a reading a stack of papers on your desk. If you read half the papers and someone puts more on the top you start with the new ones first.
Works great in node.js, webpack, browserify, or any other commonjs loader or compiler. To use in plain old vanilla browser javascript without common js just replace the requires in the examples with script tags. We show that below too. Any time you need a JS stack easy-stack is there for you.
require('easy-stack');
for ES6 node.
require('easy-stack/es5.js');
for ES5 node and browser.
npm install easy-stack
npm info : See npm trends and stats for easy-stack
GitHub info :
Package details websites :
This work is licenced via the DBAD Public Licence.
key | type | parameters | default | description |
---|---|---|---|---|
add | function | any number of functions | adds all parameter functions to stack and starts execution if autoRun is true, stack is not already running and stack is not forcibly stopped | |
next | function | executes next item in stack if stack is not forcibly stopped | ||
clear | function | removes remaining items in the stack | ||
contents | Array | stack instance contents | ||
autoRun | Bool | true | should autoRun stack when new item added | |
stop | Bool | false | setting this to true will forcibly prevent the stack from executing |
1 2 var Stack=require('easy-stack'); 3 //create a new Stack instance 4 var stack=new Stack; 5 6 for(var i=0; i<50; i++){ 7 //add a bunch of stuff to the stack 8 stack.add(makeRequest); 9 } 10 11 function makeRequest(){ 12 //do stuff 13 console.log('making some request'); 14 15 this.next(); 16 } 17
The only difference is including via a script tag instead of using require.
1 2 <html> 3 <head> 4 <!-- this is the only difference --> 5 <script src='./es5.js'></script> 6 <script> 7 console.log('my awesome app script'); 8 var stack=new Stack; 9 10 for(var i=0; i<50; i++){ 11 stack.add(makeRequest); 12 } 13 14 function makeRequest(){ 15 console.log('making some request'); 16 17 this.next(); 18 } 19 </script> 20 </head> 21 <body> 22 </body> 23 </html> 24
This allows you to start adding requests immediately and only execute if the websocket is connected. To use in plain browser based JS without webpack or browserify just replace the requires with the script tag.
1 2 var Stack=require('easy-stack'); 3 4 //ws-share just makes it easier to share websocket code and ensure you don't open a websocket more than once 5 var WS=require('ws-share'); 6 7 //js-message makes it easy to create and parse normalized JSON messages. 8 var Message=require('js-message'); 9 10 //create a new Stack instance 11 var stack=new Stack; 12 13 //force stop until websocket opened 14 stack.stop=true; 15 16 var ws=null; 17 18 function startWS(){ 19 //websocket.org rocks 20 ws=new WS('wss://echo.websocket.org/?encoding=text'); 21 22 ws.on( 23 'open', 24 function(){ 25 ws.on( 26 'message', 27 handleResponse 28 ); 29 30 //now that websocket is opened allow auto execution 31 stack.stop=false; 32 stack.next(); 33 } 34 ); 35 36 ws.on( 37 'error', 38 function(err){ 39 //stop execution of stack if there is an error because the websocket is likely closed 40 stack.stop=true; 41 //remove remaining items in the stack 42 stack.clear(); 43 throw(err); 44 } 45 ); 46 47 ws.on( 48 'close', 49 function(){ 50 //stop execution of stack when the websocket closed 51 stack.stop=true; 52 } 53 ); 54 } 55 56 //simulate a lot of requests being stackd up for the websocket 57 for(var i=0; i<50; i++){ 58 stack.add(makeRequest); 59 } 60 61 var messageID=0; 62 63 function handleResponse(e){ 64 var message=new Message; 65 message.load(e.data); 66 67 console.log(message.type,message.data); 68 } 69 70 function makeRequest(){ 71 messageID++; 72 var message=new Message; 73 message.type='testMessage'; 74 message.data=messageID; 75 76 ws.send(message.JSON); 77 78 this.next(); 79 } 80 81 startWS(); 82
1 2 const Stack=require('easy-stack'); 3 4 class MyAwesomestack extends Stack{ 5 6 isStopped(){ 7 return this.stop; 8 } 9 10 removeThirdItem(){ 11 this.contents.splice(2,1); 12 return this.contents; 13 } 14 }; 15 16
1 2 var Stack=require('easy-stack'); 3 4 //MyAwesomestack inherits from stack 5 MyAwesomestack.prototype = new Stack; 6 //Constructor will extend stack 7 MyAwesomestack.prototype.constructor = MyAwesomestack; 8 9 function MyAwesomestack(){ 10 //extend with some stuff your app needs, 11 //maybe npm publish your extention with easy-stack as a dependancy? 12 Object.defineProperties( 13 this, 14 { 15 isStopped:{ 16 enumerable:true, 17 get:checkStopped, 18 set:checkStopped 19 }, 20 removeThirdItem:{ 21 enumerable:true, 22 writable:false, 23 value:removeThird 24 } 25 } 26 ); 27 28 //enforce Object.assign for extending by locking down Class structure 29 //no willy nilly cowboy coding 30 Object.seal(this); 31 32 function checkStopped(){ 33 return this.stop; 34 } 35 36 function removeThird(){ 37 //get the stack content 38 var list=this.contents; 39 //modify the stack content 40 list.splice(2,1); 41 //save the modified stack content 42 this.contents=list; 43 44 return this.contents; 45 } 46 } 47
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/7 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More