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

@dworkman/jam

v1.0.4

Published

jam: JSON Array Modifier - A small package to help you add additional properties and data to a JSON array and return a JSON file or JSON string.

Downloads

1

Readme

jam - JSON Array Modifier

A package to add additional properties to every object in a JSON array and return a new JSON file or string.


This started out as a single script and I saw the potential to flesh it out and break it apart to use as my first NPM package.

There is only one CLI dependency, making this a super light weight package. It is just a series of JS files that take in your original data, alongside an object containing the desired keys and values you want to add to each object in your initial array.

There are examples of the JSON data that the function expects under the /src/lib/mocks dir.

Documentation

Syntax

CLI

Usage
$ jam -s <source> -d <data> -o <outputType> -r <random> -fn <fileName> -fp <filePath>

    Options
    --source, -s  Original source of data.
    --data, -s Data you want to add.
    --outputType -o Do you want json returned or a new .json file created? Accepts "json" & "file".
    --random, -r Do you want to randomise what data is added?
    --fileName, -fn, If you're creating a new file, choose a name.
    --filePath, -fp, Enter a filepath where you'd like to create your file. Default is './'.

    Examples
      $ jam -s "../src/lib/mocks/input.json" -d "../src/lib/mocks/additions.json" -o "json"
      $ jam -s "https://jsonplaceholder.typicode.com/posts" -d "https://jsonplaceholder.typicode.com/photos/1" -o "json"
      $ jam -s "https://jsonplaceholder.typicode.com/posts" -d "../src/lib/mocks/additions.json" -o "file" -r true --fn "testFile"

On Client

const [returnJson, createFile] = modifyJsonArray();
const newJsonArray = returnJson(input, additions, options);

On Server (NodeJs)

createFile(input, additions, options);

Parameters

input

This defines the resource of which you wish to modify. This can either be

  • A string path to a JSON file
  • An Array of objects

additions

An object containing the keys and values what you wish added to each object.

options (optional)

An object containing the following options:

random (optional)

A Boolean flag that lets you decide if you want to randomise what value is added to each object per property. Default is set to false.

filename (optional)

The name of the file you'd like to create.

fileSaveLocation (optional)

If you wish to create a file, where would you want the file to be created. Default is ./.

Return value

The return value is dependent on which function you invoke.

  • returnJson - String of json data.
  • createFile - void. A new file will be created.

Example

This package is only built for use with ESM compatiable projects. Therefore use ESM syntax:

import jam from '@dworkman/jam';
import input from './mocks/mockInput.json' assert { type: 'json' };
import additions from './mocks/mockAdditions.json' assert { type: 'json' };

const [returnJson] = modifyJsonArray();

const options = {
  random: true,
  fileName: 'newJsonData',
  fileSaveLocation: '../../tmp',
};

const newJSON = returnJson(input, additions, options);

console.log(newJSON);