Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding FakerDataProvider #31

Merged
merged 3 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions example/faker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ void main() {

// Generate random User Agent, with osName iOS
print(faker.internet.userAgent(osName: 'iOS'));

// Generate localized Farsi lorem text
var fakerFa = Faker(FakerDataProviderFa());
print(fakerFa.lorem.word());
print(fakerFa.lorem.sentence());
print(fakerFa.lorem.words(10).join(' '));
print(fakerFa.lorem.sentences(3).join(' '));

}
4 changes: 4 additions & 0 deletions lib/faker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export 'src/data/job/job_adj.dart';
export 'src/data/job/job_noun.dart';
export 'src/data/job/job_prefix.dart';
export 'src/data/sport/sport_names.dart';

export 'src/providers/base_providers.dart';
export 'src/providers/default_providers.dart';
export 'src/providers/fa_providers.dart';
File renamed without changes.
1,002 changes: 1,002 additions & 0 deletions lib/src/data/lorem/fa/sentences_fa.dart

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions lib/src/data/lorem/fa/words_fa.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
const words = [
'معایبی',
'دارد',
'روغن',
'شریعتی',
'زنده‌یاد',
'ادبی',
'درختان',
'دهان',
'بلوار',
'سوئیسی',
'اصلی',
'ارتفاع',
'متعددی',
'تضاد',
'مراکز',
'ماهی',
'واقع',
'استفاده',
'افزاری',
'تئاتر',
'رشت',
'حال',
'زبان',
'دستور',
'تواند',
'پایانه',
'رود',
'خاویار',
'صنعتی',
'غرب',
'روزانه',
'کوچک',
'برگزار',
'افزایش',
'صفتی',
'شتر',
'آنتی',
'اطلس',
'جنگل',
'این',
'بیشترین',
'شود',
'امنیت',
'سنجی',
'واکاه',
'دیگر',
'مسئله',
'اکوسیستم',
'می‌خواباندند',
'دارای',
'مَرث',
'مذهب',
'برنجکوبی',
'مارادونا',
'همچنین',
'ابوالفضل',
'مدرن',
'تحلیلی',
'نژادی',
'مطلب',
'خود',
'می‌شود',
'توجهی',
'بود',
'معتقد',
'فاقد',
'قحطی',
'گلوبوس',
'لحاظ',
'دهه',
'زمانی',
'محصولات',
'دشمنان',
'شمار',
'بومی',
'ساکنان',
'ایرانی',
'جزئی',
'تکلم',
'کاربردی',
'دیلمی',
'حمید',
'وجود',
'روستایی',
'صادق',
'مازندران',
'موقعیت',
'تعطیل',
'مفید',
'کرد',
'آلرژی',
'کمابيش',
'است',
'برای',
'علی',
'خانگی',
'نخستین',
'ویژگی‌های',
'مختلف',
'قبل',
'می‌کردند',
'داشتند',
'الهى',
'مایا',
'بعدها',
'باقی‌مانده',
'جنگ',
'نمی',
'همه',
'دلایلی',
'خبرگزاری',
'مناطق',
'داخل',
'شواهد',
'می‌کشیم',
'آورندگان',
'نيز',
'شده',
'عبارتند',
'سردار',
'بعد',
'اکولوژی',
'حروف',
'تغییر',
'چاشنی',
'اردبیلی',
'اوچمال',
'سیاه',
'منجر',
'بازرگانی',
'تاز',
'پیوند',
'اوت',
'بزرگترین',
'ایران',
'ثروتمند',
'تبرستان',
'معابد',
'ترکیبات',
'اقوام',
'قطار',
'کنید',
'کاهش',
'رفتارهای',
'عصر',
'خانواده',
'گونهٔ',
'آرامگاه',
'ایرانیکا',
'پایه',
'پناه',
'فتحعلی',
'روزنامه',
'سال',
'مزار',
'محدود',
'سلام',
'کارگاه',
'مربوط',
'بنده',
'موجز',
'جامعه',
'جوار',
'کسی',
'مجسمه',
'میراث',
'کمدی',
'پایان',
'مورد',
'قزوین',
'کاسهٔ',
'چاه',
'شهر',
'مستقیم',
'فتح',
'جعفر',
'مدخل‌ها',
'نمودن',
'نامی',
'انتخاب',
'ذکر',
'اسلام',
'مسافرین',
'مهم‌ترین',
'نمناک',
'آجر',
'پیشاکلمبی',
'مدارس',
'مشاهده',
'برجسته',
'بیرونش',
'روزنامه‌ای',
'داده',
'سلول',
'انگشت',
'حیسن',
'خاتمه',
'سپس',
'آن‌ها',
'واگرایی'
];
20 changes: 17 additions & 3 deletions lib/src/faker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:faker/src/date.dart';
import 'package:faker/src/lorem.dart';
import 'package:faker/src/providers/default_providers.dart';
import 'package:faker/src/providers/fa_providers.dart';

