Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Created November 30, 2018 14:55
Show Gist options
  • Save friendlyanon/004be64732986f72ca140f2c4fe5c73c to your computer and use it in GitHub Desktop.
Save friendlyanon/004be64732986f72ca140f2c4fe5c73c to your computer and use it in GitHub Desktop.
"use strict";
class Optional {
constructor(value, isError) {
this._value = value;
this._ok = !isError;
}
[Symbol.toPrimitive](hint) {
switch (hint) {
case "number": return this._ok ? 1 : 0;
case "string": return this._ok ? "1" : "";
default: return this._ok;
}
}
get value() {
return this._value;
}
}
module.exports = Optional;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment