call-stack
call-stack module (originally by Finley.Z.M.F) current version: v0.0.1
Installation
npm install call-stack
Example
var stack = require('call-stack')();
stack.push('item0', 'item1');
stack.push('item2');
stack.each(function(val, i) {
console.log('pointer %d: %s', i, val);
});
stack.pointer = 0;
console.log('set pointer to %d', stack.pointer);
stack.alloc('123'); // output: item0
stack.alloc('123'); // output: item1
stack.alloc('123'); // output: item2
stack.alloc('123'); // output: 123
API
Factory: Callstack([name][, maxLayers][, constructor])
- name String Default='anonymous'
- maxLayers Number Default=10
- constructor Function
The factory function to create a new call-stack object. Returns call-stack, used to chain calls.
Set the call-stack name to name
.
Use maxLayers
to limit the length of the call-stack layers.
If you call the stack.alloc
, might be executed constructor.
stack.setMaxLayers(n)
- n Number
Limit the length of the call-stack layers.
If n
is't a positive number, throws a type error.
Returns call-stack, used to chain calls.
stack.previous()
Returns the call-stack previous layer.
See Getter: Interface.__previous
.
stack.current()
Returns the call-stack current layer.
See Getter: Interface.__current
.
stack.next()
Returns the call-stack next layer.
See Getter: Interface.__next
.
stack.end()
Returns the call-stack current layer.
See Getter: Interface.__end
.
stack.reset(n)
Returns the call-stack current layer.
See Setter: Interface.pointer
.
stack.push(payer[, ...])
- layer Mixed
Append the stack layers. Returns call-stack, used to chain calls.
stack.each(iterate[, context])
- iterate Function
- context Mixed
By moving the stack pointer to traverse the stack layers.
Returns false if the iterator will break through.
If we want to continue to walk through, this stack pointer must move one step to the right.
If iterate
is't a function, throw a type error.
stack.alloc([...])
Allocate stack layers.
When the stack layer assignment is completed, if you configured a constructor for the call-stack the parameters of this method could be used on the stack constructor.
Returns a call-stack layer or a results of ran constructors.
Getter and Setter
See Callstack.Interface
.
Interface: Callstack.Interface([name][, functional])
- name String Default='anonymous'
- functional Function
This interface function only for the basic properties of a call-stack object.
Set the call-stack name to name
.
Use functional
to extend the properties and methods of the call-stack.
Getter: stack.name
The name of call-stack. It is a string type.
Getter: stack.length
The length of the call-stack. It is a number type.
Getter: stack.pointer
The pointer position of the call-stack. It is a number type.
Setter: stack.pointer = n
- n Number
Configure the stack pointer.
If n
is't a positive number or n
is invalid for the pointer position, throw a type error.
Getter: stack.isEnd
This value is true, if moved pointer to the end of the call-stack. It is a boolean type.
Getter: stack.isInvalid
This value is true, if the pointer is invalid. It is a boolean type.
Getter: stack.__previous
The previous call-stack layer. The stack pointer is not in the starting position, referencing the property, this stack pointer will move one step to the left.
Getter: stack.__current
The current call-stack layer.
Getter: stack.__next
The next call-stack layer. The stack pointer is not in the starting position, referencing the property, this stack pointer will move one step to the right.
Getter: stack.__end
The last call-stack layer. The stack pointer is not in the starting position, referencing the property, this stack pointer will move to the end.
Setter: stack.__append
Append the call-stack layer. If the call-stack has one or more layers, this call-stack pointer will move one step to the right.
License
Callstack is licensed under the MIT license.
Copyright(c) 2015 Finley.Z.M.F
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.