# fully-storage-faker-api

> API generator fixtures implement of fully-storage package

Latest version **1.0.3** (published 2020-06-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install fully-storage-faker-api
pnpm add fully-storage-faker-api
yarn add fully-storage-faker-api
bun add fully-storage-faker-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-06-07 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | S.GABORIEAU |
| Maintainers | orivoir21 |
| Keywords | fully-storage, api, implement, apis, faker, fixtures, factory |

## Links

- npm: https://www.npmjs.com/package/fully-storage-faker-api
- npm.io page: https://npm.io/package/fully-storage-faker-api

## Dependencies (1)

- [faker](https://npm.io/package/faker.md) ^4.1.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [astro-better-toc](https://npm.io/package/astro-better-toc.md) — 0 weekly downloads
- [@crvouga/mockingbird-service-fcm](https://npm.io/package/@crvouga/mockingbird-service-fcm.md) — 0 weekly downloads
- [jabber](https://npm.io/package/jabber.md) — 0 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-06-07
- 1.0.2 — 2020-06-06
- 1.0.1 — 2020-06-05
- 1.0.0 — 2020-06-05

## README

# [fully-storage-faker-api](https://github.com/Orivoir/fully-storage-faker-api)

## This API is a *generator fixtures* based on [faker](https://npmjs.com/package/faker) and a implement for [fully-storage](https://npmjs.com/package/fully-storage) package

> **fully-storage** is a simple no-sql data store with an HTTP session manager implemented.

## fully-storage-faker-api is usable outside fully storage

- [installation](#installation)
- [usage](#usage)
- [options](#options)
- [usage with fully-storage](#usage-with-fully-storage)
- [extends faker.date.between](#extends-faker.date.between)

## installation

```bash

> npm install fully-storage-faker-api --save

> yarn add fully-storage-faker-api

```

## usage

```js

const GeneratorFixtures = require('fully-storage-faker-api');

const faker = new GeneratorFixtures({

    locality: 'en_US',
    onAppend: function( { state } ) {

        // state is fixtures object generated
        // you can push inside any storage here
        console.log( state );
    }
});


const numberObjectFixtures = 10;

faker.forEach( numberObjectFixtures, function( generator ) {

    const objectFixtures = {};

    // generator is a `faker` object
    // based on package https://npmjs.com/package/faker
    // you can generated factory data with this here

    objectFixtures.title = generator.lorem.words( 5 );

    objectFixtures.createAt = generator.date.between( 'now', '-90days' );

    // the object fixtures return is give to `onAppend` method
    // this is the object append inside your storage
    return objectFixtures;

} );

```

## options

From the `GeneratorFixtures` constructor or instance object you can define a *arbitrary* value for a `options`
attribute this data is transfert to your `onAppend` method

*e.g:*
```js

const GeneratorFixtures = require('fully-storage-faker-api');

const faker = new GeneratorFixtures({

    locality: 'en_US',
    onAppend: function( { state, options } ) {

        console.log( 'should push:', state, ' inside', options.table );
    }
});

// define a options object transfer to `onAppend` method
faker.options.table = "articles";

const numberObjectFixtures = 10;

faker.forEach( numberObjectFixtures, function( generator ) {

    const objectFixtures = {};

    objectFixtures.title = generator.lorem.words( 5 );

    objectFixtures.createAt = generator.date.between( 'now', '-90days' );

    return objectFixtures;

} );

```

# usage with fully-storage

[fully-storage](https://npmjs.com/package/fully-storage) implement this API,
and auto add `fixtures object` inside collection define by the `options` attribute


fully-storage should implement a code equal to below

```js

const GeneratorFixtures = require('fully-storage-faker-api');

const faker = new GeneratorFixtures({

    locality: "en_US",

    onAppend: ( {
        options,
        state
    } ) => {

        Storage.addDoc(
            options.collectionName,

            state,

            options.AUTO_SAVE_ID
        );
    }
});

```

User [fully-storage](https://npmjs.com/package/fully-storage) should access to this usage:

```js

const faker = fullyStorage.createFaker("en_US");

faker.options = {

    collectionName: "articles",

    AUTO_SAVE_ID: fullyStorage.AUTO_SAVE_ID
};

const numberArticlesFixtures = 10;

faker.forEach(  numberArticlesFixtures, function(generator) {

    const article = {};

    article.title = generator.lorem.words( 7 ) ;

    const sentenceCount = 3;
    const separator = ' ';

    articles.contentText = generator.lorem.sentences( sentenceCount , separator );

    articles.createAt = generate.date.between( 'now', '-15days' );

    return articles;
} );

```

## extends faker.date.between

[fully-storage-faker-api](https://github.com/Orivoir/fully-storage-faker-api) have extends the native method `faker.date.between`
for allow params time as string value.

with native code:

```js

const from = new Date(); // now


const oneHours = 1000 * 60 * 60;
const oneDay = onHours * 24;

const _15days = oneDay * 15; // timestamp MS 15days

const to = Date.now() - _15Days; // 'now' - '15days'

// random date between: now and now-15days
const randomDate = faker.date.between( from, new Date( to ) );

console.log( randomDate );

```

with extends:

```js

const randomDate = faker.date.between( 'now', '-15days' );

console.log( randomDate );

```

---
_Source: https://npm.io/package/fully-storage-faker-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
