Stream

The Stream is the base class of all other streams.

single()

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'

many()

Returns the produced array.

ParameterTypeDefaultDescription

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']

array()

Returns an ArrayStream with the given length.

ParameterTypeDefaultDescription

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']

format()

Returns a StringStream that formats the produced input by using @fluentfixture/format.

ParameterTypeDefaultDescription

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

optional()

Returns a Stream that may produce value or undefined.

ParameterTypeDefaultDescription

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'

nullable()

Returns a Stream that may produce value or null.

ParameterTypeDefaultDescription

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'

convert()

Returns a Stream with maps the produced value to another type.

ParameterTypeDefaultDescription

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

apply()

Returns a Stream with maps the produced value to the same type.

ParameterTypeDefaultDescription

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'

memo()

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']

dump()

Returns a Stream with debugging points.

ParameterTypeDefaultDescription

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']

Last updated