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

json-fusion

v0.2.3

Published

Json-Fusion is a Node.js library designed to streamline the process of loading, merging, and reflecting directory hierarchies in JSON files. With Json-Fusion, you can consolidate information scattered across different JSON files, and reflect your filesyst

Downloads

663

Readme

json-fusion

npm npm package minimized gzipped size (select exports) GitHub Release Test

json-fusion is a Node.js library designed to streamline the process of loading, merging, and reflecting directory hierarchies in JSON files. With json-fusion, you can consolidate information scattered across different JSON files, and reflect your filesystem's structure directly in your data, all with just a few lines of code.

Moreover, json-fusion provides a special handling for index.json files. The contents of index.json files are expanded directly into the parent directory's key, rather than creating a separate index key. This allows more intuitive organization of your JSON files.

Features

  • Load all JSON files from a specified directory
  • Merge multiple JSON objects into one
  • Incorporate the directory hierarchy as keys in the resulting JSON object
  • Special handling for index.json files, which are expanded directly under the parent directory's key

Installation

npm install json-fusion

Usage

Here's a basic example of how to use json-fusion:

CommonJS

const jsonFusion = require('json-fusion');

const path = './path/to/your/json/files';
const result = await jsonFusion(path);

console.log(result);

ESModule

import jsonFusion from 'json-fusion';

const path = './path/to/your/json/files';
const result = await jsonFusion(path);

console.log(result);

Structure

Consider the following directory structure:

/path/to/your/json/files
├── config.json
├── users
│   ├── index.json
│   ├── john.json
│   └── jane.json
└── data
    ├── items.json
    └── purchases.json

Running jsonFusion('./path/to/your/json/files') would result in an object similar to:

{
  "config": {/** ./config.json */},
  "users": {
    /** index.json */
    "john": {/** ./users/john.json */},
    "jane": {/** ./users/jane.json */}
  },
  "data": {
    "items": {/** ./data/items.json */},
    "purchases": {/** ./data.purchases.json */}
  }
}

where {/** */} represents the contents of the corresponding JSON file.

API

jsonFusion(path, options)

  • path - The path to the directory containing your JSON files.
  • options - An optional object containing the following options:
    • exportType - The type of export to use. Defaults to json. Can be one of the following:
      • json - Exports the resulting object as a JSON string.
      • yaml - Exports the resulting object as a YAML string. required yaml package
      • object - Exports the resulting object as a JavaScript object.
    • ignore - An array of file names to ignore. Defaults to ['index.json'].
    • cwd - The current working directory to use. Defaults to process.cwd().
    • export - If you want to export the result to a file, you can set the path to the file to be exported.
    • extensions - An array of file extensions to include. Defaults to ['json'].
      • json - JSON files
      • yaml - YAML files. required yaml package
    • noSpreadIndex - If you want to disable the special handling for index.json files, set this to true. Defaults to false.

Contributing

see CONTRIBUTING.md

License

MIT