Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
util-deprecate
Advanced tools
The util-deprecate package is a utility for node and the browser that allows developers to mark functions or methods as deprecated. This helps in signaling to users of the library that a particular function or method will be removed or changed in future releases. It provides a straightforward way to display deprecation warnings to developers, encouraging them to update their code to use newer or preferred APIs.
Deprecating a function
This feature allows you to wrap a function with a deprecation warning. When the deprecated function is called, it will execute normally, but it will also print a warning message to the console indicating that the function is deprecated.
const deprecate = require('util-deprecate');
const deprecatedFunction = deprecate(function() {}, 'deprecatedFunction is deprecated and will be removed in the next major release.');
Custom warning message
This demonstrates how to provide a custom warning message for the deprecated function. This is useful for guiding users towards an alternative function or method.
const deprecate = require('util-deprecate');
const customWarningFunction = deprecate(function() {}, 'customWarningFunction is deprecated. Please use alternativeFunction instead.');
Similar to util-deprecate, depd is a deprecation helper for node.js. It allows you to mark functions, properties, and messages as deprecated with a customizable message. Compared to util-deprecate, depd offers more detailed control over how and where deprecation messages are displayed, including the ability to silence them or output them to different streams.
The deprecated package is another alternative that provides decorators and function wrappers to mark methods or functions as deprecated. It is particularly useful in an ES6/ES7 environment where decorators can be used. Unlike util-deprecate, which is more straightforward and function-focused, deprecated offers a more modern syntax for deprecating features within a class or object.
util.deprecate()
function with browser supportIn Node.js, this module simply re-exports the util.deprecate()
function.
In the web browser (i.e. via browserify), a browser-specific implementation
of the util.deprecate()
function is used.
A deprecate()
function is the only thing exposed by this module.
// setup:
exports.foo = deprecate(foo, 'foo() is deprecated, use bar() instead');
// users see:
foo();
// foo() is deprecated, use bar() instead
foo();
foo();
(The MIT License)
Copyright (c) 2014 Nathan Rajlich nathan@tootallnate.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
The Node.js `util.deprecate()` function with browser support
The npm package util-deprecate receives a total of 47,224,417 weekly downloads. As such, util-deprecate popularity was classified as popular.
We found that util-deprecate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.