
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
using-statement
Advanced tools
Function call that acts like a using statement.
With Deno:
import { using } from "https://deno.land/x/using_statement/mod.ts";
Or with Node:
npm install --save using-statement
Before:
const camera = new Camera();
try {
outputPicture(camera.takePictureSync());
} finally {
camera.dispose();
}
After:
import { using } from "https://deno.land/x/using_statement/mod.ts";
using(new Camera(), (camera) => {
outputPicture(camera.takePictureSync());
});
dispose(), close(), or unsubscribe() method.Setup:
// Camera.ts
export class Camera {
takePictureSync() {
// ...etc...
return pictureData;
}
async takePicture() {
// ...etc...
return pictureData;
}
dispose() {
// clean up the resource this class is holding
}
}
Synchronous example:
import { using } from "https://deno.land/x/using_statement/mod.ts";
import { Camera } from "./Camera.ts";
using(new Camera(), (camera) => {
const picture = camera.takePictureSync();
outputPicture(picture); // some function that outputs the picture
});
// camera is disposed here
Asynchronous example:
import { using } from "https://deno.land/x/using_statement/mod.ts";
import { Camera } from "./Camera.ts";
await using(new Camera(), async (camera) => {
const picture = await camera.takePicture();
outputPicture(picture);
});
// camera is disposed here
Generator function example:
import { using } from "https://deno.land/x/using_statement/mod.ts";
import { Camera } from "./Camera.ts";
const picturesIterator = using(new Camera(), function* (camera) {
for (let i = 0; i < 10; i++) {
yield camera.takePictureSync();
}
});
// camera is not disposed yet...
for (const picture of picturesIterator) {
outputPicture(picture);
}
// camera is now disposed
FAQs
"using statement" in JavaScript and TypeScript.
The npm package using-statement receives a total of 322 weekly downloads. As such, using-statement popularity was classified as not popular.
We found that using-statement 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.