In , streams cannot be initialized directly. To take advantage of the stream's fluent interface, we can use generator functions.
Boolean
bool()
Returns a that produces a boolean value.
Parameter
Type
Default
Description
chance causing it to be true
import { bool } from '@fluentfixture/core';
const stream = bool(0.9);
console.log(stream.many(5));
// [true, true, false, true, true]
truthy()
Returns a that always produces true
.
import { truthy } from '@fluentfixture/core';
const stream = truthy();
console.log(stream.many(5));
// [true, true, true, true, true]
falsy()
import { falsy } from '@fluentfixture/core';
const stream = falsy();
console.log(stream.many(5));
// [false, false, false, false, false]
Number
int()
Parameter
Type
Default
Description
import { int } from '@fluentfixture/core';
const stream = int(1, 10)
console.log(stream.many(5));
// [7, 1, 6, 4, 9]
real()
Parameter
Type
Default
Description
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()
Parameter
Type
Default
Description
import { num } from '@fluentfixture/core';
const stream = num(1881);
console.log(stream.many(5));
// [1881, 1881, 1881, 1881, 1881]
zero()
import { zero } from '@fluentfixture/core';
const stream = zero();
console.log(stream.many(5));
// [0, 0, 0, 0, 0]
one()
import { one } from '@fluentfixture/core';
const stream = one();
console.log(stream.many(5));
// [1, 1, 1, 1, 1]
String
text()
Parameter
Type
Default
Description
import { text } from '@fluentfixture/core';
const stream = text('hello');
console.log(stream.single());
// 'hello'
str()
Parameter
Type
Default
Description
import { str } from '@fluentfixture/core';
const stream = str('abc', 10);
console.log(stream.single());
// 'abcca'
hex()
Parameter
Type
Default
Description
import { hex } from '@fluentfixture/core';
const stream = hex(10);
console.log(stream.single());
// '22c839cce0'
binary()
Parameter
Type
Default
Description
import { binary } from '@fluentfixture/core';
const stream = binary(10);
console.log(stream.single());
// '1100001110'
octal()
Parameter
Type
Default
Description
import { octal } from '@fluentfixture/core';
const stream = octal(10);
console.log(stream.single());
// '2025723760'
numeric()
Parameter
Type
Default
Description
import { numeric } from '@fluentfixture/core';
const stream = numeric(10);
console.log(stream.single());
// '0843683947'
alphabetic()
Parameter
Type
Default
Description
import { alphabetic } from '@fluentfixture/core';
const stream = alphabetic(10);
console.log(stream.single());
// 'KlmobUQbyt'
alphanumeric()
Parameter
Type
Default
Description
import { alphanumeric } from '@fluentfixture/core';
const stream = alphanumeric(10);
console.log(stream.single());
// 'iZvY8UtXxh'
Date
date()
Parameter
Type
Default
Description
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()
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()
Parameter
Type
Default
Description
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()
import { nil } from '@fluentfixture/core';
const stream = nil();
console.log(stream.single());
// null
undef()
import { undef } from '@fluentfixture/core';
const stream = undef();
console.log(stream.single());
// null
val()
Parameter
Type
Default
Description
import { val } from '@fluentfixture/core';
const stream = val(5);
console.log(stream.single());
// 5
from()
Parameter
Type
Default
Description
import { from } from '@fluentfixture/core';
const stream = from(() => 5);
console.log(stream.single());
// 5
list()
Parameter
Type
Default
Description
import { list } from '@fluentfixture/core';
const stream = list([1, 2, 3])
.map(i => i * 2);
console.log(stream.single());
// [2, 4, 6]
pick()
import { pick } from '@fluentfixture/core';
const stream = pick([1, 2, 3]);
console.log(stream.single());
// 3
sample()
Parameter
Type
Default
Description
import { sample } from '@fluentfixture/core';
const stream = sample([1, 2, 3], 2);
console.log(stream.single());
// [2, 3]
shuffle()
import { shuffle } from '@fluentfixture/core';
const stream = shuffle([1, 2, 3]);
console.log(stream.single());
// [2, 3, 1]