Algorithms
A collection of utility functions and algorithms for various programming tasks.
Installation
You can install the @fabryscript/algorithms
library using npm or yarn:
npm install @fabryscript/algorithms
yarn add @fabryscript/algorithms
Usage
Import the functions you need from the library and use them in your code.
transformKeys<T>(o: Record<string, T>, transformCallback: (originalKey: string) => string | Promise<string>): Record<string, T> | Promise<Record<string, T>>
Transform an object's keys based on a provided callback function, which can be either synchronous or asynchronous.
Parameters:
o
(Required): The object to be operated on.transformCallback
(Required): The callback function that transforms each key. It must return a string as the keys are expected to be strings. This callback can be either synchronous or asynchronous.
Returns:
- A new object with transformed keys. If the
transformCallback
is asynchronous, it returns a promise that resolves to the new object.
Example:
import { transformKeys } from "@fabryscript/algorithms"
const inputObject = { name: 'John', age: 30 };
const asyncTransformCallback = async (key) => key.toUpperCase();
const transformedObject = await transformKeys(inputObject, asyncTransformCallback);
console.log(transformedObject);
License
This library is open-source and available under the MIT License.