How to use the json-schema-faker.formats function in json-schema-faker

To help you get started, weā€™ve selected a few json-schema-faker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / lib / utils / data_utils.js View on Github external
var date = moment();

    if(!schema.start) {
        schema.start = start
    }
    if(!schema.end) {
        schema.end = date
    }

    var someDate = gen.faker.date.between(schema.start, schema.end);

    //ex.   "2016-01-19T13:48:08.426-07:00"
    return moment(someDate).format(dateFormat);
});

jsf.formats('utcBetween', function(gen, schema){
    var start = moment(0);  //01 January, 1970 UTC
    var date = moment();

    if(!schema.start) {
        schema.start = start
    }
    if(!schema.end) {
        schema.end = date
    }

    var someDate = gen.faker.date.between(schema.start, schema.end);

    //ex.   "2016-01-19T20:48:08.426Z"  , compare to isoBetween, same dates
    return moment(someDate).toISOString();
});
github terascope / teraslice / lib / utils / data_utils.js View on Github external
'use strict';

var jsf = require('json-schema-faker');
var moment = require('moment');
var dateFormat = require('./elastic_utils').dateFormat;

jsf.formats('isoBetween', function(gen, schema){
    var start = moment(0);  //01 January, 1970 UTC
    var date = moment();

    if(!schema.start) {
        schema.start = start
    }
    if(!schema.end) {
        schema.end = date
    }

    var someDate = gen.faker.date.between(schema.start, schema.end);

    //ex.   "2016-01-19T13:48:08.426-07:00"
    return moment(someDate).format(dateFormat);
});
github terascope / teraslice / lib / utils / data_utils.js View on Github external
var date = moment();

    if(!schema.start) {
        schema.start = start
    }
    if(!schema.end) {
        schema.end = date
    }

    var someDate = gen.faker.date.between(schema.start, schema.end);

    //ex.   "2016-01-19T20:48:08.426Z"  , compare to isoBetween, same dates
    return moment(someDate).toISOString();
});

jsf.formats('utcDate', function(gen, schema){
    return new Date().toISOString()
});

jsf.formats('dateNow', function(gen, schema){
    return moment().format(dateFormat);
});

module.exports = {
    type: 'object',
    properties: {
        ip: {
            "type": "string",
            "faker": "internet.ip"
        },
        userAgent: {
            type: 'string',
github terascope / teraslice / lib / utils / data_utils.js View on Github external
}
    if(!schema.end) {
        schema.end = date
    }

    var someDate = gen.faker.date.between(schema.start, schema.end);

    //ex.   "2016-01-19T20:48:08.426Z"  , compare to isoBetween, same dates
    return moment(someDate).toISOString();
});

jsf.formats('utcDate', function(gen, schema){
    return new Date().toISOString()
});

jsf.formats('dateNow', function(gen, schema){
    return moment().format(dateFormat);
});

module.exports = {
    type: 'object',
    properties: {
        ip: {
            "type": "string",
            "faker": "internet.ip"
        },
        userAgent: {
            type: 'string',
            'faker': 'internet.userAgent'
        },
        url: {
            type: 'string',