Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
deep-freeze
Advanced tools
The deep-freeze npm package is used to recursively freeze objects, making them immutable. This means that once an object is frozen, it cannot be modified, which is useful for ensuring the integrity of data structures in JavaScript applications.
Deep Freezing Objects
This feature allows you to deeply freeze an object, making it and all nested objects immutable. Any attempts to modify the object or its nested properties will fail silently in non-strict mode or throw an error in strict mode.
const deepFreeze = require('deep-freeze');
const obj = {
a: 1,
b: {
c: 2
}
};
deepFreeze(obj);
obj.a = 2; // This will not change the value of obj.a
obj.b.c = 3; // This will not change the value of obj.b.c
console.log(obj); // { a: 1, b: { c: 2 } }
The deep-freeze-strict package is similar to deep-freeze but throws an error when attempting to modify a frozen object, even in non-strict mode. This can be useful for debugging and ensuring that immutability is strictly enforced.
The immer package provides a more flexible approach to immutability by allowing you to work with mutable state in a draft state and then producing an immutable state. It is more powerful and versatile compared to deep-freeze, especially for complex state management.
The immutable package offers a comprehensive set of immutable data structures, such as List, Map, and Set. It provides more functionality and performance optimizations compared to deep-freeze, making it suitable for large-scale applications.
recursively Object.freeze()
objects
var deepFreeze = require('deep-freeze');
deepFreeze(Buffer);
Buffer.x = 5;
console.log(Buffer.x === undefined);
Buffer.prototype.z = 3;
console.log(Buffer.prototype.z === undefined);
$ node example/deep.js
true
true
var deepFreeze = require('deep-freeze')
Call Object.freeze(obj)
recursively on all unfrozen properties of obj
that
are functions or objects.
public domain
Based in part on the code snippet from the MDN wiki page on Object.freeze(), which is released to the public domain.
FAQs
recursively Object.freeze() objects and functions
The npm package deep-freeze receives a total of 536,844 weekly downloads. As such, deep-freeze popularity was classified as popular.
We found that deep-freeze 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.