Code Monkey home page Code Monkey logo

fakerator's Introduction

fakerator NPM version

Random fake data generator with localization

Codacy Badge Build Status Coverage Status

Dependency Status devDependency Status Downloads

fakerator was inspired by and has used data definitions from Marak's faker.js library

If you like my work, please donate. Thank you!

Demo

JSFiddle test page

Tonic demo

Install

Bower

$ bower install fakerator

NodeJS

$ npm install fakerator

Manual

Download the package and use the dist/fakerator.js or the dist/fakerator.min.js file in your project.

Usage

Browser

<script src="https://rawgit.com/icebob/fakerator/master/dist/fakerator.js"></script>

<script>
  var fakerator = Fakerator();
  var name = fakerator.names.name();
  var user = fakerator.entity.user();
</script>

NodeJS

var Fakerator = require("fakerator");
var fakerator = Fakerator("de-DE");
var name = fakerator.names.name();
// Result: 'Dr. Marcus Drechsler'

Shortly

var fakerator = require("fakerator")("hu-HU");
var name = fakerator.names.name();
// Result: 'Fülöp Magdolna'

Or load a specific locale

var fakerator = require("fakerator/locales/de-DE")();
var name = fakerator.names.name();
// Result: 'Dr. Marcus Drechsler'

Seeding

The library uses the Mersenne Twister pseudorandom number generator, so set seed value, if you want to get a repeatable random sequence:

fakerator.seed(5567832);

Random

Generate random values or select a random element from array.

