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 = ; 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 ; 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 = ;
Plans for world domination
In my future, ECMAScript will support this syntax:
const o = { if thissomeCondition return ; else if thissomeOtherCondition return somethingElse; else return null; }
One can always dream...