New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@twogate/migrason

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twogate/migrason

migrason (/maigréisɒn/) is a migration tool for JSON.

0.1.5
latest
npm
Version published
Weekly downloads
0
-100%
Maintainers
4
Weekly downloads
 
Created
Source

migrason

migrason (/maigréisɒn/) is a migration tool for JSON.

Run

# Run migration script
# $ node <migrate script> <old input json> <output filename>
node 001_add_properties.js 001.json ./out.json

Example

Adding properties

Assume 001.json as input json. When you want to migrate it to 002.json, you can write a migrate file like 001_add_properties.js.

  change(prev) {
    // The previous JSON can be accessed via `prev`
    console.log(prev)

    // Apply the default values
    // Properties with default values that are not in the previous JSON will be added
    // If the previous JSON already has a property same as the default property, the value of the previous JSON is used.
    return this.applyDefaults(prev)
  }

Removing properties

To remove properties, use the delete operator of JavaScript. An example is 002_delete_and_rename_props.js.

  change(prev) {
    // assign object which is applied default values
    const next = this.applyDefaults(prev)

    // copying property
    next.tabs.layout = prev.tabs.tabs

    // removing property
    delete next.theme.appTheme.accent
    delete next.tabs.tabs

    return next
  }

Customizing (de)serializer

To customize (de)serializer, you can override (de)serializer methods. 001_add_properties_yaml.js is an example that overrides (de)serializer to read/write yaml files.

  deserialize(input) {
    return yaml.safeLoad(input)
  }

  serialize(next) {
    return yaml.safeDump(next)
  }

Hint

  • If you write a default value which is not existing on old JSON, the default value is used for output.
  • Properties that are not in the default value are not removed from the old JSON and must be removed explicitly.

FAQs

Package last updated on 02 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts