Gathering detailed insights and metrics for space-monad
Gathering detailed insights and metrics for space-monad
Gathering detailed insights and metrics for space-monad
Gathering detailed insights and metrics for space-monad
npm install space-monad
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
30 Stars
16 Commits
2 Forks
2 Watchers
13 Branches
1 Contributors
Updated on May 16, 2025
Latest Version
1.0.0
Package Id
space-monad@1.0.0
Unpacked Size
30.20 kB
Size
6.65 kB
File Count
11
NPM Version
6.14.8
Node Version
14.14.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
Option
and Result
monads for TypeScript.
Creates an Option from a value. If the value is null or undefined, it will create a None, else a Some.
1const some = Option(33) // some === Some(33) 2const none = Option(null) // none === None
If you already know the value is defined for sure (not nullable) or not, you can create a Some
or None
directly:
1const some = Some(33) // Some(null | undefined) wouldn't compile. 2const none = None
Creates a new Option holding the tuple of all the values contained in the passed array if they were all Some or non null/undefined values, else returns None
1const some = Option.all([ 2 Option(10), 3 20, 4 Option(5) 5]) 6// some === Some([10, 20, 5]) 7 8const none = Option.all([ 9 Option(10), 10 None, 11 Option(5), 12 null 13]) 14// none === None
Returns whether the passed instance in an Option, and refines its type
1import { Option, Some } from 'space-monad' 2Option.isOption(Some(33)) // true
The Option constant representing no value.
1import { None } from 'space-monad'
Maps the value contained in this Some, else returns None. Depending on the map function return value, a Some could be tranformed into a None, as a Some is guaranteed to never contain a null or undefined value.
1const some = Option(33).map(x => x * 2) 2// some === Some(66)
Maps the value contained in this Some to a new Option, else returns None.
1const some = Option(33).flatMap(_ => Option(44)) 2// some === Some(44)
If this Option is a Some and the predicate returns true, keep that Some. In all other cases, return None.
1const some = Option(33).filter(x => x > 32) 2// some === Some(33)
Applies the first function if this is a None, else applies the second function. Note: Since this method creates 2 functions everytime it runs, don't use in tight loops; use isDefined() instead.
1const count = Option(10).fold( 2 () => 100, // None 3 count => count * 10 // Some 4)
Transforms this option into an Array or either 1 or 0 element.
Returns this Option unless it's a None, in which case the provided alternative is returned.
1const some = Option(null).orElse(() => Option(33)) 2// some === Some(33)
Some
instances return their value, whereas None
always return undefined
.
This method never throws.
1const value = Some(33).get() 2// value === 33
Returns whether this Option has a defined value (i.e, it's a Some(value)) Note: this refines the type of the Option to be a Some so it's guaranteed its value is not null/undefined.
Returns this Option's value if it's a Some, else return the provided alternative
1const value = Option(undefined).getOrElse(33) 2 3// value === 33
Applies the given procedure to the option's value, if it is non empty.
1Option(33).forEach(x => console.log(x))
Returns whether this option is a Some that contain a specific value, using ===
1Option(30).contains(30) // true
Returns whether this option is a Some with a value satisfying the predicate.
1Option(30).exists(n => n > 10) // true
A Result
is the result of a computation that may fail. An Ok
represents a successful computation, while an Err
represent the error case.
Here's everything that can be imported to use Results:
1import { Result, Ok, Err } from 'space-monad' 2 3const ok = Ok(10) 4const err = Err('oops')
Returns whether this instance is a Result (either an Ok or a Err) and refines its type
1import { Result, Ok } from 'space-monad' 2 3Result.isResult(Ok(10)) // true
Creates a new Ok Result holding the tuple of all the values contained in the passed array if they were all Ok, else returns the first encountered Err.
1import { Result, Ok, Err } from 'space-monad' 2 3const result = Result.all([ 4 Ok(20), 5 Err('nooo'), 6 Ok(200), 7 Err('oops') 8]) // Err('nooo')
Returns whether this is an instance of Ok
1import { Result, Ok, Err } from 'space-monad' 2 3Ok(10).isOk() // true
Maps the value contained in this Result if it's an Ok, else propagates the Error.
1import { Result, Ok, Err } from 'space-monad' 2 3Ok(10).map(x => x * 2) // Ok(20) 4Err(10).map(x => x * 2) // Err(10)
Maps the Error contained in this Result if it's an Err, else propagates the Ok.
1import { Result, Ok, Err } from 'space-monad' 2 3Ok(10).mapError(x => x * 2) // Ok(10) 4Err(10).mapError(x => x * 2) // Err(20)
Maps the value contained in this Result with another Result if it's an Ok, else propagates the Error. Note: It is allowed to return a Result with a different Error type.
1import { Result, Ok, Err } from 'space-monad' 2 3Ok(10).flatMap(x => Ok(x * 2)) // Ok(20) 4Ok(10).flatMap(x => Err(x * 2)) // Err(20)
Applies the first function if this is an Err, else applies the second function. Note: Don't use in tight loops; use isOk() instead.
1import { Result, Ok, Err } from 'space-monad' 2 3Ok(10).fold( 4 err => console.error(err), 5 num => num * 2 6) // 20
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/16 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
26 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More