Code Monkey home page Code Monkey logo

faker's Introduction

faker

Build Status Coverage Status Faker on pub

A library for Dart that generates fake data.

faker is heavily inspired by the Python package faker, and the Ruby package ffaker.

Usage

A simple usage example:

import 'package:faker/faker.dart';

main() {
  var faker = new Faker();

  faker.internet.email();
  // [email protected]

  faker.internet.ipv6Address();
  // 2450:a5bf:7855:8ce9:3693:58db:50bf:a105

  faker.internet.userName();
  // fiona-ward

  faker.person.name();
  // Fiona Ward

  faker.person.prefix();
  // Mrs.

  faker.person.suffix();
  // Sr.
  
  faker.lorem.sentence();
  // Nec nam aliquam sem et
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Copyright

Copyright (c) 2015 Jesper Håkansson. See LICENSE for details. Copyright (c) 2013 Emmanuel Oga. Copyright (c) 2012 Daniele Faraglia. Copyright (c) 2007 Benjamin Curtis.

faker's People

Contributors

a-p-o avatar adem-emre avatar bassel avatar bobjackman avatar daemon3000 avatar deandreamatias avatar drager avatar drzwipercepcji avatar easazade avatar gabeaventh avatar georgepapas avatar guynoimark avatar igorgoncalves avatar ivanthz avatar jonaswre avatar kalebhermes avatar lsaudon avatar lucwollants avatar lukemoody01 avatar marvinissacul avatar mgonzalezc avatar quagstack avatar simplyfaisal avatar tehprofessor avatar wim-kaspar avatar yoiang 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

faker's Issues

Latitude and Longitude

It would be nice if Faker had support for creating Latitude and Longitude values.

Something to this effect should work, with faker being the current instance instead of the global.

It might sit under faker.address.latitude/faker.address.longitude or even faker.geospatial.latitude/faker.geospatial.longitude ?

double longitude() {
  return -180 + faker.randomGenerator.decimal() * 180 * 2;
}

double latitude() {
  return -90 + faker.randomGenerator.decimal() * 90 * 2;
}

Sugestion: faker Image

Based on Faker for PHP, the Image provider get images from lorem pixel or unplash to dowload images by categories.

Other alternative is place kitten but only for cats photos.

Exemple img URL:
Lorem Pixel: http://lorempixel.com/800/600/
Unplash: https://source.unsplash.com/1600x900/?nature,water

Faker PHP repository(use lorem pixel): https://github.com/fzaninotto/Faker/blob/master/src/Faker/Provider/Image.php
Faker JS repository (use unplash): https://github.com/Marak/faker.js/blob/master/lib/image.js

Generate DateTime in between 2 Dates

While using faker, I wanted to generate a DateTime that was in between 2 given dates (Not the years option).

I am creating this issue so I have something to put my PR against 😄

Faker generating invalid email addresses

It looks like faker.internet.email() is generating its result by calling domainName(), which in turn calls domainWord(), which in turn uses a random element from lastNames. Some of those last names have special characters that are illegal in email addresses (and domain names). e.g. teresa_buckridge@d'amore.info was the latest offender I generated.

I think it's good to have special characters in faker data to make sure our systems can properly handle them, but they need to be limited to places where special characters are legal to begin with.

Suggested Fix

lib/src/internet.dart
-  String domainWord() => random.element(lastnames).toLowerCase()
+  String domainWord() => random
+    .element(lastnames)
+    .toLowerCase()
+    .replaceAll(new RegExp(r'[^a-z0-9\-]'), ''); // -- remove illegal domain characters

Soon a release?

Hi @drager,

I wanted to know if a release is planned soon. I would like to use some features that are not available on the current release (ex: latitude).

Multiple fakers in a list

I am trying to create multiple users with lastName, firstName, email and so on...
I have a for loop and call faker each time, but it's creating the same user multiple times. I expected it to create multiple users with different names and so on...

Code snippet

for (int i = 0; i < 10; i++){
   var faker = Fake();
  
  users.add(
    Users(
      userid: faker.person.random.string(10),
      name: faker.person.firstName(),
      surname: faker.person.lastName(),
      phone: faker.phoneNumber.us(),
      email: faker.internet.email(),
      username: faker.internet.userName(),
    )
  );
}

Lorem.sentences() returning words instead of sentences

Hi!

I just saw that the Lorem.sentences method does not output sentences but words.

Original

List<String> sentences(numberOfSentences) {
    return Iterable<int>.generate(numberOfSentences).map((_) => word()).toList();
}

Expected

List<String> sentences(num numberOfSentences) {
    return Iterable<int>.generate(numberOfSentences).map((_) => sentence()).toList();
}

✌️

JWT Support

I'll submit a function to generate fake jwt. Today I use like internal function, but I think this is a useful function. What do you say?

There's just one thing, this function needs "crypto" package of dev.dart. Is this a problem?

Test Fails for restaurant

When I run the test/runner.dart, a test fails for restaurant names. Maybe the regex is not working correctly for 'Applebee’s International, Inc.' case.

Tests Log:

00:00 +18 -1: food should be able to generate restaurant [E]

  Expected: match '^([\w\s\'-])+$'
    Actual: 'Applebee’s International, Inc.'
  

  package:test_api/src/frontend/expect.dart 154:30              fail
  package:test_api/src/frontend/expect.dart 148:3               _expect
  package:test_api/src/frontend/expect.dart 60:3                expect
  test/specs/food.dart 9:7                                      main.<fn>.<fn>
  package:test_api/src/backend/declarer.dart 172:27             Declarer.test.<fn>.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1064:19                                  _CustomZone.registerBinaryCallback
  dart:async-patch/async_patch.dart 82:23                       _asyncErrorWrapperHelper
  package:test_api/src/backend/invoker.dart                     Invoker.waitForOutstandingCallbacks.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 1518:10                                  _runZoned
  dart:async/zone.dart 1465:12                                  runZoned
  package:test_api/src/backend/invoker.dart 243:5               Invoker.waitForOutstandingCallbacks
  package:test_api/src/backend/declarer.dart 170:33             Declarer.test.<fn>.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 1518:10                                  _runZoned
  dart:async/zone.dart 1465:12                                  runZoned
  package:test_api/src/backend/declarer.dart 169:13             Declarer.test.<fn>
  package:test_api/src/backend/invoker.dart 400:25              Invoker._onRun.<fn>.<fn>.<fn>.<fn>
  dart:async/future.dart 176:37                                 new Future.<fn>
  package:stack_trace/src/stack_zone_specification.dart 209:15  StackZoneSpecification._run
  package:stack_trace/src/stack_zone_specification.dart 119:48  StackZoneSpecification._registerCallback.<fn>
  dart:async/zone.dart 1122:38                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 925:7                                    _CustomZone.runGuarded
  dart:async/zone.dart 965:23                                   _CustomZone.bindCallbackGuarded.<fn>
  package:stack_trace/src/stack_zone_specification.dart 209:15  StackZoneSpecification._run
  package:stack_trace/src/stack_zone_specification.dart 119:48  StackZoneSpecification._registerCallback.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 949:23                                   _CustomZone.bindCallback.<fn>
  dart:async-patch/timer_patch.dart 23:15                       Timer._createTimer.<fn>
  dart:isolate-patch/timer_impl.dart 384:19                     _Timer._runTimers
  dart:isolate-patch/timer_impl.dart 418:5                      _Timer._handleMessage
  dart:isolate-patch/isolate_patch.dart 174:12                  _RawReceivePortImpl._handleMessage
  ===== asynchronous gap ===========================
  dart:async/zone.dart 1047:19                                  _CustomZone.registerCallback
  dart:async/zone.dart 964:22                                   _CustomZone.bindCallbackGuarded
  dart:async/timer.dart 54:45                                   new Timer
  dart:async/timer.dart 91:9                                    Timer.run
  dart:async/future.dart 174:11                                 new Future
  package:test_api/src/backend/invoker.dart 399:21              Invoker._onRun.<fn>.<fn>.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 1518:10                                  _runZoned
  dart:async/zone.dart 1465:12                                  runZoned
  package:test_api/src/backend/invoker.dart 387:9               Invoker._onRun.<fn>.<fn>
  package:test_api/src/backend/invoker.dart 438:15              Invoker._guardIfGuarded
  package:test_api/src/backend/invoker.dart 386:7               Invoker._onRun.<fn>
  package:stack_trace/src/chain.dart 101:24                     Chain.capture.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 1518:10                                  _runZoned
  dart:async/zone.dart 1465:12                                  runZoned
  package:stack_trace/src/chain.dart 99:12                      Chain.capture
  package:test_api/src/backend/invoker.dart 385:11              Invoker._onRun
  package:test_api/src/backend/live_test_controller.dart 197:5  LiveTestController._run
  package:test_api/src/backend/live_test_controller.dart 50:37  _LiveTest.run
  dart:async/future.dart 202:37                                 new Future.microtask.<fn>
  dart:async/zone.dart 1122:38                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 925:7                                    _CustomZone.runGuarded
  dart:async/zone.dart 965:23                                   _CustomZone.bindCallbackGuarded.<fn>
  dart:async/zone.dart 1126:13                                  _rootRun
  dart:async/zone.dart 1023:19                                  _CustomZone.run
  dart:async/zone.dart 925:7                                    _CustomZone.runGuarded
  dart:async/zone.dart 965:23                                   _CustomZone.bindCallbackGuarded.<fn>
  dart:async/schedule_microtask.dart 43:21                      _microtaskLoop
  dart:async/schedule_microtask.dart 52:5                       _startMicrotaskLoop
  dart:isolate-patch/timer_impl.dart 393:30                     _Timer._runTimers
  dart:isolate-patch/timer_impl.dart 418:5                      _Timer._handleMessage
  dart:isolate-patch/isolate_patch.dart 174:12                  _RawReceivePortImpl._handleMessage

Type `amount`

The faker.randomGenerator.amount(...) function returns a dynamic list. It would be better to have a List<T> here.

1.1.0 missing lorem & contents

Not sure whether something is odd with my env, but 1.1.0 pulled from pub, doesn't contain lorem or continents as per release notes.

Make it null safe

Flutter null-safe version major release in March 2021.

Make this package null-safe.

Sugestion: seed for random generator

Currently I don't see if there is a way to set a seed for the random generator. Something like in the python library 'faker' would be nice:

from faker import Faker
fake = Faker()
Faker.seed(4321)

Can't seem to find if the Random() function has a method to set it's seed?

Pass RandomGenerator in private in the specific generator.

RandomGenerator is public in all generator.
Is this what is intended?

So we can do as below, which seems illogical to me.
faker.color.random.decimal();

import 'data/colors/colors.dart';
import 'random_generator.dart';

class Color {
  const Color(this.random);

  final RandomGenerator random;

  /// Generates a color name.
  ///
  /// Example:
  /// ```dart
  ///   faker.colors.color();
  /// ```
  String color() => random.element(allColors);

  /// Generates a color name from a smaller list of colors.
  ///
  /// Example:
  /// ```dart
  ///   faker.colors.commonColor();
  /// ```
  String commonColor() => random.element(commonColors);
}

This will be a breaking change, but it is possible to modify it.

Faker sentence limit

it would be much better if faker.lorem.sentence(); took a parameter and generated sentences according to that .. for example

faker.lorem.sentence(2);
/*
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tristique lorem quis felis placerat sodales.
*/

add multi language support

it will be great to add support for other languages as well.
though I understand that there are alot of languages and comming up with a solution to this problem can be hard.

one problem is that some languages are RTL (like farsi aka persian) unlike english which is LTR. and developers who make their app RTL first will override the flutter app locale to show the entire app in RTL. because of this showing faker's fake text which are read from left to right (LTR) because they are in english in an app which loaded its entire widget tree in (RTL) is very confusing.

Suggestion: Fake user agent

It'd be great if there could be a internet.userAgent() feature, as this fits quite nicely when faking other things for network requests.

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.