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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lcdkhoa/object-handler

v1.0.2

Published

Convert complex nested data structures into flat formats and vice versa, to enhance simplicity and efficiency in data management.

Downloads

1

Readme

@lcdkhoa/object-handler

Convert complex nested data structures into flat formats and vice versa, to enhance simplicity and efficiency in data management.

Installation

Install the package using npm:

npm install @lcdkhoa/object-handler

Or using yarn:

yarn add @lcdkhoa/object-handler

Usage

Flatten Objects

Converts a nested object into a flat object.

import { FlattenObjects } from "@lcdkhoa/object-handler";

const splitter = "_"; // Custom splitter, default is "_"
const nestedObject = {
  user: {
    name: "John Doe",
    address: {
      city: "New York",
      country: "USA",
    },
  },
};

const flatObject = FlattenObjects(nestedObject, splitter);

console.log(flatObject);
// Output: { "user_name": "John Doe", "user_address_city": "New York", "user_address_country": "USA" }

UnFlattening Objects

Converts a flat object back into a nested object.

import { UnFlatObjects } from "@lcdkhoa/object-handler";

const splitter = "_"; // Custom splitter, default is "_"
const flatObject = {
  user_name: "John Doe",
  user_address_city: "New York",
  user_address_country: "USA",
};

const nestedObject = UnFlatObjects(flatObject, splitter);

console.log(nestedObject);
// Output: { user: { name: "John Doe", address: { city: "New York", country: "USA" } } }

Handling Arrays within Objects

Demonstrates how to handle objects containing arrays when flattening and unFlattening.

Flattening Objects with Arrays
import { FlattenObjects } from "@lcdkhoa/object-handler";

const splitter = "_"; // Custom splitter, default is "_"
const objectWithArray = {
  user: {
    name: "Jane Doe",
    hobbies: ["reading", "painting", "cycling"],
  },
};

const flatObject = FlattenObjects(objectWithArray, splitter);

console.log(flatObject);
// Output: { "user_name": "Jane Doe", "user_hobbies[0]": "reading", "user_hobbies[1]": "painting", "user_hobbies[2]": "cycling" }
UnFlattening Objects with Arrays
import { UnFlatObjects } from "@lcdkhoa/object-handler";

const splitter = "_"; // Custom splitter, default is "_"
const flatObjectWithArray = {
  user_name: "Jane Doe",
  "user_hobbies[0]": "reading",
  "user_hobbies[1]": "painting",
  "user_hobbies[2]": "cycling",
};

const nestedObject = UnFlatObjects(flatObjectWithArray, splitter);

console.log(nestedObject);
// Output: { user: { name: "Jane Doe", hobbies: ["reading", "painting", "cycling"] } }

Playground

Explore and test the capabilities of @lcdkhoa/object-handler in real-time with our interactive playground. Visit https://lcdkhoa.com/tools to access the playground.

Features

  • Live Editing: Instantly see the results of flattening and unFlattening operations as you type.
  • Custom Configurations: Experiment with different configurations, such as custom split keys for unFlattening.
  • Examples Library: Access a variety of pre-defined examples to understand how @lcdkhoa/object-handler can be used in different scenarios.
  • Code Export: Easily export your playground code for use in your projects.

How to Use

  1. Navigate to https://lcdkhoa.com/tools.
  2. Select the @lcdkhoa/object-handler playground from the tools list.
  3. Enter your JSON object in the input area. You can choose to flatten or un-flat the object.
  4. Customize the operation using the available options, if needed.
  5. Observe the output in real-time as you make changes.
  6. Copy the output or export the code snippet for use in your project.

This playground is an excellent way to familiarize yourself with the library's functionality and to prototype solutions before integrating them into your application.

GitHub

For more information, updates, and to contribute to the project, visit our GitHub repository:

https://github.com/lcdkhoa/object-handler

We welcome contributions, feedback, and bug reports!

License

This project is licensed under the MIT License.