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

jsonpilot

v1.0.0

Published

JSON versioning and migration tool

Downloads

4

Readme

JSON Pilot

A library designed to help version JSON objects and migrate through them while also providing default data.

Features

  • Minimal Modification: Everything JSON Pilot needs to work is under __pilot to minimize potential collisions.
  • Plug'n play: Have an existing object? No problem! JSON Pilot will add it's necessary metadata and treat it as "version 0."
  • Non-destructive: If a property already exist, JSON Pilot doesn't change it. It only changes what it needs to change.
  • Automatic Sorting: Option to enable sorting of all properties in the object.
  • CommonJS and ESM Support: JSONPilot leverages SWC to export the library in both CommonJS and ESM.

Getting Started

Installation

npm install jsonpilot
# or
yarn add jsonpilot
# or
pnpm add jsonpilot

Basic Usage

import { migrate, MigrateVersions } from 'jsonpilot'

const originalObject = {
  some_value: '123',
}

const versions: MigrateVersions = [
  {
    version: 1,
    migration: {
      some_value: null,
    },
  },
  {
    version: 2,
    migration: {
      another_value: 0,
    },
  },
]

/**
 * This will return the following object
 * {
 *   some_value: '123',
 *   another_value: 0
 * }
 */
const migratedObject = migrate(originalObject, versions)

API Reference

Migrate

migrate(source, versions, options)

  • source: JSON object that is already defined and you want to migrate (if needed).
  • versions: An array of version definitions. The version number is not semantic versioning and follows a simple incremental pattern.
  • options: Optional options to use to further adjust the migration process.
    • targetVersion: If you want to override the default versioning process (to the latest). Defaults to -1 to always upgrade the object to the latest version available.
    • sort: Sorts the object (and nested objects) properties alphabetically. Defaults to false.

License

JSON Pilot is licensed under Mozilla Public License Version 2.0.

Support

While there's no official support, you can always create a new discussion or if you encounter a bug please feel free to open an issue