Function Description Sample result
fakerator.random.boolean() Generate a boolean value true
fakerator.random.boolean(likelihoodPercent) Generate a boolean value based a likelihood value. false
fakerator.random.number(max) Generate a number value between 0 and max value 87
fakerator.random.number(min, max) Generate a number value between min and max 54
fakerator.random.digit() Generate a digit (0..9) 5
fakerator.random.letter() Generate a letter (a..z) "h"
fakerator.random.arrayElement(array) Give a random element from the array
fakerator.random.objectElement(obj) Give a random { key: value } from the object
fakerator.random.masked(mask) Generate a masked string ( a - lowercase letter, A - uppercase letter, 9 - digit, * - letter or digit "aaa-AAA_999:*" -> "aqa-RPG_932:6"
fakerator.random.hex(length) Generate a hexadecimal number "7950a0b9"
fakerator.random.string(length) Generate a random string "dulgecbhrsa"

Localization

The library supports localizations. You can set the locale code in constructor.

Usage

  // Use default (English) localization
  var fakerator = Fakerator();
  console.log(fakerator.names.name());
  // Floyd Corkery
  // Use german
  var fakerator = Fakerator("de-DE");
  console.log(fakerator.names.name());
  // Hassan vom Kumbernuss
  // Use russian
  var fakerator = Fakerator("ru-RU");
  console.log(fakerator.names.name());
  // Альберт Валентинович Архипов

In production, you can load only a specific locale:

  // Use french
  var fakeratorFR = require("fakerator/locales/fr-FR")();
  console.log(fakeratorFR.names.name());
  // Dufour Camille

Available localizations:

Code Language/Country Usage Creator/Source
default English (default) Fakerator(); faker.js
cs-CZ Czech Fakerator("cs-CZ"); zpiman
de-DE German Fakerator("de-DE"); faker.js
en-AU English (Australia) Fakerator("en-AU"); faker.js
en-CA English (Canada) Fakerator("en-CA"); faker.js
es-ES Spanish Fakerator("es-ES"); faker.js
fr-FR French Fakerator("fr-FR"); faker.js
hu-HU Hungarian Fakerator("hu-HU"); Icebob
it-IT Italian Fakerator("it-IT"); faker.js
nb-NO Norwegian Fakerator("nb-NO"); faker.js
pl-PL Polish Fakerator("pl-PL"); faker.js
pt-BR Brazilian Portuguese Fakerator("pt-BR"); Filipe Forattini
ru-RU Russian Fakerator("ru-RU"); faker.js
sk-SK Slovakian Fakerator("sk-SK"); faker.js
sv-SE Swedish Fakerator("sv-SE"); faker.js

Custom locale

Please read this how to add a new locale

Generators

Use this functions to generate fake random data

Names

Function Description Sample result
fakerator.names.name() Generate a full name "Dr. Sheryl Gleichner"
fakerator.names.nameM() Generate a male full name (*) "Bruce Weber"
fakerator.names.nameF() Generate a female full name (*) "Juanita Daniel"
fakerator.names.firstName() Generate a first name "Marco"
fakerator.names.firstNameM() Generate a male first name (*) "Bruce"
fakerator.names.firstNameF() Generate a female first name (*) "Kelly"
fakerator.names.lastName() Generate a last name "Reilly"
fakerator.names.lastNameM() Generate a male last name (*) "Collier"
fakerator.names.lastNameF() Generate a female last name (*) "Moore"
fakerator.names.prefix() Generate a name prefix name "Mr."
fakerator.names.suffix() Generate a name suffix "MD"
(*) - if localization support

Address

Function Description Sample result
fakerator.address.country() Give a country name "Romania"
fakerator.address.countryCode() Give a country code "RO"
fakerator.address.countryAndCode() Give a country object { code: "RO", name: "Romania" }
fakerator.address.city() Generate a city name "Merlestad"
fakerator.address.street() Generate a street address "96214 Annette Radial Apt. 543"
fakerator.address.streetName() Generate a street name "Gabriel Islands"
fakerator.address.buildingNumber() Generate a building number "196"
fakerator.address.postCode() Generate a post code "54360-6405"
fakerator.address.geoLocation() Generate a geolocation { latitude: 40.4233, longitude: -131.9741 }
fakerator.address.altitude() Generate an altitude 1180

Phone

Function Description Sample result
fakerator.phone.number() Generate a phone number "(640) 552-0763"

Company

Function Description Sample result
fakerator.company.name() Generate a company name "Weber, Gleichner and Kertzmann Inc."
fakerator.company.suffix() Generate a company suffix "LLC"

Internet data

Function Description Sample result
fakerator.internet.userName() Generate a username "kelly.moore14"
fakerator.internet.userName(firstName, lastName) Generate a username based an existing name "johndoe19"
fakerator.internet.password(length) Generate a password
fakerator.internet.domain() Generate a domain name "merle-gleichner.net"
fakerator.internet.url() Generate an url "http://ella-parisian.com"
fakerator.internet.email() Generate an email address "[email protected]"
fakerator.internet.email(firstName, lastName) Generate an email address from an existing name "[email protected]"
fakerator.internet.image(width, height, category) Generate a lorem image "http://lorempixel.com/640/480"
fakerator.internet.mac() Generate a MAC address "65:a1:a6:18:94:0b"
fakerator.internet.ip() Generate an IP v4 address "69.45.112.94"
fakerator.internet.ipv6() Generate an IP v6 address "b2e9:4275:95a9:65a1:a618:940b:a6ce:adb6"
fakerator.internet.color() Generate a color "b76f49"
fakerator.internet.avatar() Give an avatar link (uifaces.com) Sample
fakerator.internet.gravatar() Generate a gravatar link Sample
fakerator.internet.gravatar(email) Generate a gravatar link from an email address Sample

Lorem

Function Description Sample result
fakerator.lorem.word() Give a lorem word "dolores"
fakerator.lorem.sentence() Generate a lorem sentence "Libero similique quam voluptas soluta."
fakerator.lorem.paragraph() Give a lorem paragraph "Ut velit enim vel. Unde aut sint possimus velit commodi numquam. Autem expedita dignissimos est qui consequatur et delectus. Et qui necessitatibus voluptas quam. Dicta temporibus animi optio tempora aperiam repudiandae beatae. Placeat quo voluptatibus neque repellendus dolorem."

Date & time

Function Description Sample result
fakerator.date.timezone() Give a timezone "Asia/Bangkok"
fakerator.date.past(years, refDate) Generate a date in the past Date
fakerator.date.future(years, refDate) Generate a date in the future Date
fakerator.date.between(from, to) Generate a date between two dates Date
fakerator.date.recent(days) Generate a date in recent few days Date
fakerator.date.age(min, max) Generate an age number 26
fakerator.date.month() Give a month name "September"
fakerator.date.weekday() Give a weekday name "Sunday"
fakerator.date.weekdayShort() Give a short weekday name "Fri"
fakerator.date.weekdayMin() Give a min weekday name "Su"

Miscellaneous

Function Description Sample result
fakerator.misc.uuid() Generate an UUID "e26717ad-1513-43c5-b7de-2849521fa195"

Entities

You can generate complex entities

User

fakerator.entity.user()

Result:

{
    "firstName": "Ashley",
    "lastName": "Kautzer",
    "userName": "ashley38",
    "password": "yuzasimima",
    "email": "[email protected]",
    "phone": "1-485-841-6009",
    "dob": "1939-11-22T01:15:16.735Z",
    "website": "http://natalie-walker.info",
    "ip": "202.26.104.4",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/jakemoore/128.jpg",
    "gravatar": "https://www.gravatar.com/avatar/7875d665c96e5e388aa4074697cab0a0",
    "address": {
        "country": "Northern Mariana Islands",
        "countryCode": "MP",
        "state": "Michigan",
        "city": "New Jamie",
        "street": "1730 Abbott Views Apt. 460",
        "zip": "77988",
        "geo": {
            "latitude": -41.5878,
            "longitude": 34.266400000000004
        }
    },
    "status": false
}

You can set genre of user with first parameter.

// F - female, M - male
fakerator.entity.user("F");

Address

fakerator.entity.address()

Result:

{
    "country": "Bulgaria",
    "countryCode": "BG",
    "state": "Indiana",
    "city": "North Michele",
    "street": "06169 Beer Villages Suite 302",
    "zip": "20896",
    "geo": {
        "latitude": -9.275499999999994,
        "longitude": 92.53280000000001
    }
}

Company

fakerator.entity.company()

Result:

{
    "name": "Cormier, Murphy and Turcotte Ltd.",
    "email": "[email protected]",
    "phone": "044.708.8876 x834",
    "website": "https://olgabeatty.info",
    "ip": "54.65.201.35",
    "address": {
        "country": "Caribbean Netherlands",
        "countryCode": "BQ",
        "state": "Kansas",
        "city": "East Ronnie",
        "street": "81019 Cormier Mall",
        "zip": "11474-0882",
        "geo": {
            "latitude": 1.6444000000000045,
            "longitude": 107.97910000000002
        }
    }
}

Blog post

fakerator.entity.post()

Result:

{
    "title": "Esse excepturi eum id ab aut dolore veritatis et.",
    "keywords": [
        "commodi",
        "odio",
        "sit"
    ],
    "created": "2016-05-25T18:19:46.283Z",
    "content": "Mollitia officiis quam nulla veritatis omnis eius enim quis. Dolorem est reiciendis adipisci. Laboriosam enim saepe sunt nisi. Autem tempora ullam non laborum. Qui dolorem fugiat amet. Eius consectetur ea et minus ipsam et qui unde doloremque.\r\nNihil minima aut. Voluptatibus neque at nulla ut expedita laboriosam. Veniam natus voluptates nulla voluptas impedit cumque qui nihil.\r\nMinus quos in autem facere dolorem quidem rem rerum. Animi quo eaque debitis nam non earum molestiae. Maxime vitae exercitationem doloremque."
}

Times

You can generate array of items with times and utimes (unique) functions. First parameter is the generator function. Second is the length of array.

You can pass further parameters, they will be passed to the generator function.

Usage

// Generate 3 names
fakerator.times(fakerator.names.name, 3);
// [ "Ross Hansen", "Thomas Pfeffer", "Alexis Hauck I" ]

// Generate 5 username with populate where first name must be 'John'
fakerator.times(fakerator.populate, 5, "#{internet.userName}", "John");
// [ 'john.langosh8341', 'john12', 'john.howe5075', 'john_jerde', 'john.grant9923' ]

// Generate 5 number from 1 to 10
fakerator.times(fakerator.random.number, 5, 1, 10);
// [ 10, 8, 1, 8, 5 ]
// Note: 8 is twice!

// Generator 5 UNIQUE number from 1 to 10
fakerator.utimes(fakerator.random.number, 5, 1, 10);
// [ 10, 2, 9, 6, 1 ]
// Note: every number is unique!

Templates

You can also generate fake data with templates:

fakerator.populate("#{names.name}")
// Ross Hansen
fakerator.populate("#{address.street}")
// 0662 Ferry Drive
fakerator.populate("Hi, my name is #{names.name}. I was born in #{address.city}, #{address.country}. I am #{date.age} years old.")
// Hi, my name is Mrs. Rufus Shanahan. I was born in Hilpertton, Denmark. I am 44 years old.

Replace symbols

The populate replace # symbol to a random number and ? symbol to a random letter.

fakerator.populate("#{names.firstName}-###-???")
// Mandy-802-oqs

TODO

Contribution

Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.

License

fakerator is available under the MIT license.

Contact

Copyright (C) 2021 Icebob

@icebob @icebob

fakerator's People

Contributors

avin avatar centrual avatar depfu[bot] avatar greenkeeperio-bot avatar icebob avatar nicolapalavecino avatar pgte avatar riderx avatar tablackmore avatar tombyrer avatar tylormayfield avatar worldspawn-web avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fakerator's Issues

Readme example not calling constructor with new?

<script src="https://rawgit.com/icebob/fakerator/master/dist/fakerator.js"></script>

<script>
  //no new?
  var fakerator = Fakerator();
  var name = fakerator.names.name();
  var user = fakerator.entity.user();
</script>

The node example uses new. Is the usage actually different?

Seed has to be a number but type definitions force to string

Hi,

there is an error in the fakerator.d.ts:

seed(newSeed?: string);

this should be

seed(newSeed: number);

because the code wants a number and it is mandatory:

.../fakerator.js:4661
if (typeof S != 'number') throw new Error("seed(S) must take numeric argument; is " + (typeof S === 'undefined' ? 'undefined' : _typeof(S)));
                                  ^
Error: seed(S) must take numeric argument; is string

i can provide you with a MR if you want. although it is a simple change ...

Typescript support

Hello,

Enjoying using your lib but i would rather have the methods typed instead of having to always refer to the documentation 😊

is this something you are considering in the future?

Wrong country code and name generated

Code
let Faker = require("fakerator"); let faker = Faker("en-AU"); console.log( faker.entity.address());

Output
{
country: 'Aruba',
countryCode: 'AW',
state: 'Victoria',
city: 'South Owen',
street: '3552 Joseph Branch Apt. 535',
zip: '6115',
geo: { latitude: 80.2022, longitude: 17.571499999999986 }
}

I have chosen to generate random data for Australia. When generating the address, only the state name is Australian.

Typescript Declarations

Hello.

I created typescript declarations for this project. It is not fully documented. You can complete if you want. I put all functions with parameters I can find.

Here is the fakerator.d.ts file:

declare module 'fakerator' {

  export interface IRandomStringOptions {
    min?: number,
    max?: number
  }

  export type ITimesOptions = IRandomStringOptions;

  export interface ICountryAndCode {
    code: string,
    name: string
  }

  export interface ILatitudeAndLongitude {
    latitude: number,
    longitude: number
  }

  export enum LoremPixelCategories {
    Abstract = 'abstract',
    Animals = 'animals',
    Business = 'business',
    Cats = 'cats',
    City = 'city',
    Food = 'food',
    Nightlife = 'nightlife',
    Fashion = 'fashion',
    People = 'people',
    Nature = 'nature',
    Sports = 'sports',
    Technics = 'technics',
    Transport = 'transport',
    Technics = 'flickr',
    ColorImage = 'color',
    GrayImage = 'gray'
  }

  export interface IUser {
    "firstName": string,
    "lastName": string,
    "userName": string,
    "password": string,
    "email": string,
    "phone": string,
    "dob": string,
    "website": string,
    "ip": string,
    "avatar": string,
    "gravatar": string,
    "address": IAddress,
    "status": boolean
  }

  export interface ICompany {
    "name": string,
    "email": string,
    "phone": string,
    "website": string,
    "ip": string,
    "address": IAddress
  }

  export interface IAddress {
    "country": string,
    "countryCode": string,
    "state": string,
    "city": string,
    "street": string,
    "zip": string,
    "geo": ILatitudeAndLongitude
  }

  export interface IPost {
    "title": string,
    "keywords": Array<string>,
    "created": string,
    "content": string
  }

  class fakeratorRandom {
    /**
     * It starts from 0
     * Sample: 0
     * @param max Max number function will select
     * @returns number
     */
    number(max: number): number;

    /**
     * Random number selection between min and max. Min and max values are included.
     * Sample: 0
     * @param min Min number function will select
     * @param max Max number function will select
     * @returns number
     */
    number(min: number, max: number): number;

    /**
     * Random number selection between min and max. Min and max values are included.
     * Sample: 45.2
     * @param min Min number function will select
     * @param max Max number function will select
     * @param precision Can generate floating number if you define this parameter. Note: Do not use 0
     * @returns number
     */
    number(min: number, max: number, precision: number = 1): number;


    /**
     * Random boolean value.
     * Sample: true
     * @returns boolean
     */
    boolean(): boolean;

    /**
     * Random boolean value if it below likelyhood
     * Sample: true
     * @param likelyhood Returns true if selected random value between 0 and 100 below this parameter.
     * @returns boolean
     */
    boolean(likelyhood: number = 50): boolean;


    /**
     * Random 9 character string
     * Sample:
     * @returns string
     */
    digit(): string;


    /**
     * Random hexedemical string
     * @returns string
     */
    hex(): string;

    /**
     * Random hexedemical string
     * @param length Length of the generated string
     * @returns string
     */
    hex(length: number = 1): string;

    /**
     * Just one letter.
     */
    letter(): string;

    string(): string;
    string(length: number): string;
    string(options: IRandomStringOptions): string;

    arrayElement<T>(array: Array<T>): T;

    objectElement<returnType>(object: object): returnType;

    masked(format: string): string;
  }

  class fakeratorNames {
    /**
     * Dr. Sheryl Gleichner
     */
    name(): string;

    /**
     * Bruce Weber
     */
    nameM(): string;

    /**
     * Juanita Daniel
     */
    nameF(): string;

    /**
     * Marco
     */
    firstName(): string;

    /**
     * Bruce
     */
    firstNameM(): string;

    /**
     * Kelly
     */
    firstNameF(): string;

    /**
     * Reilly
     */
    lastName(): string;

    /**
     * Collier
     */
    lastNameM(): string;

    /**
     * Moore
     */
    lastNameF(): string;

    /**
     * Mr.
     */
    prefix(): string;

    /**
     * MD
     */
    suffix(): string;
  }

  class fakeratorAddress {
    /**
     * Romania
     */
    country(): string;

    /**
     * RO
     */
    countryCode(): string;

    /**
     * { code: "RO", name: "Romania" }
     */
    countryAndCode(): ICountryAndCode;

    /**
     * Merlestad
     */
    city(): string;

    /**
     * 96214 Annette Radial Apt. 543
     */
    street(): string;

    /**
     * Gabriel Islands
     */
    streetName(): string;

    /**
     * 196
     */
    buildingNumber(): string;

    /**
     * 54360-6405
     */
    postCode(): string;

    /**
     * { latitude: 40.4233, longitude: -131.9741 }
     */
    geoLocation(): ILatitudeAndLongitude;

    /**
     * 1180
     */
    altitude(): number;
  }

  class fakeratorPhone {
    /**
     * (640) 552-0763
     */
    number(): string;
  }

  class fakeratorCompany {
    /**
     * Weber, Gleichner and Kertzmann Inc.
     */
    name(): string;

    /**
     * LLC
     */
    suffix(): string;
  }

  class fakeratorInternet {
    /**
     * kelly.moore14
     */
    userName(): string;

    /**
     * Generate a username based an existing name
     * Sample: johndoe19
     * @param firstName First name
     * @param lastName Last Name
     */
    userName(firstName: string, lastName: string): string;

    /**
     * Generates a password
     */
    password(): string;

    /**
     * Generates a password
     */
    password(length: number): string;

    password(length: number, memorable: boolean): string;

    password(length: number, memorable: boolean, pattern: string): string;

    password(length: number, memorable: boolean, pattern: string, prefix: string): string;

    /**
     * merle-gleichner.net
     */
    domain(): string;

    /**
     * http://ella-parisian.com
     */
    url(): string;

    url(isHttps: boolean): string;

    url(isHttps: boolean, hasWWW: boolean): string;

    /**
     * [email protected]
     */
    email(): string;

    /**
     * Generate an email address from an existing name
     * Sample: [email protected]
     * @param firstName First name
     * @param lastName Last name
     */
    email(firstName: string, lastName: string): string;

    email(firstName: string, lastName: string, domain: string): string;


    /**
     * http://lorempixel.com/640/480
     */
    image(): string;

    /**
     * http://lorempixel.com/640/480
     */
    image(width: number, height: number): string;

    /**
     * http://lorempixel.com/640/480/sports
     */
    image(width: number, height: number, category: LoremPixelCategories): string;


    /**
     * 65:a1:a6:18:94:0b
     */
    mac(): string;


    /**
     * 69.45.112.94
     */
    ip(): string;


    /**
     * b2e9:4275:95a9:65a1:a618:940b:a6ce:adb6
     */
    ipv6(): string;


    /**
     * Generates a hexedemical color string
     * b76f49
     */
    color(): string;

    /**
     * Give an avatar link (uifaces.com)
     * https://s3.amazonaws.com/uifaces/faces/twitter/snowwrite/128.jpg
     */
    avatar(): string;


    /**
     * Generate a gravatar link
     * https://www.gravatar.com/avatar/a91004b566f80271f0a3577f71d43cd4
     */
    gravatar(): string;

    /**
     * Generate a gravatar link from an email address
     * https://www.gravatar.com/avatar/a91004b566f80271f0a3577f71d43cd4
     */
    gravatar(email: string): string;
  }

  class fakeratorLorem {
    /**
     * lorem
     */
    word(): string;

    /**
     * Libero similique quam voluptas soluta.
     */
    sentence(): string;

    /**
     * Ut velit enim vel. Unde aut sint possimus velit commodi numquam. Autem expedita dignissimos est qui consequatur et delectus. Et qui necessitatibus voluptas quam. Dicta temporibus animi optio tempora aperiam repudiandae beatae. Placeat quo voluptatibus neque repellendus dolorem.
     */
    paragraph(): string;
  }

  class fakeratorDate {
    /**
     * Asia/Bangkok
     */
    timezone(): string;

    past(years: number, refDate: Date): Date;

    future(years: number, refDate: Date): Date;

    between(from: Date, to: Date): Date;

    recent(days): Date;

    age(min: number, max: number): number;

    month(): string;

    weekday(): string;

    weekdayShort(): string;

    weekdayMin(): string;
  }

  class fakeratorMisc {
    uuid(): string;
  }

  class fakeratorEntity {
    user(): IUser;

    user(sex: 'M' | 'F'): IUser;

    address(): IAddress;

    company(): ICompany;

    post(): IPost;
  }

  class fakerator {
    constructor(localeID: string = 'default');

    seed(newSeed: string = 'default');

    capitalize(textWillBeCapitalized: string): string;

    slugify(textWillBeSlugified: string): string;

    replaceSymbols(format: string): string;
    replaceSymbols(format: string, numberSymbol: string = "#", alphaSymbol: string = "\\?"): string;

    shuffle(textWillBeShuffled: string): string;
    shuffle<T>(arrayWillBeShuffled: Array<T>): Array<T>;

    populate(format: string, ...args: Array<any>): string;

    times(functionWillRepeat: Function, nTimes: number, ...args: Array<any>): Array<any>;
    times(functionWillRepeat: Function, options: ITimesOptions, ...args: Array<any>): Array<any>;

    utimes(functionWillRepeat: Function, nTimes: number, ...args: Array<any>): Array<any>;
    utimes(functionWillRepeat: Function, options: ITimesOptions, ...args: Array<any>): Array<any>;

    generate(functionWillBeUsedForGeneration: Function, ...args: Array<any>): string;

    public random = new fakeratorRandom();

    public names = new fakeratorNames();

    public address = new fakeratorAddress();

    public phone = new fakeratorPhone();

    public company = new fakeratorCompany();

    public internet = new fakeratorInternet();

    public lorem = new fakeratorLorem();

    public date = new fakeratorDate();

    public misc = new fakeratorMisc();

    public entity = new fakeratorEntity();
  }

  export default new fakerator();
}

Missing type declarations in dist folder

Hello,

I can see that a fakerator.d.ts file exists at the root of the project, but it is not bundled in dist folder and not referenced in package.json.
As a result, it is not usable in a typescript project.
Could you add it please?

Thank you.

TS types definitions

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

I needed my TS project to compile with your project and also saw you have two issues related to the TS types definition here and here. With the proposed changes TS >=4.1.2 compiles well for my project. I will be creating a PR for this if you like.

Here is the diff that solved my problem:

diff --git a/node_modules/fakerator/dist/fakerator.d.ts b/node_modules/fakerator/dist/fakerator.d.ts
index 5e35995..c2710fa 100644
--- a/node_modules/fakerator/dist/fakerator.d.ts
+++ b/node_modules/fakerator/dist/fakerator.d.ts
@@ -31,7 +31,6 @@ declare module 'fakerator' {
         Sports = 'sports',
         Technics = 'technics',
         Transport = 'transport',
-        Technics = 'flickr',
         ColorImage = 'color',
         GrayImage = 'gray'
     }
@@ -104,7 +103,7 @@ declare module 'fakerator' {
          * @param precision Can generate floating number if you define this parameter. Note: Do not use 0
          * @returns number
          */
-        number(min: number, max: number, precision: number = 1): number;
+        number(min: number, max: number, precision: number): number;
     
     
         /**
@@ -120,7 +119,7 @@ declare module 'fakerator' {
          * @param likelyhood Returns true if selected random value between 0 and 100 below this parameter.
          * @returns boolean
          */
-        boolean(likelyhood: number = 50): boolean;
+        boolean(likelyhood: number): boolean;
     
     
         /**
@@ -142,7 +141,7 @@ declare module 'fakerator' {
          * @param length Length of the generated string
          * @returns string
          */
-        hex(length: number = 1): string;
+        hex(length: number): string;
     
         /**
          * Just one letter.
@@ -466,16 +465,16 @@ declare module 'fakerator' {
         post(): Post;
     }
     class Fakerator {
-        constructor(localeID: string = 'default');
+        constructor(localeID: string);
     
-        seed(newSeed: string = 'default');
+        seed(newSeed: string);
     
         capitalize(textWillBeCapitalized: string): string;
     
         slugify(textWillBeSlugified: string): string;
     
         replaceSymbols(format: string): string;
-        replaceSymbols(format: string, numberSymbol: string = "#", alphaSymbol: string = "\\?"): string;
+        replaceSymbols(format: string, numberSymbol: string, alphaSymbol: string): string;
     
         shuffle(textWillBeShuffled: string): string;
         shuffle<T>(arrayWillBeShuffled: Array<T>): Array<T>;
@@ -483,32 +482,33 @@ declare module 'fakerator' {
         populate(format: string, ...args: Array<any>): string;
     
         times(functionWillRepeat: Function, nTimes: number, ...args: Array<any>): Array<any>;
-        times(functionWillRepeat: Function, options: ITimesOptions, ...args: Array<any>): Array<any>;
+        times(functionWillRepeat: Function, options: TimesOptions, ...args: Array<any>): Array<any>;
     
         utimes(functionWillRepeat: Function, nTimes: number, ...args: Array<any>): Array<any>;
-        utimes(functionWillRepeat: Function, options: ITimesOptions, ...args: Array<any>): Array<any>;
+        utimes(functionWillRepeat: Function, options: TimesOptions, ...args: Array<any>): Array<any>;
     
         generate(functionWillBeUsedForGeneration: Function, ...args: Array<any>): string;
     
-        public random = new FakeratorRandom();
+        public random: FakeratorRandom;
     
-        public names = new FakeratorNames();
+        public names: FakeratorNames;
     
-        public address = new FakeratorAddress();
+        public address: FakeratorAddress;
     
-        public phone = new FakeratorPhone();
+        public phone: FakeratorPhone;
     
-        public company = new FakeratorCompany();
+        public company: FakeratorCompany;
     
-        public internet = new FakeratorInternet();
+        public internet: FakeratorInternet;
     
-        public lorem = new FakeratorLorem();
+        public lorem: FakeratorLorem;
     
-        public date = new FakeratorDate();
+        public date: FakeratorDate;
     
-        public misc = new FakeratorMisc();
+        public misc: FakeratorMisc;
     
-        public entity = new FakeratorEntity();
+        public entity: FakeratorEntity;
     }
-    export default (localeID = 'default') => new Fakerator(localeID);
+    const fn: (localeID: string) => Fakerator;
+    export default fn;
 }

This issue body was partially generated by patch-package.

Name limits

Excellent library! Is it possible to know approximately how many unique names are generated using fakerator.names.name()?

Ts lint

Hi,

When running tslint I'm getting errors on the d.ts file.

fakerator.d.ts(32,9): error TS2300: Duplicate identifier 'Technics'.
fakerator.d.ts(34,9): error TS2300: Duplicate identifier 'Technics'.
fakerator.d.ts(107,42): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(123,17): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(145,13): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(469,21): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(471,14): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(478,40): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(478,68): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
fakerator.d.ts(486,54): error TS2552: Cannot find name 'ITimesOptions'. Did you mean 'TimesOptions'?
fakerator.d.ts(489,55): error TS2552: Cannot find name 'ITimesOptions'. Did you mean 'TimesOptions'?
fakerator.d.ts(493,25): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(495,24): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(497,26): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(499,24): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(501,26): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(503,27): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(505,24): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(507,23): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(509,23): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(511,25): error TS1039: Initializers are not allowed in ambient contexts.
fakerator.d.ts(513,20): error TS2714: The expression of an export assignment must be an identifier or qualified name in an ambient context.

They seem like valid errors, you might want to check them out?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.