Skip to content

Deprecated in favor of ajel's rewrite but still neat

Notifications You must be signed in to change notification settings

Handfish/ajel-go

Repository files navigation

DEPRECATED

Personally - I recommend using ajel instead. Follow this link to see the new api.

ajel-go is a 312 byte set of functions that encourage you to handle errors in a way that is similar to Golang.

NPM Version Package License NPM Downloads

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-go';

function main() {
  const [result, err] = sjel(JSON.parse)("{}");

  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

Basic eslintrc

{
  plugins: ['ajel-go'],
  extends: [
    'plugin:ajel-go/recommended',
  ],
}

What's inside this repo?

Apps and Packages

  • docs: A placeholder documentation site powered by Next.js
  • ajel: The core library (function)
  • eslint-plugin-ajel: Eslint rules for proper usage and error handling paradigm
  • benchmarks: Testing ajel-go's performance against other methods

About

Deprecated in favor of ajel's rewrite but still neat

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published