Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 4, 2024 via pnpm

reusify 1.0.4

Reuse objects and functions with style
Package summary
Share
0
issues
1
license
1
MIT
Package created
11 Sep 2015
Version published
26 Jan 2018
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
reusify@1.0.4
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of reusify 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does reusify do?

Reusify is an efficient and potent NPM package for JavaScript, designed to significantly speed up your functions by reusing objects and functions. By leveraging a cache system, Reusify enables you to reuse instances of your objects, reducing the computational load and optimizing your program's speed by approximately 10%. This can be especially beneficial in hot code paths where functions are called frequently.

How do you use reusify?

To use this dynamic tool, you need to install it in your JavaScript project via npm. Then you can require it in your JavaScript files where you want to use it. Below is a simple example of synchronous code with Reusify.

var reusify = require('reusify')
var instance = reusify(MyObject)

// get an object from the cache,
// or creates a new one when cache is empty
var obj = instance.get()

// set the state
obj.num = 100
obj.func()

// reset the state.
obj.num = 0

// store an object in the cache
instance.release(obj)

For dealing with asynchronous code, here's an example of using Reusify to recycle instances of an object:

var reusify = require('reusify')
var instance = reusify(MyObject)

for (var i = 0; i < 100; i++) {
  getData(i, console.log)
}

function getData (value, cb) {
  var obj = instance.get()
  obj.value = value
  obj.cb = cb
  obj.run()
}

function MyObject () {
  this.next = null
  this.value = null
  var that = this

  this.run = function () {
    asyncOperation(that.value, that.handle)
  }

  this.handle = function (err, result) {
    that.cb(err, result)
    that.value = null
    that.cb = null
    instance.release(that)
  }
}

Where are the reusify docs?

Unfortunately, there are no dedicated documentation pages available for the Reusify package at a separate location. The primary source of documentation for Reusify is its README directly on the project's GitHub repository page, which is at https://github.com/mcollina/reusify. Complete with examples and detailed explanations, the README provides the necessary information to understand and use Reusify effectively. Keep track of the repository for future updates, bug fixes, or changes in the project's functionality or syntax.