@arun_murali/rustyutils v1.0.11
📘 Function Documentation
Introduction
Welcome to the function documentation for our project! This document provides detailed descriptions, parameters, return values, and example usages for all available functions. It is designed to help you understand how each function works and how to use them in your projects. Below you'll find a table of contents that links to each function’s detailed documentation.
Table of Contents
deep_clone()
Description: Creates a deep copy of the given input.
Example usage:
const cloned = deep_clone({ key: 'value' });
console.log(cloned); // Output: { key: 'value' }Parameters
| Name | Type | Description |
|---|---|---|
input | any | The value to clone. |
Returns
| Type | Description |
|---|---|
any | The deeply cloned value. |
flatten()
Description: Flattens a nested object or array into a single-level object with dot-separated keys.
Example usage:
const flattened = flatten({ 'a.b.c': 1 });
console.log(flattened); // Output: { 'a.b.c': 1 }Parameters
| Name | Type | Description |
|---|---|---|
input | any | The object or array to flatten. |
Returns
| Type | Description |
|---|---|
any | The flattened object with dot-separated keys representing the hierarchy of the original structure. |
hash_value()
Description: Generates a hash of the input string using the specified algorithm.
Example usage:
const hash = hash_value('hello world', 'sha256');
console.log(hash); // Output: e.g. '64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477246bfe2f30e6e5aef'Parameters
| Name | Type | Description |
|---|---|---|
input | string | The input string to hash. |
algo | string | The hash algorithm to use. Supported: 'sha256', 'sha512', 'md5', 'sha3_256', 'sha3_512', 'blake2b', 'blake2s'. |
Returns
| Type | Description |
|---|---|
string | The hexadecimal string of the hash output. |
compare_hash()
Description: Compares an input string against a given hash using the specified algorithm.
Example usage:
const isValid = compare_hash('hello world', 'sha256', '64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477246bfe2f30e6e5aef');
console.log(isValid); // Output: trueParameters
| Name | Type | Description |
|---|---|---|
input | string | The input string to hash and compare. |
algo | string | The hashing algorithm to use. Same options as in hash_value. |
expected_hash | string | The expected hash string to compare with. |
Returns
| Type | Description |
|---|---|
boolean | Returns true if the generated hash matches the expected hash; otherwise, false. |
chunk()
Description: Splits an input array into smaller chunks of a specified size.
Example usage:
const result = chunk([1, 2, 3, 4, 5], 2);
console.log(result); // Output: [[1, 2], [3, 4], [5]]Parameters
| Name | Type | Description |
|---|---|---|
input | Array<any> | The input array to be divided into chunks. |
size | number | The maximum size of each chunk. |
Returns
| Type | Description |
|---|---|
Array<Array<any>> | Returns an array of chunked arrays. |