@fabryscript/algorithms
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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.

Package Sidebar

Install

npm i @fabryscript/algorithms

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

5.52 kB

Total Files

8

Last publish

Collaborators

  • fabryscript