
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
lazy-getter
Advanced tools
[](https://badge.fury.io/js/lazy-getter) [](https://badge.fury.io/gh/briandamaged%2Fnode-lazy-getter)
Lazily evaluate properties and cache the results.
npm install lazy-getter
If you're using plain-old Javascript, then you can inject lazy getters into your objects via the injectLazyGetter(...)
function:
const { injectLazyGetter } = require('lazy-getter');
const x = {};
// Notice: this getter is computationally expensive to run!
injectLazyGetter(x, "expensive", function() {
console.log("Starting calculations");
let k = 0;
for(let i = 0; i < 100000; ++i) {
for(let j = 0; j < 100000; ++j) {
++k;
}
}
console.log("Finished expensive calculation!");
return k;
});
// The getter will be evaluated the first time it is invoked
console.log(x.expensive); // Super SLOW!
// Now the result is cached. So, all subsequent calls will
// just be regular property lookups.
console.log(x.expensive); // Super FAST!
If you're using Babel's Decorators Transform, then you can convert your getters to lazy getters via the @lazyGetter
decorator:
const { lazyGetter } = require('lazy-getter');
const x = {
@lazyGetter
get expensive() {
console.log("Starting calculations");
let k = 0;
for(let i = 0; i < 100000; ++i) {
for(let j = 0; j < 100000; ++j) {
++k;
}
}
console.log("Finished expensive calculation!");
return k;
},
};
console.log(x.expensive); // Super SLOW!
console.log(x.expensive); // Super FAST!
Lazy Getters might seem a bit esoteric, but they are definitely very handy in certain scenarios. Here are a few examples:
For example:
class HumongousNumber {
@lazyGetter
get primeFactorization() {
// Algorithm that returns an Array of prime factors
// for the number. Might take years to run.
}
}
Sometimes, it's useful to model a problem as an infinite graph of Objects. Obviously, you can't actually contruct this infinite graph since it would require an unlimited about of time and memory. Fortunately, you can "fake it" using lazy getters:
function integerNode(i) {
return {
value: i,
@lazyGetter
get next() {
return integerNode(i + 1);
},
}
}
const x = integerNode(0);
console.log(x.next.next.next.next.value); // Prints: 4
Now the object graph will be constructed as needed.
FYI: zelda-lists leverages this technique to convert any iterable Object into a linked list. This allows infinite iterators to be converted into infinite object graphs, which makes it significantly easier to implement recursive algorithms.
FAQs
[](https://badge.fury.io/js/lazy-getter) [](https://badge.fury.io/gh/briandamaged%2Fnode-lazy-getter)
We found that lazy-getter 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.