In @fluentfixture, streams cannot be initialized directly. To take advantage of the stream's fluent interface, we can use generator functions.
Returns a BooleanStream that produces a boolean value.
| Parameter | Type | Default | Description |
|---|---|---|---|
percentage |
Float |
0.5 |
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]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]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]Returns an NumberStream that produces an integer value.
| Parameter | Type | Default | Description |
|---|---|---|---|
min |
Integer |
0 |
lower boundary |
max |
Integer |
1000 |
upper boundary |
import { int } from '@fluentfixture/core';
const stream = int(1, 10)
console.log(stream.many(5));
// [7, 1, 6, 4, 9]Returns an NumberStream that produces a float value.
| Parameter | Type | Default | Description |
|---|---|---|---|
min |
Float |
0 |
lower boundary |
max |
Float |
1000 |
upper boundary |
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]Returns an NumberStream that always produces the given number.
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
Number |
value |
import { num } from '@fluentfixture/core';
const stream = num(1881);
console.log(stream.many(5));
// [1881, 1881, 1881, 1881, 1881]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]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]Returns a StringStream that always produces the given value.
| Parameter | Type | Default | Description |
|---|---|---|---|
str |
String |
string |
import { text } from '@fluentfixture/core';
const stream = text('hello');
console.log(stream.single());
// 'hello'Returns a StringStream that produces a string.
| Parameter | Type | Default | Description |
|---|---|---|---|
charset |
String |
included characters | |
length |
Integer |
10 |
target length |
import { str } from '@fluentfixture/core';
const stream = str('abc', 10);
console.log(stream.single());
// 'abcca'Returns a StringStream that produces a hex string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { hex } from '@fluentfixture/core';
const stream = hex(10);
console.log(stream.single());
// '22c839cce0'Returns a StringStream that produces a binary string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { binary } from '@fluentfixture/core';
const stream = binary(10);
console.log(stream.single());
// '1100001110'Returns a StringStream that produces an octal string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { octal } from '@fluentfixture/core';
const stream = octal(10);
console.log(stream.single());
// '2025723760'Returns a StringStream that produces a numeric string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { numeric } from '@fluentfixture/core';
const stream = numeric(10);
console.log(stream.single());
// '0843683947'Returns a StringStream that produces an alphabetic string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { alphabetic } from '@fluentfixture/core';
const stream = alphabetic(10);
console.log(stream.single());
// 'KlmobUQbyt'Returns a StringStream that produces an alphanumeric string.
| Parameter | Type | Default | Description |
|---|---|---|---|
length |
Integer |
10 |
target length |
import { alphanumeric } from '@fluentfixture/core';
const stream = alphanumeric(10);
console.log(stream.single());
// 'iZvY8UtXxh'Returns a DateStream that produces a date.
| Parameter | Type | Default | Description |
|---|---|---|---|
min |
Date |
yesterday |
lower boundary |
max |
Date |
tomorrow |
upper boundary |
import { date } from '@fluentfixture/core';
const stream = date();
console.log(stream.single());
// Tue Sep 06 2022 11:10:26 GMT+0300 (GMT+03:00)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)Returns an ObjectStream that produces an object.
| Parameter | Type | Default | Description |
|---|---|---|---|
model |
Object |
object model |
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'}Returns a Stream that always produces null.
import { nil } from '@fluentfixture/core';
const stream = nil();
console.log(stream.single());
// nullReturns a Stream that always produces undefined.
import { undef } from '@fluentfixture/core';
const stream = undef();
console.log(stream.single());
// nullReturns a Stream that always produces the given value.
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
Any |
value |
import { val } from '@fluentfixture/core';
const stream = val(5);
console.log(stream.single());
// 5Returns a Stream that produces the result of the given function.
| Parameter | Type | Default | Description |
|---|---|---|---|
fn |
Function |
function |
import { from } from '@fluentfixture/core';
const stream = from(() => 5);
console.log(stream.single());
// 5Returns an ArrayStream that produces that contains the given list.
| Parameter | Type | Default | Description |
|---|---|---|---|
arr |
Array |
array |
import { list } from '@fluentfixture/core';
const stream = list([1, 2, 3])
.map(i => i * 2);
console.log(stream.single());
// [2, 4, 6]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());
// 3Returns an ArrayStream that takes items from the given list.
| Parameter | Type | Default | Description |
|---|---|---|---|
count |
Integer |
count |
import { sample } from '@fluentfixture/core';
const stream = sample([1, 2, 3], 2);
console.log(stream.single());
// [2, 3]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]