在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):datafaker-net/datafaker开源软件地址(OpenSource Url):https://github.com/datafaker-net/datafaker开源编程语言(OpenSource Language):Java 86.7%开源软件介绍(OpenSource Introduction):Data FakerThis library is a modern port of java-faker, built on Java 8, with up to date libraries and several newly added Fake Generators. This library generates fake data, similar to other fake data generators, such as:
It's useful when you're developing a new project and need some pretty data for showcase. UsageIn the pom.xml, add the following fragment to the <dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>1.4.0</version>
</dependency> For Gradle users, add the following to your build.gradle file. dependencies {
implementation 'net.datafaker:datafaker:1.4.0'
}
You can also use the snapshot version ( Get startedIn your Java code: Faker faker = new Faker();
String name = faker.name().fullName(); // Miss Samanta Schmidt
String firstName = faker.name().firstName(); // Emory
String lastName = faker.name().lastName(); // Barton
String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 449 Or in your Kotlin code: val faker = Faker()
val name = faker.name().fullName() // Miss Samanta Schmidt
val firstName = faker.name().firstName() // Emory
val lastName = faker.name().lastName() // Barton
val streetAddress = faker.address().streetAddress() // 60018 Sawayn Brooks Suite 449 ExpressionsFaker faker = new Faker();
faker.expression("#{letterify 'test????test'}"); // testqwastest
faker.expression("#{numerify '#test#'}"); // 3test5
faker.expression("#{templatify 'test','t','q','@'}"); // @esq
faker.expression("#{examplify 'test'}"); // ghjk
faker.expression("#{regexify '[a-z]{4,10}'}"); // wbevoa
faker.expression("#{options.option '23','2','5','$','%','*'}"); // *
faker.expression("#{date.birthday 'yy DDD hh:mm:ss'}"); // 61 327 08:11:45
faker.expression("#{csv '1','name_column','#{Name.first_name}','last_name_column','#{Name.last_name}'}");
// "name_column","last_name_column"
// "Sabrina","Kihn"
faker.expression("#{json 'person','#{json ''first_name'',''#{Name.first_name}'',''last_name'',''#{Name.last_name}''}','address','#{json ''country'',''#{Address.country}'',''city'',''#{Address.city}''}'}");
// {"person": {"first_name": "Barbie", "last_name": "Durgan"}, "address": {"country": "Albania", "city": "East Catarinahaven"}} also more examples at https://www.datafaker.net/documentation/expressions/ CollectionsFaker faker = new Faker();
List<String> names = faker.collection(
() -> faker.name().firstName(),
() -> faker.name().lastName())
.len(3, 5)
.generate();
System.out.println(names);
// [Skiles, O'Connell, Lorenzo, West] more examples about that at https://www.datafaker.net/documentation/collections/ File formatscsvString csv = Format.toCsv(faker.collection(faker::name).build())
.headers(() -> "first_name", () -> "last_name")
.columns(Name::firstName, Name::lastName)
.separator(" ; ")
.limit(2).build().get();
// "first_name" ; "last_name"
// "Kimberely" ; "Considine"
// "Mariela" ; "Krajcik" jsonFaker faker = new Faker();
String json = Format.toJson(
faker.collection(faker::name)
.maxLen(2)
.build())
.set("firstName", Name::firstName)
.set("lastName", Name::lastName)
.build()
.generate();
// [{"firstName": "Oleta", "lastName": "Toy"},
// {"firstName": "Gerard", "lastName": "Windler"}] More complex examples and other formats like YAML, XML could be found at https://www.datafaker.net/documentation/file-formats/ Custom providerAdd your own custom provider in your app following steps from https://www.datafaker.net/documentation/custom-providers/ Documentationhttps://www.datafaker.net/documentation/providers/ ContributionsSee CONTRIBUTING.md Providers
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论