npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fnet/key-value-transformer

v0.1.4

Published

## Introduction

Readme

@fnet/key-value-transformer

Introduction

The @fnet/key-value-transformer is a utility that allows users to traverse an object or array recursively to modify keys or values according to a user-defined logic. This tool is designed to efficiently process large datasets where there is a need to apply consistent transformations or cleanups to the structure.

How It Works

This tool accepts an object or an array, along with a callback function, and it traverses through each element recursively. The callback function provides the logic on how each key (or index for arrays) and its corresponding value should be transformed. If the callback function returns null for a key, that key is removed from the structure. If it returns a new key-value pair, the original key-value pair is replaced by the new one.

Key Features

  • Recursive Traversal: Automatically explores nested structures, applying transformations deeply within an object or array.
  • Flexible Callback: Users define how keys and values should be updated or if they should be removed entirely.
  • Supports Objects and Arrays: Whether your data is laid out in objects or arrays, this utility can handle it seamlessly.

Conclusion

The @fnet/key-value-transformer is a straightforward tool for anyone needing to update or clean up JSON-like data structures. Its flexibility and recursive nature make it suitable for various applications, from data transformation to data cleaning, without requiring complex coding solutions.

Developer Guide for @fnet/key-value-transformer

Overview

@fnet/key-value-transformer is a utility library designed for developers who need to traverse and manipulate key-value pairs within complex nested structures, such as objects and arrays. By using a simple callback function, you can rename keys, modify values, or remove properties entirely. The library handles recursive traversal, simplifying the process of deep transformations on JavaScript objects and arrays.

Installation

To install @fnet/key-value-transformer, you can use either npm or yarn. Here’s how:

Using npm:

npm install @fnet/key-value-transformer

Using yarn:

yarn add @fnet/key-value-transformer

Usage

@fnet/key-value-transformer exports a main function that takes an object or an array and a callback function as arguments. The callback function is applied to each key-value pair, allowing modifications like changing keys, updating values, or removing entries.

Example Usage

First, import the library in your JavaScript or TypeScript file:

import transform from '@fnet/key-value-transformer';

const data = {
  name: 'John Doe',
  address: {
    city: 'New York',
    state: 'NY'
  },
  projects: ['Project1', 'Project2']
};

const transformedData = transform({
  data,
  callback: (key, value) => {
    // Convert all object keys to uppercase
    const newKey = key.toUpperCase();
    // Example modification: add "Updated" to all project names
    const newValue = key === 'projects' ? value.map(v => v + ' Updated') : value;
    return [newKey, newValue];
  }
});

console.log(transformedData);

Examples

Here are some straightforward examples demonstrating typical transformations:

Example 1: Key Transformation and Value Removal

const inputData = {
  firstName: 'Jane',
  lastName: 'Doe',
  email: '[email protected]'
};

const cleanedData = transform({
  data: inputData,
  callback: (key, value) => {
    if (key === 'email') {
      // Remove the email key
      return null;
    }
    // Keep the key as-is
    return [key, value];
  }
});

console.log(cleanedData); // Output: { firstName: 'Jane', lastName: 'Doe' }

Example 2: Renaming Keys

const userData = {
  user_id: 123,
  user_name: 'jdoe'
};

const updatedData = transform({
  data: userData,
  callback: (key, value) => {
    const keyMapping = {
      user_id: 'id',
      user_name: 'username'
    };

    const newKey = keyMapping[key] || key;
    return [newKey, value];
  }
});

console.log(updatedData); // Output: { id: 123, username: 'jdoe' }

Acknowledgement

This library was developed and maintained by the team at [Your Organization]. Special thanks to contributors who assisted in improving the library with valuable feedback and code contributions.

By following this guide, developers can effectively utilize @fnet/key-value-transformer to perform deep transformations on their data structures, making it an essential utility for modern JavaScript applications.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  data:
    oneOf:
      - type: object
      - type: array
    description: The object or array to be traversed recursively.
  callback:
    type: object
    description: A callback function to process each key. Should return an array
      [newKey, newValue] or null to remove the key.
required:
  - data
  - callback