
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
elegant-expression
Advanced tools
Library provides try/catch/finally
as expression.
npm i elegant-expression -S
JavaScript and TypeScript (accordingly) provide the try/catch/finally
only as statement.
When using a block of try/catch/finally
creating different scopes and you will need to declare ahead the variables that are used within blocks. Additional, you should manual set types for this variables (you can't using smart detection types of variables) and make casting of error type in block of catch.
All this leads to the writing of boilerplate code and makes it difficult to read:
// Before 😮💨
let status: 'ok' | 'fail';
try {
await fn();
status = 'ok';
// error has type unknown
} catch (err: unknown) {
const error = err as Error;
status = 'fail';
}
// After 🙆♂️
import exp from 'elegant-expression';
// We get result of executing immediately in one place
const status = await exp
.try(async () => {
await fn();
return 'ok';
})
// error already has type Error
.catch((err: Error) => {
console.error(err);
return 'fail';
});
try/catch/finally
:
const result = await exp
.try(async () => {
await fn();
return 'ok';
}).catch((err) =>
'fail'
).finally(() =>
console.log('finally');
);
try/finally
:
const result = await exp
.try(async () => {
await fn();
return 'ok';
}).finally(() =>
console.log('finally');
);
FAQs
Library provides try/catch/finally as expression
The npm package elegant-expression receives a total of 1 weekly downloads. As such, elegant-expression popularity was classified as not popular.
We found that elegant-expression 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.