ajel-go
v0.0.4
Published
ajel-go encourages handling errors similarly to Golang
Downloads
6
Readme
DEPRECATED
Personally - I recommend using ajel instead. Follow this link to see the new api.
ajel-go
Installation
yarn add ajel-go eslint-plugin-ajel-go
pnpm add ajel-go eslint-plugin-ajel-go
Example usage
// Handling async functions that throw
import { ajel } from 'ajel-go';
async function main() {
const [result, err] = await ajel(Promise.resolve('hello world'));
if (err) {
return err;
}
return result;
}
// Handling synchronous functions that throw
import { sjel } from 'ajel';
function main() {
const [res, err] = sjel(fs.readFileSync)(path, { encoding: 'utf8' });
if (err) {
return err;
}
return result;
}
ajel
and sjel
are a set of functions that return a tuple representing a potential result and a potential error.
On success, the result item has value. On error, the error item has value. It's that simple.
More interestingly, it comes with a series of linting tools to help enforce the paradigm available in the package eslint-plugin-ajel