Phony is fake data generate with cats library.
Using as a tool
#Generate 10 random names phony -l en -t "{{ contact.firstName }} {{ contact.lastName }}" -c 10
tee /tmp/tpl.txt <<- EOM INSERT INTO users (first_name, last_name, age) VALUES("{{ contact.firstName }}", "{{ contact.lastName }}", {{alphanumeric.number(18, 68)}}); SET @USER_ID = @@IDENTITY; {{#loop 10}} INSERT INTO login_history(user_id,ip, timestamp) VALUES(@USER_ID, "{{internet.ip}}", "{{calendar.unixTime}}"); {{#endloop}} {{#loop 20}} INSERT INTO user_locations(user_id, latitude, longitude, timestamp) VALUES(@USER_ID, "{{location.latitude}}", "{{location.longitude}}"); {{#endloop}} EOM phony -f /tmp/tpl.txt -c 10
Using as a library
To use Phony in an existing SBT project with Scala 2.12 and 2.13, add the following dependency to your build.sbt:
resolvers += "phony" at "https://dl.bintray.com/meskin/phony/"
libraryDependencies += "com.github.alirezameskin" %% "phony-core" % "0.4.3"
Examples
import phony.Phony import scala.util.Try import phony.instances.try_.languages.ENGLISH import phony.instances.try_._ val bio = Phony[Try].lorem.text println(bio)
import phony.Phony import phony.instances.either.languages.ENGLISH import phony.instances.either._ type EitherA[A] = Either[Throwable, A] val bio = Phony[EitherA].lorem.text println(bio)
Using with cats-effect
resolvers += "phony" at "https://dl.bintray.com/meskin/phony/"
libraryDependencies += "com.github.alirezameskin" %% "phony-cats-effect" % "0.4.3"
import cats.effect.IO import phony.Phony import phony.cats.effect.instances.io.languages.ENGLISH import phony.cats.effect.instances.io._ val bio = Phony[IO].lorem.text println(bio.unsafeRunSync())
Using with fs2
import cats.effect.IO import fs2._ import phony.Phony import phony.cats.effect.instances.io.languages.ENGLISH import phony.cats.effect.instances.io._ case class Contact(firstName :String, lastName : String, age:Int) val contact = for { firstName <- Phony[IO].contact.firstName lastName <- Phony[IO].contact.lastName age <- Phony[IO].alphanumeric.number(18, 68) } yield Contact(firstName, lastName, age) val stream = Stream.eval(contact) stream.repeat.take(10).map(println).compile.drain.unsafeRunSync
Generators
Alphanumeric
def char: F[Char] def boolean: F[Boolean] def float: F[Float] def number: F[Int] def number(max: Int) def number(min: Int, max: Int): F[Int] def custom(format: String) //format replace # with random number and replace ? with random character def hash: F[String] def hash(length: Int): F[String]
Calendar
def year: F[Int] def day: F[String] def month: F[String] def time24h: F[String] def time12h: F[String] def date: F[Date] def date(format: String = "yyyy-MM-dd"): F[Date] def iso8601:F[String] def timezone: F[String]
Contact
def firstName: F[String] def lastName: F[String] def prefix: F[String] def suffix: F[String] def fullName: F[String] def fullName(withPrefix: Boolean = false, withSuffix: Boolean = false): F[String] def username: F[String] def phone: F[String] def cellPhone: F[String]
Internet
def uuid: F[String] def email: F[String] def password: F[String] def domain: F[String] def hostname: F[String] def protocol: F[String] def url: F[String] def ip: F[String] def ipv6: F[String] def hashtag: F[String]
Lorem
def word: F[String] def words: F[List[String]] def words(length: Int): F[List[String]] def sentence: F[String] def text: F[String] def sentence(size: Int): F[String] def text(lines: Int): F[String]
Location
def latitude: F[String] def longitude: F[String] def country: F[phony.data.Country] def countryName: F[String] def countryCode: F[String] def postalCode: F[String]