wavefuel-utils
v1.1.15
Published
Utility Functions for all Development Purpose
Downloads
25
Maintainers
Readme
LinkedList
Represents a singly linked list.
Kind: global class
- LinkedList
- .size ⇒ number
- .append(value)
- .prepend(value)
- .insertAfter(value, target) ⇒ boolean
- .remove(value) ⇒ boolean
- .find(value) ⇒ T | null
- .isEmpty() ⇒ boolean
- .toArray() ⇒ Array.<T>
- .clear()
linkedList.size ⇒ number
Returns the number of elements in the linked list.
Kind: instance property of LinkedList
Returns: number - The number of elements in the linked list.
Example
const list = new LinkedList();
list.append(1);
list.append(2);
const size = list.size;
console.log(size); // Output: 2
linkedList.append(value)
Appends a new element to the end of the linked list.
Kind: instance method of LinkedList
| Param | Type | Description | | --- | --- | --- | | value | T | The value to append. |
Example
const list = new LinkedList();
list.append(1);
list.append(2);
console.log(list.toArray()); // Output: [1, 2]
linkedList.prepend(value)
Prepends a new element to the beginning of the linked list.
Kind: instance method of LinkedList
| Param | Type | Description | | --- | --- | --- | | value | T | The value to prepend. |
Example
const list = new LinkedList();
list.prepend(1);
list.prepend(2);
console.log(list.toArray()); // Output: [2, 1]
linkedList.insertAfter(value, target) ⇒ boolean
Inserts a new element after a given element in the linked list.
Kind: instance method of LinkedList
Returns: boolean - true
if the insertion is successful, false
if the target element is not found.
| Param | Type | Description | | --- | --- | --- | | value | T | The value to insert. | | target | T | The element after which the new value should be inserted. |
Example
const list = new LinkedList();
list.append(1);
list.append(2);
list.insertAfter(3, 1);
console.log(list.toArray()); // Output: [1, 3, 2]
linkedList.remove(value) ⇒ boolean
Removes the first occurrence of a specified element from the linked list.
Kind: instance method of LinkedList
Returns: boolean - true
if the removal is successful, false
if the element is not found.
| Param | Type | Description | | --- | --- | --- | | value | T | The value to remove. |
Example
const list = new LinkedList();
list.append(1);
list.append(2);
list.remove(1);
console.log(list.toArray()); // Output: [2]
linkedList.find(value) ⇒ T | null
Finds the first occurrence of a specified element in the linked list.
Kind: instance method of LinkedList
Returns: T | null - The found element, or null
if not found.
| Param | Type | Description | | --- | --- | --- | | value | T | The value to find. |
Example
const list = new LinkedList();
list.append(1);
list.append(2);
const foundValue = list.find(2);
console.log(foundValue); // Output: 2
linkedList.isEmpty() ⇒ boolean
Checks if the linked list is empty.
Kind: instance method of LinkedList
Returns: boolean - true
if the linked list is empty, false
otherwise.
Example
const list = new LinkedList();
console.log(list.isEmpty()); // Output: true
list.append(1);
console.log(list.isEmpty()); // Output: false
linkedList.toArray() ⇒ Array.<T>
Converts the linked list to an array.
Kind: instance method of LinkedList
Returns: Array.<T> - An array containing all elements of the linked list in order.
Example
const list = new LinkedList();
list.append(1);
list.append(2);
const array = list.toArray();
console.log(array); // Output: [1, 2]
linkedList.clear()
Clears all elements from the linked list.
Kind: instance method of LinkedList
Example
const list = new LinkedList();
list.append(1);
list.append(2);
list.clear();
console.log(list.toArray()); // Output: []
console.log(list.size); // Output: 0
Stack
Represents a stack data structure.
Kind: global class
- Stack
- .push(element)
- .pop() ⇒ T | undefined
- .peek() ⇒ T | undefined
- .isEmpty() ⇒ boolean
- .size() ⇒ number
- .clear()
- .toArray() ⇒ Array.<T>
stack.push(element)
Pushes an element onto the top of the stack.
Kind: instance method of Stack
| Param | Type | Description | | --- | --- | --- | | element | T | The element to push onto the stack. |
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
console.log(stack.toArray()); // Output: [1, 2]
stack.pop() ⇒ T | undefined
Removes and returns the top element from the stack.
Kind: instance method of Stack
Returns: T | undefined - The top element of the stack, or undefined
if the stack is empty.
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
const poppedElement = stack.pop();
console.log(poppedElement); // Output: 2
console.log(stack.toArray()); // Output: [1]
stack.peek() ⇒ T | undefined
Returns the top element of the stack without removing it.
Kind: instance method of Stack
Returns: T | undefined - The top element of the stack, or undefined
if the stack is empty.
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
const topElement = stack.peek();
console.log(topElement); // Output: 2
console.log(stack.toArray()); // Output: [1, 2]
stack.isEmpty() ⇒ boolean
Checks if the stack is empty.
Kind: instance method of Stack
Returns: boolean - true
if the stack is empty, false
otherwise.
Example
const stack = new Stack();
console.log(stack.isEmpty()); // Output: true
stack.push(1);
console.log(stack.isEmpty()); // Output: false
stack.size() ⇒ number
Returns the number of elements in the stack.
Kind: instance method of Stack
Returns: number - The number of elements in the stack.
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
const size = stack.size();
console.log(size); // Output: 2
stack.clear()
Clears all elements from the stack.
Kind: instance method of Stack
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
stack.clear();
console.log(stack.toArray()); // Output: []
console.log(stack.size()); // Output: 0
stack.toArray() ⇒ Array.<T>
Converts the stack to an array.
Kind: instance method of Stack
Returns: Array.<T> - An array containing all elements of the stack in order from top to bottom.
Example
const stack = new Stack();
stack.push(1);
stack.push(2);
const array = stack.toArray();
console.log(array); // Output: [2, 1]
Queue
Represents a queue data structure.
Kind: global class
- Queue
- .enqueue(element)
- .dequeue() ⇒ T | undefined
- .peek() ⇒ T | undefined
- .isEmpty() ⇒ boolean
- .size() ⇒ number
- .clear()
- .toArray() ⇒ Array.<T>
queue.enqueue(element)
Adds an element to the back of the queue.
Kind: instance method of Queue
| Param | Type | Description | | --- | --- | --- | | element | T | The element to enqueue. |
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.toArray()); // Output: [1, 2]
queue.dequeue() ⇒ T | undefined
Removes and returns the front element from the queue.
Kind: instance method of Queue
Returns: T | undefined - The front element of the queue, or undefined
if the queue is empty.
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
const dequeuedElement = queue.dequeue();
console.log(dequeuedElement); // Output: 1
console.log(queue.toArray()); // Output: [2]
queue.peek() ⇒ T | undefined
Returns the front element of the queue without removing it.
Kind: instance method of Queue
Returns: T | undefined - The front element of the queue, or undefined
if the queue is empty.
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
const frontElement = queue.peek();
console.log(frontElement); // Output: 1
console.log(queue.toArray()); // Output: [1, 2]
queue.isEmpty() ⇒ boolean
Checks if the queue is empty.
Kind: instance method of Queue
Returns: boolean - true
if the queue is empty, false
otherwise.
Example
const queue = new Queue();
console.log(queue.isEmpty()); // Output: true
queue.enqueue(1);
console.log(queue.isEmpty()); // Output: false
queue.size() ⇒ number
Returns the number of elements in the queue.
Kind: instance method of Queue
Returns: number - The number of elements in the queue.
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
const size = queue.size();
console.log(size); // Output: 2
queue.clear()
Clears all elements from the queue.
Kind: instance method of Queue
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
queue.clear();
console.log(queue.toArray()); // Output: []
console.log(queue.size()); // Output: 0
queue.toArray() ⇒ Array.<T>
Converts the queue to an array.
Kind: instance method of Queue
Returns: Array.<T> - An array containing all elements of the queue in order from front to back.
Example
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
const array = queue.toArray();
console.log(array); // Output: [1, 2]
TreeNode
Represents a node in a binary search tree.
Kind: global class
BinarySearchTree
Represents a binary search tree.
Kind: global class
- BinarySearchTree
- .insert(value)
- .delete(value)
- .find(value) ⇒ boolean
- .getMin() ⇒ T | null
- .getMax() ⇒ T | null
- .getHeight() ⇒ number
- .traverseInOrder() ⇒ Array.<T>
- .traversePreOrder() ⇒ Array.<T>
- .traversePostOrder() ⇒ Array.<T>
binarySearchTree.insert(value)
Inserts a new element into the binary search tree.
Kind: instance method of BinarySearchTree
| Param | Type | Description | | --- | --- | --- | | value | T | The value to insert. |
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.find(3)); // Output: true
console.log(bst.find(6)); // Output: false
binarySearchTree.delete(value)
Deletes an element from the binary search tree.
Kind: instance method of BinarySearchTree
| Param | Type | Description | | --- | --- | --- | | value | T | The value to delete. |
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
bst.delete(3);
console.log(bst.find(3)); // Output: false
binarySearchTree.find(value) ⇒ boolean
Finds an element in the binary search tree.
Kind: instance method of BinarySearchTree
Returns: boolean - true
if the element is found, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | value | T | The value to find. |
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.find(3)); // Output: true
console.log(bst.find(6)); // Output: false
binarySearchTree.getMin() ⇒ T | null
Gets the minimum element in the binary search tree.
Kind: instance method of BinarySearchTree
Returns: T | null - The minimum element, or null
if the tree is empty.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.getMin()); // Output: 3
binarySearchTree.getMax() ⇒ T | null
Gets the maximum element in the binary search tree.
Kind: instance method of BinarySearchTree
Returns: T | null - The maximum element, or null
if the tree is empty.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.getMax()); // Output: 8
binarySearchTree.getHeight() ⇒ number
Gets the height of the binary search tree.
Kind: instance method of BinarySearchTree
Returns: number - The height of the tree.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.getHeight()); // Output: 2
binarySearchTree.traverseInOrder() ⇒ Array.<T>
Traverses the binary search tree in in-order and returns the elements in an array.
Kind: instance method of BinarySearchTree
Returns: Array.<T> - An array containing elements of the tree in in-order.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.traverseInOrder()); // Output: [3, 5, 8]
binarySearchTree.traversePreOrder() ⇒ Array.<T>
Traverses the binary search tree in pre-order and returns the elements in an array.
Kind: instance method of BinarySearchTree
Returns: Array.<T> - An array containing elements of the tree in pre-order.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.traversePreOrder()); // Output: [5, 3, 8]
binarySearchTree.traversePostOrder() ⇒ Array.<T>
Traverses the binary search tree in post-order and returns the elements in an array.
Kind: instance method of BinarySearchTree
Returns: Array.<T> - An array containing elements of the tree in post-order.
Example
const bst = new BinarySearchTree();
bst.insert(5);
bst.insert(3);
bst.insert(8);
console.log(bst.traversePostOrder()); // Output: [3, 8, 5]
Vertex
Represents a vertex in an undirected graph.
Kind: global class
UndirectedGraph
Represents an undirected graph.
Kind: global class
undirectedGraph.addVertex(value)
Adds a new vertex to the graph.
Kind: instance method of UndirectedGraph
| Param | Type | Description | | --- | --- | --- | | value | T | The value to associate with the new vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
undirectedGraph.removeVertex(value)
Removes a vertex and all its edges from the graph.
Kind: instance method of UndirectedGraph
| Param | Type | Description | | --- | --- | --- | | value | T | The value associated with the vertex to remove. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
graph.removeVertex('A');
undirectedGraph.addEdge(value1, value2)
Adds an edge between two vertices in the graph.
Kind: instance method of UndirectedGraph
| Param | Type | Description | | --- | --- | --- | | value1 | T | The value associated with the first vertex. | | value2 | T | The value associated with the second vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
undirectedGraph.removeEdge(value1, value2)
Removes an edge between two vertices in the graph.
Kind: instance method of UndirectedGraph
| Param | Type | Description | | --- | --- | --- | | value1 | T | The value associated with the first vertex. | | value2 | T | The value associated with the second vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
graph.removeEdge('A', 'B');
undirectedGraph.hasVertex(value) ⇒ boolean
Checks if a vertex with a given value exists in the graph.
Kind: instance method of UndirectedGraph
Returns: boolean - true
if the vertex exists, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | value | T | The value associated with the vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
console.log(graph.hasVertex('A')); // Output: true
console.log(graph.hasVertex('B')); // Output: false
undirectedGraph.hasEdge(value1, value2) ⇒ boolean
Checks if an edge exists between two vertices in the graph.
Kind: instance method of UndirectedGraph
Returns: boolean - true
if the edge exists, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | value1 | T | The value associated with the first vertex. | | value2 | T | The value associated with the second vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
graph.addEdge('A', 'B');
console.log(graph.hasEdge('A', 'B')); // Output: true
console.log(graph.hasEdge('A', 'C')); // Output: false
undirectedGraph.getNeighbors(value) ⇒ Array.<T>
Gets an array of neighbors for a given vertex.
Kind: instance method of UndirectedGraph
Returns: Array.<T> - An array of neighbor values.
| Param | Type | Description | | --- | --- | --- | | value | T | The value associated with the vertex. |
Example
const graph = new UndirectedGraph();
graph.addVertex('A');
graph.addVertex('B');
graph.addVertex('C');
graph.addEdge('A', 'B');
graph.addEdge('A', 'C');
console.log(graph.getNeighbors('A')); // Output: ['B', 'C']
KeyValuePair
Represents a key-value pair in a hash table.
Kind: global class
HashTable
Represents a hash table.
Kind: global class
- HashTable
- .put(key, value)
- .get(key) ⇒ V | undefined
- .remove(key)
- .containsKey(key) ⇒ boolean
- .keys() ⇒ Array.<K>
- .values() ⇒ Array.<V>
hashTable.put(key, value)
Inserts a key-value pair into the hash table.
Kind: instance method of HashTable
| Param | Type | Description | | --- | --- | --- | | key | K | The key to insert. | | value | V | The value to insert. |
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
hashTable.put('banana', 8);
hashTable.get(key) ⇒ V | undefined
Retrieves the value associated with a key from the hash table.
Kind: instance method of HashTable
Returns: V | undefined - The value associated with the key, or undefined
if not found.
| Param | Type | Description | | --- | --- | --- | | key | K | The key to search for. |
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
console.log(hashTable.get('apple')); // Output: 5
console.log(hashTable.get('banana')); // Output: undefined
hashTable.remove(key)
Removes a key-value pair associated with a key from the hash table.
Kind: instance method of HashTable
| Param | Type | Description | | --- | --- | --- | | key | K | The key to remove. |
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
hashTable.remove('apple');
console.log(hashTable.get('apple')); // Output: undefined
hashTable.containsKey(key) ⇒ boolean
Checks if the hash table contains a key.
Kind: instance method of HashTable
Returns: boolean - true
if the key exists, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | key | K | The key to check. |
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
console.log(hashTable.containsKey('apple')); // Output: true
console.log(hashTable.containsKey('banana')); // Output: false
hashTable.keys() ⇒ Array.<K>
Retrieves an array of keys in the hash table.
Kind: instance method of HashTable
Returns: Array.<K> - An array of keys in the hash table.
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
hashTable.put('banana', 8);
console.log(hashTable.keys()); // Output: ['apple', 'banana']
hashTable.values() ⇒ Array.<V>
Retrieves an array of values in the hash table.
Kind: instance method of HashTable
Returns: Array.<V> - An array of values in the hash table.
Example
const hashTable = new HashTable<string, number>();
hashTable.put('apple', 5);
hashTable.put('banana', 8);
console.log(hashTable.values()); // Output: [5, 8]
BTreeNode
Represents a node in a B-Tree.
Kind: global class
TrieNode
Represents a node in a Trie.
Kind: global class
Trie
Represents a Trie (prefix tree).
Kind: global class
- Trie
- .insert(word)
- .search(word) ⇒ boolean
- .startsWith(prefix) ⇒ boolean
- .delete(word)
- .autocomplete(prefix) ⇒ Array.<string>
trie.insert(word)
Inserts a word into the Trie.
Kind: instance method of Trie
| Param | Type | Description | | --- | --- | --- | | word | string | The word to insert. |
Example
const trie = new Trie();
trie.insert("apple");
trie.insert("app");
trie.search(word) ⇒ boolean
Searches for a word in the Trie.
Kind: instance method of Trie
Returns: boolean - true
if the word is found, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | word | string | The word to search for. |
Example
const trie = new Trie();
trie.insert("apple");
console.log(trie.search("apple")); // Output: true
console.log(trie.search("app")); // Output: false
trie.startsWith(prefix) ⇒ boolean
Determines if there are any words in the Trie that start with a given prefix.
Kind: instance method of Trie
Returns: boolean - true
if there are words with the given prefix, false
otherwise.
| Param | Type | Description | | --- | --- | --- | | prefix | string | The prefix to check. |
Example
const trie = new Trie();
trie.insert("apple");
console.log(trie.startsWith("app")); // Output: true
console.log(trie.startsWith("ban")); // Output: false
trie.delete(word)
Deletes a word from the Trie.
Kind: instance method of Trie
| Param | Type | Description | | --- | --- | --- | | word | string | The word to delete. |
Example
const trie = new Trie();
trie.insert("apple");
trie.delete("apple");
console.log(trie.search("apple")); // Output: false
trie.autocomplete(prefix) ⇒ Array.<string>
Returns a list of words in the Trie that start with a given prefix.
Kind: instance method of Trie
Returns: Array.<string> - An array of autocompleted words.
| Param | Type | Description | | --- | --- | --- | | prefix | string | The prefix to autocomplete. |
Example
const trie = new Trie();
trie.insert("apple");
trie.insert("appetizer");
console.log(trie.autocomplete("app")); // Output: ["apple", "appetizer"]
console.log(trie.autocomplete("ban")); // Output: []
SparseMatrix
Represents a sparse matrix.
Kind: global class
new SparseMatrix(rows, cols)
Constructs a sparse matrix with the specified number of rows and columns.
| Param | Type | Description | | --- | --- | --- | | rows | number | The number of rows in the matrix. | | cols | number | The number of columns in the matrix. |
Example
const matrix = new SparseMatrix(3, 4);
sparseMatrix.get(row, col) ⇒ number
Gets the value at the specified row and column in the matrix.
Kind: instance method of SparseMatrix
Returns: number - The value at the specified position, or 0 if the position is empty.
| Param | Type | Description | | --- | --- | --- | | row | number | The row index (0-based). | | col | number | The column index (0-based). |
Example
const matrix = new SparseMatrix(3, 4);
matrix.set(0, 1, 5);
console.log(matrix.get(0, 1)); // Output: 5
console.log(matrix.get(1, 2)); // Output: 0
sparseMatrix.set(row, col, value)
Sets the value at the specified row and column in the matrix.
Kind: instance method of SparseMatrix
| Param | Type | Description | | --- | --- | --- | | row | number | The row index (0-based). | | col | number | The column index (0-based). | | value | number | The value to set. |
Example
const matrix = new SparseMatrix(3, 4);
matrix.set(0, 1, 5);
console.log(matrix.get(0, 1)); // Output: 5
sparseMatrix.transpose() ⇒ SparseMatrix
Transposes the matrix, swapping rows and columns.
Kind: instance method of SparseMatrix
Returns: SparseMatrix - The transposed matrix.
Example
const matrix = new SparseMatrix(3, 4);
matrix.set(0, 1, 5);
const transposed = matrix.transpose();
console.log(transposed.get(1, 0)); // Output: 5
sparseMatrix.add(otherMatrix) ⇒ SparseMatrix
Adds two matrices together and returns a new matrix with the result.
Kind: instance method of SparseMatrix
Returns: SparseMatrix - The resulting matrix after addition.
| Param | Type | Description | | --- | --- | --- | | otherMatrix | SparseMatrix | The matrix to add. |
Example
const matrixA = new SparseMatrix(2, 3);
matrixA.set(0, 1, 5);
const matrixB = new SparseMatrix(2, 3);
matrixB.set(0, 1, 3);
const result = matrixA.add(matrixB);
console.log(result.get(0, 1)); // Output: 8
sparseMatrix.multiply(otherMatrix) ⇒ SparseMatrix
Multiplies two matrices together and returns a new matrix with the result.
Kind: instance method of SparseMatrix
Returns: SparseMatrix - The resulting matrix after multiplication.
| Param | Type | Description | | --- | --- | --- | | otherMatrix | SparseMatrix | The matrix to multiply by. |
Example
const matrixA = new SparseMatrix(2, 3);
matrixA.set(0, 1, 5);
const matrixB = new SparseMatrix(3, 2);
matrixB.set(1, 0, 3);
const result = matrixA.multiply(matrixB);
console.log(result.get(0, 0)); // Output: 15
sparseMatrix.compress()
Compresses the matrix by removing zero values.
Kind: instance method of SparseMatrix
Example
const matrix = new SparseMatrix(3, 4);
matrix.set(0, 1, 5);
matrix.set(1, 2, 0);
matrix.compress();
console.log(matrix.get(0, 1)); // Output: 5
console.log(matrix.get(1, 2)); // Output: 0
BitSet
Represents a BitSet, a data structure for efficient manipulation of bits.
Kind: global class
- BitSet
- new BitSet(size)
- .set(index)
- .clear(index)
- .toggle(index)
- .test(index) ⇒ boolean
- .countSetBits() ⇒ number
- .findNextSetBit(startIndex) ⇒ number
new BitSet(size)
Constructs a BitSet with the specified number of bits.
| Param | Type | Description | | --- | --- | --- | | size | number | The number of bits in the BitSet. |
Example
const bitSet = new BitSet(10);
bitSet.set(index)
Sets the bit at the specified index to 1.
Kind: instance method of BitSet
| Param | Type | Description | | --- | --- | --- | | index | number | The index of the bit to set. |
Example
const bitSet = new BitSet(10);
bitSet.set(3);
console.log(bitSet.test(3)); // Output: true
bitSet.clear(index)
Clears the bit at the specified index (sets it to 0).
Kind: instance method of BitSet
| Param | Type | Description | | --- | --- | --- | | index | number | The index of the bit to clear. |
Example
const bitSet = new BitSet(10);
bitSet.set(3);
bitSet.clear(3);
console.log(bitSet.test(3)); // Output: false
bitSet.toggle(index)
Toggles the bit at the specified index (flips its value).
Kind: instance method of BitSet
| Param | Type | Description | | --- | --- | --- | | index | number | The index of the bit to toggle. |
Example
const bitSet = new BitSet(10);
bitSet.toggle(3);
console.log(bitSet.test(3)); // Output: true
bitSet.toggle(3);
console.log(bitSet.test(3)); // Output: false
bitSet.test(index) ⇒ boolean
Tests the value of the bit at the specified index.
Kind: instance method of BitSet
Returns: boolean - true
if the bit is set (1), false
if it is clear (0).
| Param | Type | Description | | --- | --- | --- | | index | number | The index of the bit to test. |
Example
const bitSet = new BitSet(10);
bitSet.set(3);
console.log(bitSet.test(3)); // Output: true
bitSet.countSetBits() ⇒ number
Counts the number of set (1) bits in the BitSet.
Kind: instance method of BitSet
Returns: number - The count of set bits.
Example
const bitSet = new BitSet(10);
bitSet.set(3);
bitSet.set(5);
console.log(bitSet.countSetBits()); // Output: 2
bitSet.findNextSetBit(startIndex) ⇒ number
Finds the index of the next set (1) bit starting from the specified index.
Kind: instance method of BitSet
Returns: number - The index of the next set bit, or -1 if not found.
| Param | Type | Description | | --- | --- | --- | | startIndex | number | The starting index (inclusive). |
Example
const bitSet = new BitSet(10);
bitSet.set(3);
bitSet.set(5);
console.log(bitSet.findNextSetBit(0)); // Output: 3
console.log(bitSet.findNextSetBit(4)); // Output: 5
console.log(bitSet.findNextSetBit(6)); // Output: -1
CircularBuffer
Represents a Circular Buffer, a data structure for managing a fixed-size buffer with efficient enqueue and dequeue operations.
Kind: global class
- CircularBuffer
- new CircularBuffer(size)
- .enqueue(element)
- .dequeue() ⇒ T
- .isFull() ⇒ boolean
- .isEmpty() ⇒ boolean
- .peek() ⇒ T
- .clear()
new CircularBuffer(size)
Constructs a Circular Buffer with the specified size.
| Param | Type | Description | | --- | --- | --- | | size | number | The maximum size of the buffer. |
Example
const circularBuffer = new CircularBuffer<number>(5);
circularBuffer.enqueue(element)
Enqueues an element at the rear of the Circular Buffer.
Kind: instance method of CircularBuffer
| Param | Type | Description | | --- | --- | --- | | element | T | The element to enqueue. |
Example
const circularBuffer = new CircularBuffer<number>(5);
circularBuffer.enqueue(1);
circularBuffer.enqueue(2);
circularBuffer.dequeue() ⇒ T
Dequeues an element from the front of the Circular Buffer.
Kind: instance method of CircularBuffer
Returns: T - The dequeued element.
Example
const circularBuffer = new CircularBuffer<number>(5);
circularBuffer.enqueue(1);
const element = circularBuffer.dequeue();
console.log(element); // Output: 1
circularBuffer.isFull() ⇒ boolean
Checks if the Circular Buffer is full.
Kind: instance method of CircularBuffer
Returns: boolean - true
if the buffer is full, false
otherwise.
Example
const circularBuffer = new CircularBuffer<number>(2);
circularBuffer.enqueue(1);
circularBuffer.enqueue(2);
console.log(circularBuffer.isFull()); // Output: true
circularBuffer.isEmpty() ⇒ boolean
Checks if the Circular Buffer is empty.
Kind: instance method of CircularBuffer
Returns: boolean - true
if the buffer is empty, false
otherwise.
Example
const circularBuffer = new CircularBuffer<number>(2);
console.log(circularBuffer.isEmpty()); // Output: true
circularBuffer.peek() ⇒ T
Peeks at the element at the front of the Circular Buffer without dequeuing it.
Kind: instance method of CircularBuffer
Returns: T - The element at the front.
Example
const circularBuffer = new CircularBuffer<number>(3);
circularBuffer.enqueue(1);
circularBuffer.enqueue(2);
const element = circularBuffer.peek();
console.log(element); // Output: 1
circularBuffer.clear()
Clears all elements from the Circular Buffer.
Kind: instance method of CircularBuffer
Example
const circularBuffer = new CircularBuffer<number>(3);
circularBuffer.enqueue(1);
circularBuffer.enqueue(2);
circularBuffer.clear();
console.log(circularBuffer.isEmpty()); // Output: true
SplayNode
Represents a node in a self-adjusting list (Splay Tree).
Kind: global class
SelfAdjustingList
Represents a self-adjusting list (Splay Tree).
Kind: global class
selfAdjustingList.splay(element)
Performs a splay operation on the tree to bring the specified element to the root.
Kind: instance method of SelfAdjustingList
| Param | Type | Description | | --- | --- | --- | | element | T | The element to splay. |
Example
const splayTree = new SelfAdjustingList<number>();
splayTree.insert(1);
splayTree.splay(1);
selfAdjustingList.insert(element)
Inserts an element into the self-adjusting list.
Kind: instance method of SelfAdjustingList
| Param | Type | Description | | --- | --- | --- | | element | T | The element to insert. |
Example
const splayTree = new SelfAdjustingList<number>();
splayTree.insert(1);
splayTree.insert(2);
selfAdjustingList.moveToFront(element)
Moves the specified element to the front of the self-adjusting list.
Kind: instance method of SelfAdjustingList
| Param | Type | Description | | --- | --- | --- | | element | T | The element to move to the front. |
Example
const splayTree = new SelfAdjustingList<number>();
splayTree.insert(1);
splayTree.insert(2);
splayTree.moveToFront(1);
selfAdjustingList.insertAfter(target, element)
Inserts an element after a specified element in the self-adjusting list.
Kind: instance method of SelfAdjustingList
| Param | Type | Description | | --- | --- | --- | | target | T | The element after which to insert. | | element | T | The element to insert. |
Example
const splayTree = new SelfAdjustingList<number>();
splayTree.insert(1);
splayTree.insert(3);
splayTree.insertAfter(1, 2);
__awaiter
This file contains all Wavefuel's async utility functions
Kind: global variable
Author: Mr.Blue
__createBinding
This file contains all Wavefuel's data utility functions
Kind: global variable
Author: Mr.White
__createBinding
This file contains all Wavefuel's file utility functions
Kind: global variable
Author: Mr.Blue
__createBinding
This file contains all Wavefuel's data utility functions
Kind: global variable
Author: Mr.White
__createBinding
This file contains all Wavefuel's data utility functions
Kind: global variable
Author: Mr.White
__createBinding
This file contains all Wavefuel's data utility functions
Kind: global variable
Author: Mr.White
__createBinding
This file contains all Wavefuel's test utility functions
Kind: global variable
Author: Mr.Blue
__createBinding
This file contains all Wavefuel's data utility functions
Kind: global variable
Author: Mr.White MrBlue
cache
In-memory cache for storing cached API responses. You may need to adjust the cache implementation based on your needs.
Kind: global constant
sendGETRequest(url) ⇒ Promise.<T>
Sends a GET request to the specified URL and returns the response data.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the GET request to. |
sendPOSTRequest(url, data) ⇒ Promise.<T>
Sends a POST request to the specified URL with the provided data and returns the response data.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the POST request to. | | data | Record.<string, any> | The data to send in the request body. |
sendPUTRequest(url, data) ⇒ Promise.<T>
Sends a PUT request to the specified URL with the provided data and returns the response data.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the PUT request to. | | data | Record.<string, any> | The data to send in the request body. |
sendDELETERequest(url, data) ⇒ Promise.<T>
Sends a PATCH request to the specified URL with the provided data and returns the response data.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the PATCH request to. | | data | Record.<string, any> | The data to send in the request body. |
sendPATCHRequest(url) ⇒ Promise.<T>
Sends a DELETE request to the specified URL and returns the response data.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the DELETE request to. |
sendHEADRequest(url) ⇒ Promise.<Headers>
Sends a HEAD request to the specified URL and returns the response headers.
Kind: global function
Returns: Promise.<Headers> - A Promise that resolves with the response headers as a Headers object.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the HEAD request to. |
sendCustomRequest(url, options) ⇒ Promise.<T>
Sends a custom HTTP request to the specified URL with the given options and returns the response data or headers.
Kind: global function
Returns: Promise.<T> - A Promise that resolves with the response data of type T or Headers if no body is expected.
Throws:
- Error If an error occurs during the request.
| Param | Type | Description | | --- | --- | --- | | url | string | The URL to send the custom request to. | | options | RequestInit | The options for the custom request, including method, headers, body, etc. |
Example
Sending a custom POST request with JSON body
const apiUrl = 'https://api.example.com/custom';
const customOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ key: 'value' }),
};
sendCustomRequest<{ message: string }>(apiUrl, customOptions)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
serializeData(data) ⇒ string
Serializes an object into a query string format for use in URL parameters.
Kind: global function
Returns: string - The serialized query string.
| Param | Type | Description | | --- | --- | --- | | data | Record.<string, any> | The object to be serialized into a query string. |
Example
Serialize an object into a query string
const data = { name: 'John', age: 30 };
const queryString = serializeData(data);
console.log(queryString); // Output: "name=John&age=30"
deserializeData(queryString) ⇒ Record.<string, any>
Deserializes a query string into an object.
Kind: global function
Returns: Record.<string, any> - The deserialized object.
| Param | Type | Description | | --- | --- | --- | | queryString | string | The query string to be deserialized. |
Example
Deserialize a query string into an object
const queryString = 'name=John&age=30';
const deserializedData = deserializeData(queryString);
console.log(deserializedData); // Output: { name: 'John', age: '30' }
convertXMLToJSON(xmlString) ⇒ object
Converts an XML string into a JSON object using inbuilt functions.
Kind: global function
Returns: object - The JSON object.
| Param | Type | Description | | --- | --- | --- | | xmlString | string | The XML string to be converted. |
Example
Convert an XML string into a JSON object
const xmlString = '<root><name>John</name><age>30</age></root>';
const jsonObject = convertXMLToJSON(xmlString);
console.log(jsonObject); // Output: { root: { name: 'John', age: '30' } }
convertCSVToJSON(csvString, delimiter) ⇒ Array.<object>
Converts a CSV string into a JSON array.
Kind: global function
Returns: Array.<object> - An array of JSON objects representing the CSV data.
| Param | Type | Description | | --- | --- | --- | | csvString | string | The CSV string to be converted. | | delimiter | string | The delimiter used in the CSV (e.g., ',' or ';'). |
Example
Convert a CSV string into a JSON array
const csvString = 'Name, Age, City\nJohn, 30, New York\nAlice, 25, Los Angeles';
const jsonArray = convertCSVToJSON(csvString, ',');
console.log(jsonArray);
Output: [
{ Name: 'John', Age: '30', City: 'New York' },
{ Name: 'Alice', Age: '25', City: 'Los Angeles' }
]
formatDataForDisplay(data) ⇒ string
Formats data for display by converting it to a human-readable string or HTML.
Kind: global function
Returns: string - The formatted data as a human-readable string or HTML.
| Param | Type | Description | | --- | --- | --- | | data | object | The data object to be formatted. |
Example
Format a data object for display
const data = { name: 'John', age: 30, city: 'New York' };
const formattedData = formatDataForDisplay(data);
console.log(formattedData);
Output: "Name: John\nAge: 30\nCity: New York"
handleResponse(response) ⇒ Promise.<any>
Handles an HTTP response, parsing the data and handling different status codes.
Kind: global function
Returns: Promise.<any> - A Promise that resolves with the parsed response data.
Throws:
- Error If an error occurs during response handling.
| Param | Type | Description | | --- | --- | --- | | response | Response | The HTTP response object. |
Example
Handle an HTTP response and parse the data
const apiUrl = 'https://api.example.com/data';
fetch(apiUrl)
.then(handleResponse)
.then((data) => {
console.log(data); // Parsed response data
})
.catch((error) => {
console.error(error);
});
paginateResults(items, pageNumber, pageSize) ⇒ Array.<any>
Paginates a list of items and returns a specific page of results.
Kind: global function
Returns: Array.<any> - The paginated page of results.
| Param | Type | Description | | --- | --- | --- | | items | Array.<any> | The list of items to paginate. | | pageNumber | number | The page number to retrieve (1-based index). | | pageSize | number | The number of items per page. |
Example
Paginate a list of items
const itemList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const page = paginateResults(itemList, 2, 3);
console.log(page); // Output: [4, 5, 6]
getNextPageLink(baseUrl, currentPage, pageSize, totalItems) ⇒ string | null
Generates a URL or link to access the next page of paginated results.
Kind: global function
Returns: string | null - The URL for the next page or null if there's no next page.
| Param | Type | Description | | --- | --- | --- | | baseUrl | string | The base URL of the resource. | | currentPage | number | The current page number (1-based index). | | pageSize | number | The number of items per page. | | totalItems | number | The total number of items across all pages. |
Example
Generate a link to the next page of results
const baseUrl = 'https://api.example.com/resource?page=';
const currentPage = 2;
const pageSize = 10;
const totalItems = 35;
const nextPageLink = getNextPageLink(baseUrl, currentPage, pageSize, totalItems);
console.log(nextPageLink);
Output: "https://api.example.com/resource?page=3"
getPreviousPageLink(baseUrl, currentPage, pageSize) ⇒ string | null
Generates a URL or link to access the previous page of paginated results.
Kind: global function
Returns: string | null - The URL for the previous page or null if there's no previous page.
| Param | Type | Description | | --- | --- | --- | | baseUrl | string | The base URL of the resource. | | currentPage | number | The current page number (1-based index). | | pageSize | number | The number of items per page. |
Example
Generate a link to the previous page of results
const baseUrl = 'https://api.example.com/resource?page=';
const currentPage = 3;
const pageSize = 10;
const previousPageLink = getPreviousPageLink(baseUrl, currentPage, pageSize);
console.log(previousPageLink);
Output: "https://api.example.com/resource?page=2"
calculateTotalPages(totalItems, pageSize) ⇒ number
Calculates the total number of pages required to paginate a list of items.
Kind: global function
Returns: number - The total number of pages.
| Param | Type | Description | | --- | --- | --- | | totalItems | number | The total number of items to paginate. | | pageSize | number | The number of items per page. |
Example
Calculate the total number of pages for pagination
const totalItems = 35;
const pageSize = 10;
const totalPages = calculateTotalPages(totalItems, pageSize);
console.log(totalPages); // Output: 4
handleAPIErrors(response) ⇒ Promise.<void>
Handles API errors by checking the response and parsing error messages.
Kind: global function
Returns: Promise.<void> - A Promise that resolves if there are no errors, or rejects with an error message.
| Param | Type | Description | | --- | --- | --- | | response | Response | The HTTP response object from the API request. |
Example
Handle API errors when making a fetch request
const apiUrl = 'https://api.example.com/data';
fetch(apiUrl)
.then(handleAPIErrors)
.then((data) => {
console.log(data); // API response data
})
.catch((error) => {
console.error(error); // Handle API error
});
handleRateLimitExceeded(retryAfterSeconds) ⇒ Promise.<void>
Handles rate limit exceeded errors by implementing rate limiting logic.
Kind: global function
Returns: Promise.<void> - A Promise that resolves after waiting for the specified time.
| Param | Type | Description | | --- | --- | --- | | retryAfterSeconds | number | The number of seconds to wait before retrying the request. |
Example
Handle rate limit exceeded error and retry the request
const retryAfterSeconds = 60; // Example: Retry after 1 minute
handleRateLimitExceeded(retryAfterSeconds)
.then(() => {
// Retry the API request here
console.log('Retrying the request after rate limit exceeded error.');
})
.catch((error) => {
console.error(error); // Handle error if waiting fails
});
handleTimeoutError(timeoutMilliseconds) ⇒ Promise.<void>
Handles timeout errors by implementing timeout logic.
Kind: global function
Returns: Promise.<void> - A Promise that resolves after waiting for the specified time.
| Param | Type | Description | | --- | --- | --- | | timeoutMilliseconds | number | The maximum time to wait before triggering the timeout. |
Example
Handle timeout error and retry the operation
const timeoutMilliseconds = 5000; // Example: 5 seconds
handleTimeoutError(timeoutMilliseconds)
.then(() => {
// Handle the timeout error by retrying the operation or taking other actions.
console.log('Operation timed out.');
})
.catch((error) => {
console.error(error); // Handle error if waiting fails
});
generateAuthHeaders(username, password) ⇒ Headers
Generates authentication headers for HTTP Basic Authentication.
Kind: global function
Returns: Headers - Authentication headers.
| Param | Type | Description | | --- | --- | --- | | username | string | The username for authentication. | | password | string | The password for authentication. |
Example
Generate authentication headers for Basic Authentication
const username = 'myUsername';
const password = 'myPassword';
const headers = generateAuthHeaders(username, password);
Use these headers in your API request
fetch('https://api.example.com/resource', { headers })
.then((response) => {
// Handle the API response
})
.catch((error) => {
console.error(error);
});
authorizeRequest(requestConfig, authToken) ⇒ RequestInit
Authorizes an HTTP request by adding authorization headers.
Kind: global function
Returns: RequestInit - The updated request configuration with authorization headers.
| Param | Type | Description | | --- | --- | --- | | requestConfig | RequestInit | The configuration for the HTTP request. | | authToken | string | The authorization token (e.g., bearer token). |
Example
Authorize an API request with a bearer token
const apiUrl = 'https://api.example.com/resource';
const authToken = 'Bearer myAuthToken';
const requestConfig = {
method: 'GET',
};
const authorizedConfig = authorizeRequest(requestConfig, authToken);
fetch(apiUrl, authorizedConfig)
.then((response) => {
// Handle the API response
})
.catch((error) => {
console.error(error);
});
logAPICall(method, url, headers, [requestBody], [responseBody])
Logs information about an API call.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | method | string | The HTTP method of the API call (e.g., 'GET', 'POST'). | | url | string | The URL of the API endpoint. | | headers | Headers | The request headers. | | [requestBody] | string | The request body, if applicable. | | [responseBody] | string | The response body, if applicable. |
Example
Log an API call
const apiUrl = 'https://api.example.com/resource';
const requestHeaders = new Headers({
'Authorization': 'Bearer myAuthToken',
'Content-Type': 'application/json',
});
const requestBody = JSON.stringify({ key: 'value' });
Simulate an API call and log it
const response = await fetch(apiUrl, {
method: 'POST',
headers: requestHeaders,
body: requestBody,
});
const responseBody = await response.text();
logAPICall('POST', apiUrl, requestHeaders, requestBody, responseBody);
monitorAPICall(method, url, apiCallPromise) ⇒ Promise.<Response>
Monitors an API call by tracking start time, end time, and response status.
Kind: global function
Returns: Promise.<Response> - A Promise that resolves with the API response.
| Param | Type | Description | | --- | --- | --- | | method | string | The HTTP method of the API call (e.g., 'GET', 'POST'). | | url | string | The URL of the API endpoint. | | apiCallPromise | Promise.<Response> | The Promise representing the API call. |
Example
Monitor an API call
const apiUrl = 'https://api.example.com/resource';
Create a Promise representing the API call
const apiCallPromise = fetch(apiUrl, {
method: 'GET',
headers: {
'Authorization': 'Bearer myAuthToken',
},
});
Monitor the API call and log the response status
monitorAPICall('GET', apiUrl, apiCallPromise)
.then((response) => {
console.log('API call completed with status:', response.status);
})
.catch((error) => {
console.error('API call failed:', error);
});
cacheResponse(cacheKey, response)
Caches an API response using a cache key and stores it in memory.
Kind: global function
| Param | Type | Description | | --- | --- | --- | | cacheKey | string | The key for caching the API response. | | response | Response | The API response to cache. |
getCachedResponse(cacheKey) ⇒ Response | null
Retrieves a cached API response using a cache key.
Kind: global function
Returns: Response | null - The cached API response, or null if not found.
| Param | Type | Description | | --- | --- | --- | | cacheKey | string | The key for retrieving the cached API response. |
validateRequestParameters(params) ⇒ Object
Validates and sanitizes request parameters before making an API request.
Kind: global function
Returns: Object - The sanitized request parameters.
| Param | Type | Description | | --- | --- | --- | | params | Object | The request parameters object. |
Example
Validate and sanitize request parameters before making an API request
const requestParams = {
query: 'search term',
page: 1,
// Add more parameters as needed
};
const sanitizedParams = validateRequest