npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fully-storage-faker-api

v1.0.3

Published

API generator fixtures implement of fully-storage package

Downloads

14

Readme

fully-storage-faker-api

This API is a generator fixtures based on faker and a implement for 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


> npm install fully-storage-faker-api --save

> yarn add fully-storage-faker-api

usage


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:


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 implement this API, and auto add fixtures object inside collection define by the options attribute

fully-storage should implement a code equal to below


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 should access to this usage:


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 have extends the native method faker.date.between for allow params time as string value.

with native code:


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:


const randomDate = faker.date.between( 'now', '-15days' );

console.log( randomDate );