
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
my-only-either
Advanced tools
Simple Type and Function set for Either interface. Either important concept in functional programming. But Node.js and TypeScript don't have implmentation. So you can choose another functional implementation like fp-ts or anther functional utility. But if you need only Eihter, this package is good alternative.
my-only-either not use package. only 1k(1,489byte) size.
Helpful for functional programming and integrate return type. See below.
import { parse as jsoncParse } from 'jsonc-parser';
import { parse as json5Parse } from 'json5';
function json5Parse(value: string): PassFailEither<Error, Record<any, any>> {
try {
return pass(json5Parse(value));
} catch (err) {
return fail(new Error(err));
}
}
function jsoncParse(value: string): PassFailEither<Error, Record<any, any>> {
try {
return pass(jsoncParse(value));
} catch (err) {
return fail(new Error(err));
}
}
function parse(value: string): Record<any, any> {
const jsoncParsedEither = jsoncParse(value);
if (isPass(jsoncParsedEither)) {
return jsoncParsedEither.pass;
}
const json5ParsedEither = json5Parse(value);
if (isPass(json5ParsedEither)) {
return json5ParsedEither.pass;
}
throw new Error(json5ParsedEither.fail);
}
throw keyword move control-flow. But Either, PassFailEither don't move control-flow besides Either helpful functional programming and function pipe.
Name using left and right.
name | category | description |
---|---|---|
ILeft | type | Left interface |
IRight | type | Right interface |
Either | type | Either type using ILeft and IRight |
TPickLeft | utility type | Return Type of left in Either |
TPickILeft | utility type | Return Type of ILeft in Either |
TPickRight | utility type | Return Type of right in Either |
TPickIRight | utility type | Return Type of IRight in Either |
left | function | value convert ILeft type |
right | function | value convert IRight type |
isLeft | function | check given value is ILeft type |
isRight | function | check given value is IRight type |
Name using pass and fail.
name | category | description |
---|---|---|
IFail | type | Fail interface |
IPass | type | Pass interface |
PassFailEither | type | PassFailEither type using IFail and IPass |
TPickFail | utility type | Return Type of fail in Either |
TPickIFail | utility type | Return Type of IFail in Either |
TPickPass | utility type | Return Type of pass in Either |
TPickIPass | utility type | Return Type of IPass in Either |
fail | function | value convert IFail type |
pass | function | value convert IPass type |
efail | function | value convert IFail type, exactly same fail. If you use jest or test runner this function is helpful for auto import & auto complete |
epass | function | value convert IPass type, exactly same pass. If you use jest or test runner this function is helpful for auto import & auto complete |
isFail | function | check given value is IFail type |
isPass | function | check given value is IPass type |
First type arguments is ILeft or IFail. Because fp-ts and many functional programming language choose first type is left(or fail).
type Either<TLEFT, TRIGHT> = ILeft<TLEFT> | IRight<TRIGHT>;
FAQs
Only support either interface
We found that my-only-either 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.