JSPM

deprecated-obj

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 169206
  • Score
    100M100P100Q160209F
  • License MIT

Compares deprecations against a configuration object, and returns a compliant object and violations

Package Exports

  • deprecated-obj

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (deprecated-obj) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

deprecated-obj

Simple utility to help making the transition from deprecated configuration objects to compliant ones.

Usage

const Deprecation = require('deprecation');

const myConfig = {
  fine: true,
  old: {
    deprecated: true
  },
  'remove.me': 1
};

const deprecations = {
  old: {
    deprecated: 'new.shiny'
  },
  'remove.me': null
};

// Or flat:
const deprecations = { 'old.deprecated': 'new.shiny', 'remove.me': null };

const deprecation = new Deprecation(deprecations, myConfig);

API

Deprecation::getCompliant()

const myCompliant = deprecation.getCompliant();{ fine: true, new: { shiny: true } }

Returns a new, compliant object. The null values in deprecations are excluded.

Deprecation::getViolations()

const violations = deprecation.getViolations();{ 'old.deprecated': 'new.shiny', 'remove.me': null }

The violations can be used to inform the user about the deprecations, for example:

if (Object.keys(violations).length > 0) {
  console.warn(`Deprecated configuration options found. Please migrate before the next major release.`);
}
for (let deprecated in violations) {
  console.warn(`The "${deprecated}" option is deprecated. Please use "${violations[deprecated]}" instead.`);
}

Example

See github.com/release-it/.../deprecated.js for a real-world example.