Skip to content

Latest commit

 

History

History
187 lines (128 loc) · 4.58 KB

File metadata and controls

187 lines (128 loc) · 4.58 KB

🧡 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.

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

array()

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

format()

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

optional()

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'

nullable()

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'

convert()

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

apply()

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'

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.

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