commit 4aeef9faeb0fca19283da48b555aa8b1f65e13c3 Author: Sven Slootweg Date: Tue Jun 18 21:54:35 2024 +0200 Initial version diff --git a/README.md b/README.md new file mode 100644 index 0000000..78d50ff --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# @promistream/no-value + +This module exports a symbol for representing a "no value" situation; it is used by various Promistream modules for cases where a callback provided to a stream may not always produce a value. + +Importantly, this symbol is __not__ a part of the Promistreams specification; it is a convenience for stream modules that allow specifying a custom callback (eg. `map`) and that need some way to represent an absence of a value, where a `null` or `undefined` would be too ambiguous (eg. because it would be a valid value). You should only use this symbol when a stream tells you that it supports it. + +## Why this is a stand-alone package + +This ensures that there is only ever one symbol in use for this purpose, regardless of how many different stream modules you are using, and at what versions. This package will likely never receive an update, and it internally has a mechanism to ensure that only one global symbol is ever used across the application; if you somehow have multiple versions of this package loaded, all of them will export an identical symbol. diff --git a/index.js b/index.js new file mode 100644 index 0000000..6091c1d --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +"use strict"; + +const NoValue = Symbol("NoValue"); + +if (global.__promistream_NoValue != null) { + module.exports = global.__promistream_NoValue; +} else { + global.__promistream_NoValue = NoValue; + module.exports = NoValue; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c60e79e --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "@promistream/no-value", + "version": "1.0.0", + "description": "Shared symbol for indicating within a stream that there is no value", + "repository": { + "url": "https://git.cryto.net/promistream/no-value.git" + }, + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ "promistream", "symbol" ], + "author": "Sven Slootweg ", + "license": "WTFPL OR CC0-1.0" +}