import 'address.dart';
import 'company.dart';
Expand All @@ -11,10 +13,11 @@ import 'image.dart';
import 'internet.dart';
import 'job.dart';
import 'person.dart';
import 'providers/base_providers.dart';
import 'random_generator.dart';
import 'sport.dart';

const Faker faker = Faker();
final Faker faker = Faker();

class Faker {
final Address address;
Expand All @@ -32,7 +35,7 @@ class Faker {
final Date date;
final RandomGenerator randomGenerator;

const Faker()
Faker([FakerDataProvider provider])
: address = const Address(),
conference = const Conference(),
company = const Company(),
Expand All @@ -42,9 +45,20 @@ class Faker {
image = const Image(),
internet = const Internet(),
job = const Job(),
lorem = const Lorem(),
lorem = Lorem(provider?.loremDataProvider ?? DefaultLoremDataProvider()),
person = const Person(),
sport = const Sport(),
date = const Date(),
randomGenerator = const RandomGenerator();
}

class FakerDataProvider {
final LoremDataProvider loremDataProvider;

FakerDataProvider({this.loremDataProvider});
}

class FakerDataProviderFa extends FakerDataProvider {
FakerDataProviderFa() : super(loremDataProvider: LoremDataProviderFa());
}

13 changes: 8 additions & 5 deletions lib/src/lorem.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'data/lorem/sentences.dart' as sentence_list;
import 'data/lorem/words.dart' as word_list;
import 'package:faker/src/providers/base_providers.dart';
import 'random_generator.dart';

class Lorem {
const Lorem();
final LoremDataProvider _provider;

const Lorem(this._provider);

/// Generates a word.
///
/// Example:
/// ```dart
/// faker.lorem.word();
/// ```
String word() => random.element(word_list.words);
String word() => random.element(_provider.wordsList());

/// Generates a list of random words. The number of words is determined
/// by the `numberOfWords` parameter.
Expand All @@ -30,7 +31,7 @@ class Lorem {
/// ```dart
/// faker.lorem.sentence();
/// ```
String sentence() => random.element(sentence_list.sentences);
String sentence() => random.element(_provider.sentencesList());

/// Generates a list of random sentences. The size of the list of determined
/// by the `numberOfSentences` parameter.
Expand All @@ -45,3 +46,5 @@ class Lorem {
.toList();
}
}


7 changes: 7 additions & 0 deletions lib/src/providers/base_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract class LoremDataProvider{
/// Provides a list of lorem ipsum words that can be used to create fake data
List<String> wordsList();

/// Provides a list of lorem ipsum sentences that can be used to create fake data
List<String> sentencesList();
}
12 changes: 12 additions & 0 deletions lib/src/providers/default_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'base_providers.dart';
import '../data/lorem/defaults/sentences.dart' as sentence_list;
import '../data/lorem/defaults/words.dart' as word_list;

class DefaultLoremDataProvider extends LoremDataProvider{
@override
List<String> sentencesList() => sentence_list.sentences;

@override
List<String> wordsList() => word_list.words;

}
12 changes: 12 additions & 0 deletions lib/src/providers/fa_providers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'base_providers.dart';
import '../data/lorem/fa/sentences_fa.dart' as sentence_list;
import '../data/lorem/fa/words_fa.dart' as word_list;

class LoremDataProviderFa extends LoremDataProvider{
@override
List<String> sentencesList() => sentence_list.sentences;

@override
List<String> wordsList() => word_list.words;

}