diff --git a/README.rst b/README.rst index 7f42d4e..6579618 100644 --- a/README.rst +++ b/README.rst @@ -79,7 +79,7 @@ TODO list. - [ ] base - [o] faker.provider.address -- [ ] faker.provider.automotive +- [o] faker.provider.automotive - [o] faker.provider.bank - [ ] faker.provider.barcode - [ ] faker.provider.color @@ -87,7 +87,7 @@ TODO list. - [ ] faker.provider.credit_card - [o] faker.provider.currency - [ ] faker.provider.date_time -- [ ] faker.provider.file +- [o] faker.provider.file - [ ] faker.provider.geo - [ ] faker.provider.internet - [ ] faker.provider.isbn diff --git a/faker.nimble b/faker.nimble index 17a3c25..49d2c24 100644 --- a/faker.nimble +++ b/faker.nimble @@ -1,6 +1,6 @@ # Package -version = "0.10.0" +version = "0.11.0" author = "jiro4989" description = "faker is a Nim package that generates fake data for you." license = "MIT" @@ -30,7 +30,7 @@ proc addGeneratedText(lines: var seq[string]) = proc readPublicProcs(file: string): seq[string] = readFile(file) .split("\n") - .filterIt(it.startsWith("proc") and "*(f: Faker)" in it) + .filterIt(it.startsWith("proc") and "*(f: Faker" in it) proc readImplementedLocales(dir, provider: string): seq[string] = for path in listFiles(dir): @@ -61,7 +61,7 @@ proc genProviderIndexFile(provider: string) = lines.add(&" let f = newFaker()") let arg2 = if 1 < args.split(",").len: - args.replace("f: Faker, ", "") + args.replace("f: Faker, ", "").replace("(", "").replace(")", "") else: "" lines.add(&" echo f.{procName}({arg2})") diff --git a/src/faker/provider.nim b/src/faker/provider.nim index c363ef5..61ef04d 100644 --- a/src/faker/provider.nim +++ b/src/faker/provider.nim @@ -3,5 +3,5 @@ # See 'faker.nimble'. # # ----------------------------------------------- # -import provider/[address, automotive, bank, company, currency, job, person, phone_number, user_agent] -export address, automotive, bank, company, currency, job, person, phone_number, user_agent \ No newline at end of file +import provider/[address, automotive, bank, company, currency, file, job, person, phone_number, user_agent, word] +export address, automotive, bank, company, currency, file, job, person, phone_number, user_agent, word \ No newline at end of file diff --git a/src/faker/provider/file.nim b/src/faker/provider/file.nim new file mode 100644 index 0000000..0c1ee10 --- /dev/null +++ b/src/faker/provider/file.nim @@ -0,0 +1,68 @@ +# ----------------------------------------------- # +# This module was generated by 'nimble genProvs'. # +# See 'faker.nimble'. # +# ----------------------------------------------- # + +import ../base +import file/[file_en_US] +export base + +proc fileExtension*(f: Faker, category=""): string = + ## Generates random fileExtension. + runnableExamples: + let f = newFaker() + echo f.fileExtension(category="") + + case f.locale + of "en_US": file_en_US.fileExtension(f, category="") + else: file_en_US.fileExtension(f, category="") + +proc fileName*(f: Faker, category="", extension=""): string = + ## Generates random fileName. + runnableExamples: + let f = newFaker() + echo f.fileName(category="", extension="") + + case f.locale + of "en_US": file_en_US.fileName(f, category="", extension="") + else: file_en_US.fileName(f, category="", extension="") + +proc filePath*(f: Faker, depth=1, category="", extension=""): string = + ## Generates random filePath. + runnableExamples: + let f = newFaker() + echo f.filePath(depth=1, category="", extension="") + + case f.locale + of "en_US": file_en_US.filePath(f, depth=1, category="", extension="") + else: file_en_US.filePath(f, depth=1, category="", extension="") + +proc mimeType*(f: Faker, category=""): string = + ## Generates random mimeType. + runnableExamples: + let f = newFaker() + echo f.mimeType(category="") + + case f.locale + of "en_US": file_en_US.mimeType(f, category="") + else: file_en_US.mimeType(f, category="") + +proc unixDevice*(f: Faker, prefix=""): string = + ## Generates random unixDevice. + runnableExamples: + let f = newFaker() + echo f.unixDevice(prefix="") + + case f.locale + of "en_US": file_en_US.unixDevice(f, prefix="") + else: file_en_US.unixDevice(f, prefix="") + +proc unixPartition*(f: Faker, prefix=""): string = + ## Generates random unixPartition. + runnableExamples: + let f = newFaker() + echo f.unixPartition(prefix="") + + case f.locale + of "en_US": file_en_US.unixPartition(f, prefix="") + else: file_en_US.unixPartition(f, prefix="") diff --git a/src/faker/provider/file/file_en_US.nim b/src/faker/provider/file/file_en_US.nim new file mode 100644 index 0000000..2d077f5 --- /dev/null +++ b/src/faker/provider/file/file_en_US.nim @@ -0,0 +1,239 @@ +from strformat import `&` +from sequtils import toSeq +import tables + +include interfaces +import ../util +import ../word + +const + applicationMimeTypes = @[ + "application/atom+xml", # Atom feeds + "application/ecmascript", + # ECMAScript/JavaScript; Defined in RFC 4329 (equivalent to + # application/javascript but with stricter processing rules) + "application/EDI-X12", # EDI X12 data; Defined in RFC 1767 + "application/EDIFACT", # EDI EDIFACT data; Defined in RFC 1767 + "application/json", # JavaScript Object Notation JSON; Defined in RFC 4627 + # ECMAScript/JavaScript; Defined in RFC 4329 (equivalent to + # application/ecmascript + "application/javascript", + # but with looser processing rules) It is not accepted in IE 8 + # or earlier - text/javascript is accepted but it is defined as obsolete in RFC 4329. + # The "type" attribute of the