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

node-select

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-select

Select is syntactic sugar to help maintain a functional approach to assigning to variables.

latest
Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

node-select

Select is syntactic sugar to help maintain a functional approach to assigning to variables. It lets you avoid reassigning, so you can keep things const-y, if you're into that sort of thing. 🤷🏽‍

Please don't look at the source code, as it's embarassingly small. This is a grower, not a shower, ok?

Usage

Lets say you have something like this.

  let o = null;
  if (someCondition) {
    o = someConstructorMaybe();
  } else if (someOtherCondition) {
    o = somethingElse;
  }

Maybe you, like me, don't really like the look of that snippet, and would prefer it if you could assign directly to o with a single statement, and keep it as a const. You could do something like this instead:

  const o = (() => {
    if (someCondition) {
      return someConstructorMaybe();
    } else if (someOtherCondition) {
      return somethingElse;
    } else {
      return null;
    }
  })();

Good old self-invocing function pattern. Well, if you're still not quite happy, you can use select. Like this:

  const o = select(criteriaObject, (criteria) => {
    if (criteria.someCondition) {
      return someConstructorMaybe();
    } else if (criteria.someOtherCondition) {
      return somethingElse;
    } else {
      return null;
    }
  });

Plans for world domination

In my future, ECMAScript will support this syntax:

  const o = select (criteriaObject) {
    if (this.someCondition) {
      return someConstructorMaybe();
    } else if (this.someOtherCondition) {
      return somethingElse;
    } else {
      return null;
    }
  }

One can always dream...

FAQs

Package last updated on 20 Oct 2017

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