The Stream
is the base class of all other streams.
Returns the produced value.
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('a static value');
console.log(stream.single());
// 'a static value'
Returns the produced array.
Parameter | Type | Default | Description |
---|---|---|---|
length |
Integer |
10 |
target length |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('a static value');
console.log(stream.many(2));
// ['a static value', 'a static value']
Returns an ArrayStream
with the given length.
Parameter | Type | Default | Description |
---|---|---|---|
length |
Integer |
10 |
target length of the ArrayStream `` |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.array(3)
.map(i => i.toUpperCase());
console.log(stream.single());
// ['VALUE', 'VALUE', 'VALUE']
Returns a StringStream
that formats the produced input by using @fluentfixture/format.
Parameter | Type | Default | Description |
---|---|---|---|
template |
String |
format template |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.format('VALUE IS ${:upperCase()}');
console.log(stream.single());
// 'VALUE IS VALUE
Returns a Stream
that may produce value or undefined
.
Parameter | Type | Default | Description |
---|---|---|---|
percentage |
Float |
0.5 |
chance causing it to be defined |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.optional(0.3);
console.log(stream.single());
// undefined or 'value'
Returns a Stream
that may produce value or null
.
Parameter | Type | Default | Description |
---|---|---|---|
percentage |
Float |
0.5 |
chance causing it to be defined |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.nullable(0.3);
console.log(stream.single());
// null or 'value'
Returns a Stream
with maps the produced value to another type.
Parameter | Type | Default | Description |
---|---|---|---|
fn |
Function |
converter function |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.convert(i => i.length);
console.log(stream.single());
// 5
Returns a Stream
with maps the produced value to the same type.
Parameter | Type | Default | Description |
---|---|---|---|
fn |
Function |
apply function |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.apply(i => i.padStart(7, '*'));
console.log(stream.single());
// '**value'
Memoizes and returns the same Stream
that always produces the same value.
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.apply(i => i.padStart(7, '*'))
.memo();
console.log(stream.many(2));
// ['**value', '**value']
Returns a Stream
with debugging points.
Parameter | Type | Default | Description |
---|---|---|---|
fn |
Function |
debugging function |
import { val } from '@fluentfixture/core';
// val() returns a Stream with a static value.
const stream = val('value')
.dump(i => console.log(i))
.apply(i => i.padStart(7, '*'));
console.log(stream.many(2));
// 'values'
// ['**value', '**value']