Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
A lib to encapsute operation result and manage logs.
process.env.LOG_LEVEL = 'info' | 'debug' | 'none'
Case LOG_LEVEL is defined as info all Result state will print basic information on terminal
Case LOG_LEVEL is defined as debug all Result state will show result state and file name execution
First you need to have an operation like example below
import { Payload, Ok, Fail, Error } from 'op-result';
class MyOperation {
// operation
execute(value: number): Payload<string, Error> {
// success result
if(value % 2 === 0) return Ok('success');
// failure result
return Fail({ message: 'invalid value' });
}
}
const myOp = new MyOperation();
const result = myOp.execute(10);
// ok state
console.log(result.isOk());
> true
// data state
console.log(result.data());
> "success"
// error state
console.log(result.error());
> null
Lets see an example to signup
import { Payload, Ok, Fail, Error } from 'op-result';
class SignUp {
execute(data: Auth): Payload<User, Error> {
// create user instance
const user = User.create(data);
// check user instance
if(user.isFail()) return Fail({ message: 'oops' });
// success state
return Ok(user.data());
}
}
const mailer = new Mailer();
const auth = new SignUp();
const result = auth.execute({ name, email, password });
// This will be executed only case result is Ok
// sendEmail function will receive Auth arg data
result.on('OK').execute(mailer.sendEmail);
// This will be executed only case result is Fail
// console.log function will receive error state
result.on('FAIL').execute(console.log);
You can check many results state with combine
import { Ok, Fail, Combine } from 'op-result';
const resultsA = [ Ok(), Ok(), Ok() ];
// check many results
const resA = Combine(resultsA);
const isOkA = resA.isOk();
console.log(isOkA);
> true
const resultsB = [ Ok(), Fail(), Ok() ];
// check many results
const resB = Combine(resultsB);
const isOkB = resB.isOk();
console.log(isOkB);
> false
FAQs
A lib to encapsute operation result and manage logs. ## Logs
We found that op-result 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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.