In @fluentfixture, streams cannot be initialized directly. To take advantage of the stream's fluent interface, we can use generator functions.
Boolean
bool()
Returns a BooleanStream
that produces a boolean value.
Parameter | Type | Default | Description |
---|
| | | |
import { bool } from '@fluentfixture/core';
const stream = bool(0.9);
console.log(stream.many(5));
// [true, true, false, true, true]
truthy()
Returns a BooleanStream
that always produces true
.
import { truthy } from '@fluentfixture/core';
const stream = truthy();
console.log(stream.many(5));
// [true, true, true, true, true]
falsy()
Returns a BooleanStream
that always produces false
.
import { falsy } from '@fluentfixture/core';
const stream = falsy();
console.log(stream.many(5));
// [false, false, false, false, false]
Number
int()
Returns an NumberStream
that produces an integer value.
import { int } from '@fluentfixture/core';
const stream = int(1, 10)
console.log(stream.many(5));
// [7, 1, 6, 4, 9]
real()
Returns an NumberStream
that produces a float value.
import { real } from '@fluentfixture/core';
const stream = real(1, 10)
console.log(stream.many(5));
// [9.298, 3.86, 9.31, 8.38, 8.23]
num()
Returns an NumberStream
that always produces the given number.
import { num } from '@fluentfixture/core';
const stream = num(1881);
console.log(stream.many(5));
// [1881, 1881, 1881, 1881, 1881]
zero()
Returns an NumberStream
that always produces zero
.
import { zero } from '@fluentfixture/core';
const stream = zero();
console.log(stream.many(5));
// [0, 0, 0, 0, 0]
one()
Returns an NumberStream
that always produces one
.
import { one } from '@fluentfixture/core';
const stream = one();
console.log(stream.many(5));
// [1, 1, 1, 1, 1]
String
text()
Returns a StringStream
that always produces the given value.
import { text } from '@fluentfixture/core';
const stream = text('hello');
console.log(stream.single());
// 'hello'
str()
Returns a StringStream
that produces a string.
import { str } from '@fluentfixture/core';
const stream = str('abc', 10);
console.log(stream.single());
// 'abcca'
hex()
Returns a StringStream
that produces a hex string.
import { hex } from '@fluentfixture/core';
const stream = hex(10);
console.log(stream.single());
// '22c839cce0'
binary()
Returns a StringStream
that produces a binary string.
import { binary } from '@fluentfixture/core';
const stream = binary(10);
console.log(stream.single());
// '1100001110'
octal()
Returns a StringStream
that produces an octal string.
import { octal } from '@fluentfixture/core';
const stream = octal(10);
console.log(stream.single());
// '2025723760'
numeric()
Returns a StringStream
that produces a numeric string.
import { numeric } from '@fluentfixture/core';
const stream = numeric(10);
console.log(stream.single());
// '0843683947'
alphabetic()
Returns a StringStream
that produces an alphabetic string.
import { alphabetic } from '@fluentfixture/core';
const stream = alphabetic(10);
console.log(stream.single());
// 'KlmobUQbyt'
alphanumeric()
Returns a StringStream
that produces an alphanumeric string.
import { alphanumeric } from '@fluentfixture/core';
const stream = alphanumeric(10);
console.log(stream.single());
// 'iZvY8UtXxh'
Date
date()
Returns a DateStream
that produces a date.
import { date } from '@fluentfixture/core';
const stream = date();
console.log(stream.single());
// Tue Sep 06 2022 11:10:26 GMT+0300 (GMT+03:00)
now()
Returns a DateStream
that produces the current date.
import { now } from '@fluentfixture/core';
const stream = now();
console.log(stream.single());
// Tue Sep 06 2022 11:10:26 GMT+0300 (GMT+03:00)
Object
obj()
Returns an ObjectStream
that produces an object.
import { int, obj, pick } from '@fluentfixture/core';
const stream = obj({
amount: int(1, 100),
currency: pick(['USD', 'EUR']),
});
console.log(stream.single());
// {amount: 59, currency: 'EUR'}
Utilities
nil()
Returns a Stream
that always produces null.
import { nil } from '@fluentfixture/core';
const stream = nil();
console.log(stream.single());
// null
undef()
Returns a Stream
that always produces undefined.
import { undef } from '@fluentfixture/core';
const stream = undef();
console.log(stream.single());
// null
val()
Returns a Stream
that always produces the given value.
import { val } from '@fluentfixture/core';
const stream = val(5);
console.log(stream.single());
// 5
from()
Returns a Stream
that produces the result of the given function.
import { from } from '@fluentfixture/core';
const stream = from(() => 5);
console.log(stream.single());
// 5
list()
Returns an ArrayStream
that produces that contains the given list.
import { list } from '@fluentfixture/core';
const stream = list([1, 2, 3])
.map(i => i * 2);
console.log(stream.single());
// [2, 4, 6]
pick()
Returns a Stream
that picks an item from the given list.
import { pick } from '@fluentfixture/core';
const stream = pick([1, 2, 3]);
console.log(stream.single());
// 3
sample()
Returns an ArrayStream
that takes items from the given list.
import { sample } from '@fluentfixture/core';
const stream = sample([1, 2, 3], 2);
console.log(stream.single());
// [2, 3]
shuffle()
Returns an ArrayStream
that shuffles the given list.
import { shuffle } from '@fluentfixture/core';
const stream = shuffle([1, 2, 3]);
console.log(stream.single());
// [2, 3, 1]