New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

flatry

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatry

Flatry converting promise or function to flat array response. Inspired by golang style error handling without try/catch.

latest
Source
npmnpm
Version
1.0.15
Version published
Maintainers
1
Created
Source

Flatry

Build Status GitHub license

Flatry (flat try) converting promise or function to flat array response with [err, result].

Inspired by golang style error handling without try/catch.

 

Install

npm install flatry
# or
yarn add flatry

 

Use

import flatry from "flatry";
// or
const flatry = require("flatry");

 

Examples

Flatry example

 

Asynchronous (async/await)

// Before
async asyncData({ app, error }) {
  try {
    const categories = (await app.$axios.$get('forum')).sections;
    return { categories };
  } catch (err) {
    return error({ statusCode: err.statusCode });
  }
}


// After
async asyncData({ app, error }) {
  const [err, res] = await flatry(app.$axios.$get('forum'));
  if (err) return error({ statusCode: err.statusCode });
  return { categories: res.sections };
}

Synchronous

// Before
let result = false;
try {
  result = mayThrowErrorSomeday();
} catch (error) {
  console.log("Error catched", error);
}
console.log("result", result);

// After
const [err, result] = flatry(mayThrowErrorSomeday);
if (err) console.log("Error catched", err);
console.log("result", result);

Keywords

flat

FAQs

Package last updated on 13 Jan 2024

Did you know?

Socket

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.

Install

Related posts