0.0.3 • Published 7 months ago

@fabryscript/algorithms v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Algorithms

License

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
# or
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);
// Output: { NAME: 'John', AGE: 30 }

License

This library is open-source and available under the MIT License.

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago