1.0.11 • Published 8 days ago

wavefuel-utils v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

LinkedList

Represents a singly linked list.

Kind: global class

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

ParamTypeDescription
valueTThe 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

ParamTypeDescription
valueTThe 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.

ParamTypeDescription
valueTThe value to insert.
targetTThe 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.

ParamTypeDescription
valueTThe 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.

ParamTypeDescription
valueTThe 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)

Pushes an element onto the top of the stack.

Kind: instance method of Stack

ParamTypeDescription
elementTThe 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)

Adds an element to the back of the queue.

Kind: instance method of Queue

ParamTypeDescription
elementTThe 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)

Inserts a new element into the binary search tree.

Kind: instance method of BinarySearchTree

ParamTypeDescription
valueTThe 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

ParamTypeDescription
valueTThe 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.

ParamTypeDescription
valueTThe 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

ParamTypeDescription
valueTThe 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

ParamTypeDescription
valueTThe 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

ParamTypeDescription
value1TThe value associated with the first vertex.
value2TThe 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

ParamTypeDescription
value1TThe value associated with the first vertex.
value2TThe 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.

ParamTypeDescription
valueTThe 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.

ParamTypeDescription
value1TThe value associated with the first vertex.
value2TThe 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.

ParamTypeDescription
valueTThe 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)

Inserts a key-value pair into the hash table.

Kind: instance method of HashTable

ParamTypeDescription
keyKThe key to insert.
valueVThe 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.

ParamTypeDescription
keyKThe 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

ParamTypeDescription
keyKThe 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.

ParamTypeDescription
keyKThe 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)

Inserts a word into the Trie.

Kind: instance method of Trie

ParamTypeDescription
wordstringThe 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.

ParamTypeDescription
wordstringThe 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.

ParamTypeDescription
prefixstringThe 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

ParamTypeDescription
wordstringThe 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.

ParamTypeDescription
prefixstringThe 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.

ParamTypeDescription
rowsnumberThe number of rows in the matrix.
colsnumberThe 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.

ParamTypeDescription
rownumberThe row index (0-based).
colnumberThe 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

ParamTypeDescription
rownumberThe row index (0-based).
colnumberThe column index (0-based).
valuenumberThe 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.

ParamTypeDescription
otherMatrixSparseMatrixThe 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.

ParamTypeDescription
otherMatrixSparseMatrixThe 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

new BitSet(size)

Constructs a BitSet with the specified number of bits.

ParamTypeDescription
sizenumberThe 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

ParamTypeDescription
indexnumberThe 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

ParamTypeDescription
indexnumberThe 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

ParamTypeDescription
indexnumberThe 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).

ParamTypeDescription
indexnumberThe 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.

ParamTypeDescription
startIndexnumberThe 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

new CircularBuffer(size)

Constructs a Circular Buffer with the specified size.

ParamTypeDescription
sizenumberThe 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

ParamTypeDescription
elementTThe 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

ParamTypeDescription
elementTThe 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

ParamTypeDescription
elementTThe 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

ParamTypeDescription
elementTThe 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

ParamTypeDescription
targetTThe element after which to insert.
elementTThe 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.
ParamTypeDescription
urlstringThe 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.
ParamTypeDescription
urlstringThe URL to send the POST request to.
dataRecord.<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.
ParamTypeDescription
urlstringThe URL to send the PUT request to.
dataRecord.<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.
ParamTypeDescription
urlstringThe URL to send the PATCH request to.
dataRecord.<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.
ParamTypeDescription
urlstringThe 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.
ParamTypeDescription
urlstringThe 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.
ParamTypeDescription
urlstringThe URL to send the custom request to.
optionsRequestInitThe 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.

ParamTypeDescription
dataRecord.<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.

ParamTypeDescription
queryStringstringThe 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.

ParamTypeDescription
xmlStringstringThe 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.

ParamTypeDescription
csvStringstringThe CSV string to be converted.
delimiterstringThe 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.

ParamTypeDescription
dataobjectThe 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.
ParamTypeDescription
responseResponseThe 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.

ParamTypeDescription
itemsArray.<any>The list of items to paginate.
pageNumbernumberThe page number to retrieve (1-based index).
pageSizenumberThe 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.

ParamTypeDescription
baseUrlstringThe base URL of the resource.
currentPagenumberThe current page number (1-based index).
pageSizenumberThe number of items per page.
totalItemsnumberThe 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.

ParamTypeDescription
baseUrlstringThe base URL of the resource.
currentPagenumberThe current page number (1-based index).
pageSizenumberThe 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.

ParamTypeDescription
totalItemsnumberThe total number of items to paginate.
pageSizenumberThe 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.

ParamTypeDescription
responseResponseThe 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.

ParamTypeDescription
retryAfterSecondsnumberThe 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.

ParamTypeDescription
timeoutMillisecondsnumberThe 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.

ParamTypeDescription
usernamestringThe username for authentication.
passwordstringThe 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.

ParamTypeDescription
requestConfigRequestInitThe configuration for the HTTP request.
authTokenstringThe 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

ParamTypeDescription
methodstringThe HTTP method of the API call (e.g., 'GET', 'POST').
urlstringThe URL of the API endpoint.
headersHeadersThe request headers.
requestBodystringThe request body, if applicable.
responseBodystringThe 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.

ParamTypeDescription
methodstringThe HTTP method of the API call (e.g., 'GET', 'POST').
urlstringThe URL of the API endpoint.
apiCallPromisePromise.<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

ParamTypeDescription
cacheKeystringThe key for caching the API response.
responseResponseThe 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.

ParamTypeDescription
cacheKeystringThe 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.

ParamTypeDescription
paramsObjectThe 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
1.0.11

8 days ago

1.0.2

11 days ago

1.0.1

11 days ago

1.0.9

11 days ago

1.0.8

11 days ago

1.0.7

11 days ago

1.0.6

11 days ago

1.0.5

11 days ago

1.0.4

11 days ago

1.0.3

11 days ago

1.0.10

11 days ago

1.0.0

12 days ago

0.0.20

12 days ago

0.0.21

12 days ago

0.0.18

12 days ago

0.0.19

12 days ago

0.0.17

4 months ago

0.0.11

7 months ago

0.0.12

7 months ago

0.0.13

7 months ago

0.0.14

7 months ago

0.0.15

7 months ago

0.0.16

7 months ago

0.0.10

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago