https://github.com/webpro/deprecated-obj
Compares deprecations against a configuration object, and returns a compliant object and violations
https://github.com/webpro/deprecated-obj
Last synced: 4 months ago
JSON representation
Compares deprecations against a configuration object, and returns a compliant object and violations
- Host: GitHub
- URL: https://github.com/webpro/deprecated-obj
- Owner: webpro
- License: mit
- Created: 2019-01-03T14:15:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T11:14:02.000Z (over 5 years ago)
- Last Synced: 2025-06-02T20:37:51.738Z (11 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deprecated-obj
Simple utility to help making the transition from deprecated configuration objects to compliant ones.
## Usage
```js
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()`
```js
const myCompliant = deprecation.getCompliant();
→ { fine: true, new: { shiny: true } }
```
Returns a new, compliant object. The `null` values in `deprecations` are excluded.
### `Deprecation::getViolations()`
```js
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:
```js
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](https://github.com/webpro/release-it/blob/master/lib/deprecated.js) for a real-world example.