Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

depreciator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depreciator

versioning for object function arguments

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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

{ __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

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

depreciator.ensure(2, 'myFunc')

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

depreciator.ensure(1)

handle missmatches

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

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

install a global fallback function to be called on version missmatch

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

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

License

MIT

Keywords

FAQs

Package last updated on 25 Oct 2013

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc