es-stl
v2.0.0-beta.1
Published
EMCAScript Standard Template Library
Downloads
1
Maintainers
Readme
es-stl
EMCAScript Standard Template Library
Install
npm:
$ npm install --save es-stl
yarn:
$ yarn add es-stl
Usage
Using es5
const binarySearch = require('ts-stl/algm/binarySearch');
binarySearch([1, 3, 5], 3);// => 1
Using es6 or typescript
import binarySearch from 'ts-stl/algm/binarySearch';
binarySearch([1, 3, 5], 3);// => 1
Reference
Modules
Classes
Functions
algm/binarySearch ⇒ number
Binary Search
| Param | Type | Default | Description | | --- | --- | --- | --- | | arr | Array.<T> | | an array after sort from small to large | | searchVal | number | | | | [cb] | ISearchCb.<T> | giveBackCb | | | [left] | number | 0 | | | [right] | number | arr.length - 1 | |
algm/binarySearchByRange ⇒ number
Binary search by range.
| Param | Type | Description | | --- | --- | --- | | arr | Array.<T> | an object array after sort from small to large | | searchVal | number | | | cb | ISearchRangeCb.<T> | |
Example
const dataList = [{s:0, e: 5}, {s:6, e: 18}, {s:19, e: 30}, ...];
binarySearchByRange(dataList, 10, (range: number[], data: {s: number, e: number}) => {
range[0] = data.s;
range[1] = data.e;
});
// => 1
const dataList = [{s:0, e: 5}, {s:5, e: 18}, {s:18, e: 30}, ...];
binarySearchByRange(dataList, 10, (range: number[], data: {s: number, e: number}) => {
range[0] = data.s;
range[1] = data.e - 1;
});
// => 1
algm/binarySearchInRange ⇒ number
Binary search in range [a, b)
.
| Param | Type | Description | | --- | --- | --- | | arr | Array.<T> | an object array after sort from small to large | | searchVal | number | | | cb | ISearchCb.<T> | |
Example
const dataList = [{num: 0}, {num: 100}, {num: 300}, {num: 700}, {num: 1000}];
binarySearchInRange(dataList, 125, (data: { num: number }) => data.num);
// => 1
i = binarySearchInRange(dataList, -10, (data: { num: number }) => data.num);
// => -1
i = binarySearchInRange(dataList, 0, (data: { num: number }) => data.num);
// => 0
i = binarySearchInRange(dataList, 100, (data: { num: number }) => data.num);
// => 1
i = binarySearchInRange(dataList, 300, (data: { num: number }) => data.num);
// => 2
i = binarySearchInRange(dataList, 350, (data: { num: number }) => data.num);
// => 2
i = binarySearchInRange(dataList, 800, (data: { num: number }) => data.num);
// => 3
i = binarySearchInRange(dataList, 1000, (data: { num: number }) => data.num);
// => 4
i = binarySearchInRange(dataList, 2000, (data: { num: number }) => data.num);
// => 4
algm/exponentialSearch ⇒ number
Exponential Search
| Param | Type | Default | Description | | --- | --- | --- | --- | | arr | Array.<T> | | an array after sort from small to large | | searchVal | number | | | | [cb] | ISearchCb.<T> | giveBackCb | |
algm/interpolationSearch ⇒ number
Interpolation Search
| Param | Type | Default | Description | | --- | --- | --- | --- | | arr | Array.<T> | | an array after sort from small to large | | searchVal | number | | | | [cb] | ISearchCb.<T> | giveBackCb | |
algm/mergeSortArr ⇒ Array.<T>
To combine two sorted arrays into an array sorted by original rules
Returns: Array.<T> - new array
| Param | Type | Description | | --- | --- | --- | | arr1 | Array.<T> | an array after sort | | arr2 | Array.<T> | an array after sort | | cb | ISortCb.<T> | |
algm/mergeSortSingle ⇒ Array.<T>
Inserts an element into an sorted array, keeping the original order
| Param | Type | Description | | --- | --- | --- | | arr | Array.<T> | an array after sort | | el | T | | | cb | ISortCb.<T> | |
algm/unique
Array Unique
ds/BinarySortTree
Binary Sort Tree
- ds/BinarySortTree
- ~BinarySortNode
- ~BinarySortTree
- .root ⇒ BinarySortNode.<V>
- .isEmpty() ⇒ boolean
- .insert(key, value) ⇒ boolean
- .remove(key) ⇒ V | null
- .search(key, node) ⇒ BinarySortNode.<V> | null
- .getMinNode(node) ⇒ BinarySortNode.<V> | null
- .getMaxNode(node) ⇒ BinarySortNode.<V> | null
- .preOrder(cb)
- .inOrder(cb)
- .postOrder(cb)
- .clear()
ds/BinarySortTree~BinarySortNode
Binary sort tree node
Kind: inner class of ds/BinarySortTree
ds/BinarySortTree~BinarySortTree
Kind: inner class of ds/BinarySortTree
- ~BinarySortTree
- .root ⇒ BinarySortNode.<V>
- .isEmpty() ⇒ boolean
- .insert(key, value) ⇒ boolean
- .remove(key) ⇒ V | null
- .search(key, node) ⇒ BinarySortNode.<V> | null
- .getMinNode(node) ⇒ BinarySortNode.<V> | null
- .getMaxNode(node) ⇒ BinarySortNode.<V> | null
- .preOrder(cb)
- .inOrder(cb)
- .postOrder(cb)
- .clear()
binarySortTree.root ⇒ BinarySortNode.<V>
root
Kind: instance property of BinarySortTree
binarySortTree.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of BinarySortTree
binarySortTree.insert(key, value) ⇒ boolean
insert
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | key | number | | value | V |
binarySortTree.remove(key) ⇒ V | null
remove
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | key | number |
binarySortTree.search(key, node) ⇒ BinarySortNode.<V> | null
search
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | key | number | | node | BinarySortNode.<V> |
binarySortTree.getMinNode(node) ⇒ BinarySortNode.<V> | null
getMinNode
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | node | BinarySortNode.<V> |
binarySortTree.getMaxNode(node) ⇒ BinarySortNode.<V> | null
getMaxNode
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | node | BinarySortNode.<V> |
binarySortTree.preOrder(cb)
preOrder
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | cb | IOrderCb.<V> |
binarySortTree.inOrder(cb)
inOrder
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | cb | IOrderCb.<V> |
binarySortTree.postOrder(cb)
postOrder
Kind: instance method of BinarySortTree
| Param | Type | | --- | --- | | cb | IOrderCb.<V> |
binarySortTree.clear()
clear
Kind: instance method of BinarySortTree
ds/Graph
Graph
- ds/Graph
- ~Vertex
- ~Edge
- ~Graph
- new Graph(_isDirected)
- .vertexSize ⇒ number
- .edgeSize ⇒ number
- .isEmpty() ⇒ boolean
- .isDirected() ⇒ boolean
- .getVertex(key) ⇒ Vertex.<K, V, E> | undefined
- .setVertex(key, value) ⇒ Vertex.<K, V, E>
- .removeVertex(key) ⇒ Vertex.<K, V, E> | undefined
- .getEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
- .setEdge(fromKey, toKey, value) ⇒ Edge.<K, V, E> | undefined
- .removeEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
- .dfs(key, cb)
- .bfs(key, cb)
- .dijkstra(key, getWeight) ⇒ Dictionary.<K, number>
- .clear()
ds/Graph~Vertex
Vertex
Kind: inner class of ds/Graph
ds/Graph~Edge
Edge
Kind: inner class of ds/Graph
ds/Graph~Graph
Kind: inner class of ds/Graph
- ~Graph
- new Graph(_isDirected)
- .vertexSize ⇒ number
- .edgeSize ⇒ number
- .isEmpty() ⇒ boolean
- .isDirected() ⇒ boolean
- .getVertex(key) ⇒ Vertex.<K, V, E> | undefined
- .setVertex(key, value) ⇒ Vertex.<K, V, E>
- .removeVertex(key) ⇒ Vertex.<K, V, E> | undefined
- .getEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
- .setEdge(fromKey, toKey, value) ⇒ Edge.<K, V, E> | undefined
- .removeEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
- .dfs(key, cb)
- .bfs(key, cb)
- .dijkstra(key, getWeight) ⇒ Dictionary.<K, number>
- .clear()
new Graph(_isDirected)
| Param | Type | Default | | --- | --- | --- | | _isDirected | boolean | false |
graph.vertexSize ⇒ number
vertexSize
Kind: instance property of Graph
graph.edgeSize ⇒ number
edgeSize
Kind: instance property of Graph
graph.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Graph
graph.isDirected() ⇒ boolean
isDirected
Kind: instance method of Graph
graph.getVertex(key) ⇒ Vertex.<K, V, E> | undefined
getVertex
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K |
graph.setVertex(key, value) ⇒ Vertex.<K, V, E>
setVertex
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K | | value | V |
graph.removeVertex(key) ⇒ Vertex.<K, V, E> | undefined
removeVertex
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K |
graph.getEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
getEdge
Kind: instance method of Graph
| Param | Type | | --- | --- | | fromKey | K | | toKey | K |
graph.setEdge(fromKey, toKey, value) ⇒ Edge.<K, V, E> | undefined
setEdge
Kind: instance method of Graph
| Param | Type | | --- | --- | | fromKey | K | | toKey | K | | value | E |
graph.removeEdge(fromKey, toKey) ⇒ Edge.<K, V, E> | undefined
removeEdge
Kind: instance method of Graph
| Param | Type | | --- | --- | | fromKey | K | | toKey | K |
graph.dfs(key, cb)
dfs
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K | | cb | IIterateCb.<K, V, E> |
graph.bfs(key, cb)
bfs
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K | | cb | IIterateCb.<K, V, E> |
graph.dijkstra(key, getWeight) ⇒ Dictionary.<K, number>
dijkstra
Kind: instance method of Graph
| Param | Type | | --- | --- | | key | K | | getWeight | IGetWeightCb.<E> |
graph.clear()
clear
Kind: instance method of Graph
ds/Heap
Heap
- ds/Heap
- ~Heap
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .push(value, priority)
- .pop() ⇒ T | undefined
- .top() ⇒ T | undefined
- .fit()
- .clear()
- ~Heap
ds/Heap~Heap
Kind: inner class of ds/Heap
- ~Heap
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .push(value, priority)
- .pop() ⇒ T | undefined
- .top() ⇒ T | undefined
- .fit()
- .clear()
heap.size ⇒ number
size
Kind: instance property of Heap
heap.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Heap
heap.push(value, priority)
push
Kind: instance method of Heap
| Param | Type | | --- | --- | | value | T | | priority | number |
heap.pop() ⇒ T | undefined
pop
Kind: instance method of Heap
heap.top() ⇒ T | undefined
top
Kind: instance method of Heap
heap.fit()
fit
Kind: instance method of Heap
heap.clear()
Clear the heap
Kind: instance method of Heap
ds/Queue
Queue
- ds/Queue
- ~Queue
- new Queue([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .enqueue(el) ⇒ this
- .dequeue() ⇒ T | undefined
- .first() ⇒ T | undefined
- .last() ⇒ T | undefined
- .clear()
- ~Queue
ds/Queue~Queue
Kind: inner class of ds/Queue
- ~Queue
- new Queue([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .enqueue(el) ⇒ this
- .dequeue() ⇒ T | undefined
- .first() ⇒ T | undefined
- .last() ⇒ T | undefined
- .clear()
new Queue([arr])
| Param | Type | Default | | --- | --- | --- | | [arr] | Array.<T> | [] |
queue.size ⇒ number
size
Kind: instance property of Queue
queue.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Queue
queue.enqueue(el) ⇒ this
enqueue
Kind: instance method of Queue
| Param | Type | | --- | --- | | el | T |
queue.dequeue() ⇒ T | undefined
dequeue
Kind: instance method of Queue
queue.first() ⇒ T | undefined
Return the first element
Kind: instance method of Queue
queue.last() ⇒ T | undefined
Return the last element
Kind: instance method of Queue
queue.clear()
Clear the queue
Kind: instance method of Queue
ds/Set
Set
- ds/Set
- ~Set
- new Set([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .has(value) ⇒ boolean
- .add(value) ⇒ boolean
- .delete(value) ⇒ boolean
- .values() ⇒ Array.<T>
- .clear()
- .union(tar) ⇒ Set.<T>
- .intersect(tar) ⇒ Set.<T>
- .contain(tar) ⇒ boolean
- .difference(tar) ⇒ Set.<T>
- ~Set
ds/Set~Set
Kind: inner class of ds/Set
- ~Set
- new Set([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .has(value) ⇒ boolean
- .add(value) ⇒ boolean
- .delete(value) ⇒ boolean
- .values() ⇒ Array.<T>
- .clear()
- .union(tar) ⇒ Set.<T>
- .intersect(tar) ⇒ Set.<T>
- .contain(tar) ⇒ boolean
- .difference(tar) ⇒ Set.<T>
new Set([arr])
| Param | Type | Default | | --- | --- | --- | | [arr] | Array.<T> | [] |
set.size ⇒ number
size
Kind: instance property of Set
set.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Set
set.has(value) ⇒ boolean
has
Kind: instance method of Set
| Param | Type | | --- | --- | | value | T |
set.add(value) ⇒ boolean
add
Kind: instance method of Set
| Param | Type | | --- | --- | | value | T |
set.delete(value) ⇒ boolean
delete
Kind: instance method of Set
| Param | Type | | --- | --- | | value | T |
set.values() ⇒ Array.<T>
values Note: Return value is Set inner array
Kind: instance method of Set
set.clear()
clear
Kind: instance method of Set
set.union(tar) ⇒ Set.<T>
union
Kind: instance method of Set
| Param | Type | | --- | --- | | tar | Set.<T> |
set.intersect(tar) ⇒ Set.<T>
intersect
Kind: instance method of Set
| Param | Type | | --- | --- | | tar | Set.<T> |
set.contain(tar) ⇒ boolean
contain
Kind: instance method of Set
| Param | Type | | --- | --- | | tar | Set.<T> |
set.difference(tar) ⇒ Set.<T>
difference
Kind: instance method of Set
| Param | Type | | --- | --- | | tar | Set.<T> |
ds/Stack
Stack
- ds/Stack
- ~Stack
- new Stack([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .push(value) ⇒ this
- .pop() ⇒ T | undefined
- .top() ⇒ T | undefined
- .clear()
- ~Stack
ds/Stack~Stack
Kind: inner class of ds/Stack
- ~Stack
- new Stack([arr])
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .push(value) ⇒ this
- .pop() ⇒ T | undefined
- .top() ⇒ T | undefined
- .clear()
new Stack([arr])
| Param | Type | Default | | --- | --- | --- | | [arr] | Array.<T> | [] |
stack.size ⇒ number
size
Kind: instance property of Stack
stack.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Stack
stack.push(value) ⇒ this
push
Kind: instance method of Stack
| Param | Type | | --- | --- | | value | T |
stack.pop() ⇒ T | undefined
pop
Kind: instance method of Stack
stack.top() ⇒ T | undefined
Return the top element of the stack
Kind: instance method of Stack
stack.clear()
Clear the stack
Kind: instance method of Stack
utils/clamp ⇒ number
Clamps number
within the inclusive lower
and upper
bounds.
Returns: number - Returns the clamped number.
| Param | Type | Description | | --- | --- | --- | | num | number | The number to clamp. | | [lower] | number | The lower bound. | | upper | number | The upper bound. |
Example
clamp(-10, -5, 5);
// => -5
clamp(10, -5, 5);
// => 5
utils/Compare
Compare
- utils/Compare
- ~Compare
- .start([cb]) ⇒ TCompare
- .then([cb]) ⇒ TCompare
- .reverse() ⇒ TCompare
- .end() ⇒ ISortCb.<any>
- ~Compare
utils/Compare~Compare
Kind: inner class of utils/Compare
- ~Compare
- .start([cb]) ⇒ TCompare
- .then([cb]) ⇒ TCompare
- .reverse() ⇒ TCompare
- .end() ⇒ ISortCb.<any>
Compare.start([cb]) ⇒ TCompare
Start compare, The method must be called at first
Kind: static method of Compare
| Param | Type | Description | | --- | --- | --- | | [cb] | ICompareCb | If compare number array, You can not pass this parameter |
Compare.then([cb]) ⇒ TCompare
Then compare
Kind: static method of Compare
| Param | Type | Default | | --- | --- | --- | | [cb] | ICompareCb | giveBackCb |
Compare.reverse() ⇒ TCompare
Reverse
Kind: static method of Compare
Compare.end() ⇒ ISortCb.<any>
End compare, The method must be called at last
Kind: static method of Compare
utils/debounce ⇒ function
debounce
| Param | Type | | --- | --- | | cb | function | | delay | number |
Example
const d = debounce(console.log), 1000);
d(1);d(1);d(1);
// => 1
utils/ellipsis ⇒ string
String abbreviation with ellipsis
| Param | Type | Default | | --- | --- | --- | | str | string | | | num | number | | | [template] | string | "'...'" |
Example
ellipsis('0123456789', 4);
// => 0123...
ellipsis('012', 4);
// => 012
utils/error
Throw error
| Param | Type | | --- | --- | | msg | string |
utils/format ⇒ string
String format, just support %s
, it's simple, but useful.
Returns: string - Returns the formatted string.
| Param | Type | Description |
| --- | --- | --- |
| template | string | Text with placeholders for data
. |
| data | * | Data to interpolate into template
. |
Example
formats('The %s is %s.', 'code', 123);
=> The code is 123.
utils/formats ⇒ string
String format, just support %s
, it's simple, but useful.
Returns: string - Returns the formatted string.
| Param | Type | Description |
| --- | --- | --- |
| template | string | Text with placeholders for data
. |
| data | Array.<any> | Data to interpolate into template
. |
Example
formats('I like %s and %s.', ['swimming', 'skiing']);
=> I like swimming and skiing.
utils/getClass ⇒ string
Determine the internal JavaScript [[Class]] of an object.
Returns: string - Object to get the internal JavaScript [[Class]] of.
| Param | Type | Description | | --- | --- | --- | | value | * | value The value to check. |
Example
class Foo {
private f: number = 1;
}
getClass(new Foo()) === Foo;
// => true
getClass(undefined) === undefined;
// => true
getClass(null) === null;
// => true
getClass(true) === Boolean;
// => true
getClass(new Boolean()) === Boolean;
// => true
getClass(3) === Number;
// => true
getClass("test") === String;
// => true
getClass(new String("test")) === String;
// => true
getClass(function(){}) === Function;
// => true
getClass([]) === Array;
// => true
getClass(new Array()) === Array;
// => true
getClass(new Date()) === Date;
// => true
getClass(new Error()) === Error;
// => true
getClass(Symbol()) === Symbol;
// => true
getClass(Object(Symbol())) === Symbol;
// => true
getClass(/test/) === RegExp;
// => true
getClass(Date) === Function;
// => true
getClass(Date) === Date;
// => false
utils/hashCode ⇒ number
Get hash code from number or string.
| Param | Type | | --- | --- | | key | NumOrStr |
Example
hashCode(1001);
// => 1507424
hashCode('book');
// => 3029737
utils/inRange ⇒ boolean
Checks if num
is between start
and end
, such as start <= num <= end
Returns: boolean - Returns true
if number
is in the range, else false
.
| Param | Type | Description | | --- | --- | --- | | num | number | The number to check. | | start | number | The start of the range. | | end | number | The end of the range. |
Example
inRange(3, 2, 4);
// => true
inRange(4.5, 2, 4.5);
// => true
inRange(-3, -6, -2);
// => true
utils/isArrayLike ⇒ boolean
Checks if value
is array-like. A value is considered array-like if it's
not a function and not a window and has a value.length
that's an integer greater than or
equal to 0
and less than or equal to Number.MAX_SAFE_INTEGER
.
Returns: boolean - Returns true
if value
is array-like, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isArrayLike([1, 2, 3]);
// => true
isArrayLike(document.body.children);
// => true
isArrayLike('abc');
// => true
isArrayLike(noop);
// => false
isArrayLike(window);
// => false
utils/isBool ⇒ boolean
Checks if value
is classified as a boolean primitive or object.
Returns: boolean - Returns true
if value
is a boolean, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isBool(false);
// => true
isBool(null);
// => false
utils/isClass ⇒ boolean
Checks if value
is classified as a Class
primitive or object.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. | | Class | function | Which class. |
Example
isClass(Date, Function);
// => true
isClass(Date, Date);
// => false
isClass("test", String);
// => true
isClass(3, Number);
// => true
isClass(true, Boolean);
// => true
utils/isFunc ⇒ boolean
Checks if value
is classified as a Function
object.
Returns: boolean - Returns true
if value
is a function, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isFunc(noop);
// => true
isFunc(/abc/);
// => false
utils/isInt ⇒ boolean
Checks if value
is an integer.
Returns: boolean - Returns true
if value
is an integer, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isInt(3);
// => true
isInt(3.3);
// => false
isInt(Number.MAX_VALUE);
// => true
isInt(Number.MIN_VALUE);
// => false
isInt(Infinity);
// => false
isInt('3');
// => true
utils/isLength ⇒ boolean
Checks if value
is a valid array-like length.
Note: This method is loosely based on
ToLength
.
Returns: boolean - Returns true
if value
is a valid length, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isLength(3);
// => true
isLength(Number.MIN_VALUE);
// => false
isLength(Infinity);
// => false
isLength('3');
// => false
utils/isNum ⇒ boolean
Checks if value
is classified as a Number
primitive or object.
Returns: boolean - Returns true
if value
is a number, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isNum(3);
// => true
isNum(Number.MIN_VALUE);
// => true
isNum(Infinity);
// => true
isNum('3');
// => false
utils/isObj ⇒ boolean
Checks if value
is the
language type
of Object
. (e.g. arrays, functions, objects, regexes, new Number(0)
, and new String('')
)
Returns: boolean - Returns true
if value
is an object, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isObj({});
// => true
isObj([1, 2, 3]);
// => true
isObj(noop);
// => true
isObj(null);
// => false
utils/isObjLike ⇒ boolean
Checks if value
is object-like. A value is object-like if it's not null
and has a typeof
result of "object".
Returns: boolean - Returns true
if value
is object-like, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isObjLike({});
// => true
isObjLike([1, 2, 3]);
// => true
isObjLike(function(){});
// => false
isObjLike(null);
// => false
utils/isPlainObj ⇒ boolean
Checks if value
is a plain object, that is, an object created by the
Object
constructor or one with a [[Prototype]]
of null
.
Returns: boolean - Returns true
if value
is a plain object, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
function Foo() {
this.a = 1;
}
isPlainObj(new Foo);
// => false
isPlainObj([1, 2, 3]);
// => false
isPlainObj({ 'x': 0, 'y': 0 });
// => true
isPlainObj(Object.create(null));
// => true
utils/isStr ⇒ boolean
Checks if value
is classified as a String
primitive or object.
Returns: boolean - Returns true
if value
is a string, else false
.
| Param | Type | Description | | --- | --- | --- | | value | * | The value to check. |
Example
isStr('abc');
// => true
isStr(1);
// => false
utils/merge ⇒ T
Merge the contents of a object into the first object.
Returns: T - Returns object
.
| Param | Type | Description | | --- | --- | --- | | tar | T | An object that will receive the new properties. | | src | S | An object containing additional properties to merge in. | | deep | boolean | If true, the merge becomes recursive (aka. deep copy). passing false for this argument is not supported, default is true. |
Example
var object = {
'a': [{ 'b': 2 }, { 'd': 4 }]
};
var other = {
'a': [{ 'c': 3 }, { 'e': 5 }]
};
merge(object, other);
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
utils/mergeWith ⇒ T
Merge the contents of a object into the first object by customizer.
Returns: T - Returns object
.
| Param | Type | Description | | --- | --- | --- | | tar | T | An object that will receive the new properties. | | src | S | An object containing additional properties to merge in. | | cb | IMergeCb | Customizer the function to customize assigned values, the prop will be skip when return value is undefined, | | deep | boolean | If true, the merge becomes recursive (aka. deep copy). passing false for this argument is not supported. |
Example
function customizer(srcValue, tarValue) {
if (Array.isArray(tarValue)) {
return tarValue.concat(srcValue);
}
}
var object = { 'a': [1], 'b': [2] };
var other = { 'a': [3], 'b': [4] };
mergeWith(object, other, customizer);
// => { 'a': [1, 3], 'b': [2, 4] }
utils/noop
This method returns undefined
.
Example
btn.onclick = fn || noop;
// => undefined
utils/random ⇒ number
Produces a random number between the inclusive lower
and upper
bounds.
Returns: number - Returns the random floating-point number.
| Param | Type | Description | | --- | --- | --- | | lower | number | The lower bound. | | upper | number | The upper bound. |
Example
random(1, 5);
// => a floating-point number between 1 and 5
utils/repeat ⇒ string
Repeats the given string n
times.
Returns: string - Returns the repeated string.
| Param | Type | Description | | --- | --- | --- | | str | string | The string to repeat. | | n | number | The number of times to repeat the string. |
Example
repeat('*', 3);
// => '***'
repeat('abc', 2);
// => 'abcabc'
repeat('abc', 0);
// => ''
utils/throttle ⇒ function
throttle
| Param | Type | | --- | --- | | cb | function | | interval | number |
Example
const t = throttle(console.log, 1000);
t(1);t(1);...a second...t(1);
// => 1
utils/toFixed ⇒ number
Returns a number in fixed-point notation.
Returns: number - Returns a number in fixed-point notation.
| Param | Type | Default | Description | | --- | --- | --- | --- | | num | number | | The number to fixed. | | [fixed] | number | 0 | Number of digits after the decimal point. |
Example
toFixed(3.14);
// => 3
toFixed(3.1415926, 2);
// => 3.14
toFixed(3.1415926, 4);
// => 3.1415
CycleLinkList
Kind: global class
- CycleLinkList
- .addLast(value)
- .remove(value) ⇒ number
- .insertAt(value, index) ⇒ boolean
- .removeAt(index) ⇒ T | null
cycleLinkList.addLast(value)
addLast
Kind: instance method of CycleLinkList
| Param | Type | | --- | --- | | value | T |
cycleLinkList.remove(value) ⇒ number
remove
Kind: instance method of CycleLinkList
| Param | Type | | --- | --- | | value | T |
cycleLinkList.insertAt(value, index) ⇒ boolean
insertAt
Kind: instance method of CycleLinkList
| Param | Type | | --- | --- | | value | T | | index | number |
cycleLinkList.removeAt(index) ⇒ T | null
removeAt
Kind: instance method of CycleLinkList
| Param | Type | | --- | --- | | index | number |
Dictionary
Kind: global class
- Dictionary
- new Dictionary([obj])
- .size ⇒ number
- .fromObject(obj) ⇒ this
- .toObject() ⇒ IKeyValue.<V>
- .isEmpty() ⇒ boolean
- .has(key) ⇒ boolean
- .get(key) ⇒ V | undefined
- .set(key, value) ⇒ this
- .delete(key) ⇒ boolean
- .keys() ⇒ Array.<string>
- .values([values]) ⇒ Array.<V>
- .toString() ⇒ string
- .clear()
new Dictionary([obj])
| Param | Type | Default | | --- | --- | --- | | [obj] | IKeyValue.<V> | {} |
dictionary.size ⇒ number
size
Kind: instance property of Dictionary
dictionary.fromObject(obj) ⇒ this
Object transform to Dictionary
Kind: instance method of Dictionary
| Param | Type | | --- | --- | | obj | IKeyValue.<V> |
dictionary.toObject() ⇒ IKeyValue.<V>
Dictionary transform to object Note: Return value is Dictionary inner object
Kind: instance method of Dictionary
dictionary.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of Dictionary
dictionary.has(key) ⇒ boolean
has
Kind: instance method of Dictionary
| Param | Type | | --- | --- | | key | K |
dictionary.get(key) ⇒ V | undefined
get
Kind: instance method of Dictionary
| Param | Type | | --- | --- | | key | K |
dictionary.set(key, value) ⇒ this
set
Kind: instance method of Dictionary
| Param | Type | | --- | --- | | key | K | | value | V |
dictionary.delete(key) ⇒ boolean
delete
Kind: instance method of Dictionary
| Param | Type | | --- | --- | | key | K |
dictionary.keys() ⇒ Array.<string>
keys
Kind: instance method of Dictionary
dictionary.values([values]) ⇒ Array.<V>
values
Kind: instance method of Dictionary
| Param | Type | Default | | --- | --- | --- | | [values] | Array.<V> | [] |
dictionary.toString() ⇒ string
toString
Kind: instance method of Dictionary
dictionary.clear()
Clear the dictionary
Kind: instance method of Dictionary
DoubleLinkNode
DoubleLinkNode
Kind: global class
DoubleLinkList
Kind: global class
- DoubleLinkList
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .head() ⇒ DoubleLinkNode.<T> | null
- .tail() ⇒ DoubleLinkNode.<T> | null
- .clear()
- .addFirst(value)
- .addLast(value)
- .insertAfter(value, curValue) ⇒ number
- .insertBefore(value, curValue) ⇒ number
- .remove(value) ⇒ number
- .insertAt(value, index) ⇒ boolean
- .removeAt(index) ⇒ T | null
- .indexOf(value) ⇒ number
- .includes(value) ⇒ boolean
- .get(index) ⇒ T | null
doubleLinkList.size ⇒ number
size
Kind: instance property of DoubleLinkList
doubleLinkList.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of DoubleLinkList
doubleLinkList.head() ⇒ DoubleLinkNode.<T> | null
head
Kind: instance method of DoubleLinkList
doubleLinkList.tail() ⇒ DoubleLinkNode.<T> | null
tail
Kind: instance method of DoubleLinkList
doubleLinkList.clear()
clear
Kind: instance method of DoubleLinkList
doubleLinkList.addFirst(value)
addFirst
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T |
doubleLinkList.addLast(value)
addLast
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T |
doubleLinkList.insertAfter(value, curValue) ⇒ number
insertAfter
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T | | curValue | T |
doubleLinkList.insertBefore(value, curValue) ⇒ number
insertBefore
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T | | curValue | T |
doubleLinkList.remove(value) ⇒ number
remove
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T |
doubleLinkList.insertAt(value, index) ⇒ boolean
insertAt
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T | | index | number |
doubleLinkList.removeAt(index) ⇒ T | null
removeAt
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | index | number |
doubleLinkList.indexOf(value) ⇒ number
indexOf
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T |
doubleLinkList.includes(value) ⇒ boolean
includes
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | value | T |
doubleLinkList.get(index) ⇒ T | null
get
Kind: instance method of DoubleLinkList
| Param | Type | | --- | --- | | index | number |
LinkNode
LinkNode
Kind: global class
LinkList
Kind: global class
- LinkList
- .size ⇒ number
- .isEmpty() ⇒ boolean
- .head() ⇒ LinkNode.<T> | null
- .clear()
- .addFirst(value)
- .addLast(value)
- .insert(value, preValue) ⇒ number
- .remove(value) ⇒ number
- .insertAt(value, index) ⇒ boolean
- .removeAt(index) ⇒ T | null
- .indexOf(value) ⇒ number
- .includes(value) ⇒ boolean
- .get(index) ⇒ T | null
linkList.size ⇒ number
size
Kind: instance property of LinkList
linkList.isEmpty() ⇒ boolean
isEmpty
Kind: instance method of LinkList
linkList.head() ⇒ LinkNode.<T> | null
head
Kind: instance method of [L