fluentfixture
ContributionCode of Conduct
  • Fluent Fixture
  • PACKAGES
    • @fluentfixture/core
      • Everything Is A Factory
      • Streams
        • Stream
        • Boolean Stream
        • Number Stream
        • String Stream
        • Date Stream
        • Array Stream
        • Object Stream
      • Generators
      • Live Demo
    • @fluentfixture/format
      • Structure
      • Pipe Functions
        • Built-In Pipes
        • Custom Pipes
      • How To Use
      • Error Handling
      • Live Demo
  • 🫂Contribution
  • 🐦Follow me on Twitter :)
Powered by GitBook
On this page
  • single()
  • many()
  • array()
  • format()
  • optional()
  • nullable()
  • convert()
  • apply()
  • memo()
  • dump()
Edit on GitHub
  1. PACKAGES
  2. @fluentfixture/core
  3. Streams

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()

Parameter
Type
Default
Description

length

Integer

10

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()

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()

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()

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()

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()

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()

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()

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

Last updated 7 months ago

Returns an with the given length.

target length of the

Returns a that formats the produced input by using .

Returns a that may produce value or undefined.

Returns a that may produce value or null.

Returns a with maps the produced value to another type.

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

Memoizes and returns the same that always produces the same value.

Returns a with debugging points.

ArrayStream
StringStream
@fluentfixture/format
Stream
Stream
Stream
Stream
Stream
Stream
ArrayStream