
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
limit-once
Advanced tools
Create a function that caches the result of the first function call. limit-once
let's you lazily evaluate a value (using a function), and then hold onto the value forever.
import { once } from 'limit-once';
function sayHello(name: string): string {
return `Hello ${name}`;
}
const cached = once(sayHello);
cached('Alex');
// sayHello called and "Hello Alex" is returned
// "Hello Alex" is put into the cache.
// returns "Hello Alex"
cached('Sam');
// sayHello is not called
// "Hello Alex" is returned from the cache.
cached('Greg');
// sayHello is not called
// "Hello Alex" is returned from the cache.
// is-safari.ts
import { once } from 'limit-once';
// We are caching the result of our 'isSafari()' function as the result
// of `isSafari()` won't change.
export const isSafari = once(function isSafari(): boolean {
const { userAgent } = navigator;
return userAgent.includes('AppleWebKit') && !userAgent.includes('Chrome');
});
// app.ts
if (isSafari()) {
applySafariFix();
}
# yarn
yarn add limit-once
# npm
npm install limit-once
# bun
bun add limit-once
.clear()
)You can clear the cache of a memoized function by using a .clear()
function that is on your cached function.
import { once } from 'limit-once';
function sayHello(name: string): string {
return `Hello ${name}`;
}
const cached = once(sayHello);
cached('Alex');
// sayHello called and "Hello Alex" is returned.
// "Hello Alex" is put into the cache
// cached function returns "Hello Alex"
cached('Sam');
// sayHello is not called
// "Hello Alex" is returned from cache
cached.clear();
cached('Greg');
// sayHello is called and "Hello Greg" is returned.
// "Hello Greg" is put into the cache
// "Hello Greg" is returned.
FAQs
Remember the first result of a function call
The npm package limit-once receives a total of 0 weekly downloads. As such, limit-once popularity was classified as not popular.
We found that limit-once demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.