# depreciator

> versioning for object function arguments

Latest version **0.0.1** (published 2013-10-25) · BSD license · 0 weekly downloads

## Install

```sh
npm install depreciator
pnpm add depreciator
yarn add depreciator
bun add depreciator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2013-10-25 |
| First published | 2013-10-25 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | sideshowcoder |
| Maintainers | sideshowcoder |
| Keywords | json, versioning, objects |

## Links

- npm: https://www.npmjs.com/package/depreciator
- Repository: git@github.com:sideshowcoder/depreciator
- npm.io page: https://npm.io/package/depreciator

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.1 (latest) — 2013-10-25

## README

# Depreciator versioning support for data argument

Sometimes a it is nice to know which version of data a function is passed.
Especially in NoSQL land it can be used to ensure some kind of schema, and
handle changes transparently.

Todo this Depreciator assumes that the data contains a numeric version under the
key \__version

  ```javascript
  { __version: 1, something: 'else', can: 'be here' }
  ```

This version is checked against the ensured, and actions can be take for it.
No version present assumes a 0.

## Usage


### enable depreciator
For depreciator to hook the functions it need to be required and enabled for a
given module

  ```javascript
  var depreciator = require('depreciator')

  var myThing = {
    myFunc: function(thing, param, stuff) {
      doGreatThings(thing, param, stuff)
    },
    func: function(thing, stuff) {
      doAwesomeStuff(thing, stuff)
    }
  }

  module.exports = depreciator.enable(myThing)
  ```

Now versions can be ensured on the functions, it will check the first argument
to the function for it's \__version field.

### ensure a version
ensure version for just this function

  ```javascript
  depreciator.ensure(2, 'myFunc')
  ```

ensure version globally for every function in the module it is enabled for.

  ```javascript
  depreciator.ensure(1)
  ```

### handle missmatches
ensure version for just this function and call fallback if versions don't match

  ```javascript
  version.ensure(3, 'func', function(thing, version, expectedVersion) {
    console.log("you are old")
  })
  ```

install a global fallback function to be called on version missmatch

  ```javascript
  version.ensure(1, function(thing, version, expected) {
    console.log("OLD!!!")
  })
  ```

### hook the function
register hook for when versions are not satisfied hooks are run before the function is called

  ```javascript
  version.registerMismatchHook(function(thing, version, expected) {
    console.log("OLD!!!")
  })
  ```

## License
MIT

---
_Source: https://npm.io/package/depreciator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
