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
  • Boolean
  • Number
  • String
  • Date
  • Object
  • Utilities
Edit on GitHub
  1. PACKAGES
  2. @fluentfixture/core

Generators

PreviousObject StreamNext@fluentfixture/format

Last updated 7 months ago

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

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]

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

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]

real()

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]

num()

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]

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

str

String

string

import { text } from '@fluentfixture/core';

const stream = text('hello');

console.log(stream.single());
// 'hello'

str()

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'

hex()

Parameter
Type
Default
Description

length

Integer

10

target length

import { hex } from '@fluentfixture/core';

const stream = hex(10);

console.log(stream.single());
// '22c839cce0'

binary()

Parameter
Type
Default
Description

length

Integer

10

target length

import { binary } from '@fluentfixture/core';

const stream = binary(10);

console.log(stream.single());
// '1100001110'

octal()

Parameter
Type
Default
Description

length

Integer

10

target length

import { octal } from '@fluentfixture/core';

const stream = octal(10);

console.log(stream.single());
// '2025723760'

numeric()

Parameter
Type
Default
Description

length

Integer

10

target length

import { numeric } from '@fluentfixture/core';

const stream = numeric(10);

console.log(stream.single());
// '0843683947'

alphabetic()

Parameter
Type
Default
Description

length

Integer

10

target length

import { alphabetic } from '@fluentfixture/core';

const stream = alphabetic(10);

console.log(stream.single());
// 'KlmobUQbyt'

alphanumeric()

Parameter
Type
Default
Description

length

Integer

10

target length

import { alphanumeric } from '@fluentfixture/core';

const stream = alphanumeric(10);

console.log(stream.single());
// 'iZvY8UtXxh'

Date

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)

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

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

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

value

Any

value

import { val } from '@fluentfixture/core';

const stream = val(5);

console.log(stream.single());
// 5

from()

Parameter
Type
Default
Description

fn

Function

function

import { from } from '@fluentfixture/core';

const stream = from(() => 5);

console.log(stream.single());
// 5

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]

pick()

import { pick } from '@fluentfixture/core';

const stream = pick([1, 2, 3]);

console.log(stream.single());
// 3

sample()

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]

shuffle()

import { shuffle } from '@fluentfixture/core';

const stream = shuffle([1, 2, 3]);

console.log(stream.single());
// [2, 3, 1]

Returns a that always produces false.

Returns an that produces an integer value.

Returns an that produces a float value.

Returns an that always produces the given number.

Returns an that always produces zero.

Returns an that always produces one.

Returns a that always produces the given value.

Returns a that produces a string.

Returns a that produces a hex string.

Returns a that produces a binary string.

Returns a that produces an octal string.

Returns a that produces a numeric string.

Returns a that produces an alphabetic string.

Returns a that produces an alphanumeric string.

Returns a that produces a date.

Returns a that produces the current date.

Returns an that produces an object.

Returns a that always produces null.

Returns a that always produces undefined.

Returns a that always produces the given value.

Returns a that produces the result of the given function.

Returns an that produces that contains the given list.

Returns a that picks an item from the given list.

Returns an that takes items from the given list.

Returns an that shuffles the given list.

@fluentfixture
BooleanStream
BooleanStream
BooleanStream
NumberStream
NumberStream
NumberStream
NumberStream
NumberStream
StringStream
StringStream
StringStream
StringStream
StringStream
StringStream
StringStream
StringStream
DateStream
DateStream
ObjectStream
Stream
Stream
Stream
Stream
ArrayStream
Stream
ArrayStream
ArrayStream