New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

early-return

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

early-return

Helper to facilitate early returns across function stack in JavaScript.

0.2.1
latest
Source
npm
Version published
Weekly downloads
2
-50%
Maintainers
0
Weekly downloads
 
Created
Source

early-return

early-return

Helper to facilitate early returns across function stack in JavaScript.

import { early, earlyReturn } from 'early-return'

function handler() {
    early(1, true) // Will return, value 1.
    early(2, false) // Will be skipped, no value.
    early(3) // Will return, value 3.
}

const value = earlyReturn(handler)

This plugin is especially useful when integrated directly into frameworks, so that the overhead of wrapping functions isn't necessary. The following example shows how it simplifies JSX components.

function MyComponent() {
    if (Store.loading) {
        return <p>Loading...</p>
    }
    if (Store.error) {
        return <p>Error!</p>
    }
    return <p>Hello World!</p>
}
function MyComponent() {
    early(<p>Loading...</p>, Store.loading)
    early(<p>Error!</p>, Store.error)
    return <p>Hello World!</p>
}

Most importantly early can also be called in nested methods forcing the execution of all earlier methods to stop as well.

FAQs

Package last updated on 06 Feb 2025

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