Skip to content

Commit

Permalink
gen rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Dec 20, 2023
1 parent 63955f6 commit dd56149
Show file tree
Hide file tree
Showing 65 changed files with 93,379 additions and 92,295 deletions.
9 changes: 9 additions & 0 deletions fakerjs2generator/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"authors": [
"burner"
],
"copyright": "Copyright © 2023, burner",
"description": "faker.js to D converter",
"license": "GPL3",
"name": "fakerjs2generator"
}
9 changes: 9 additions & 0 deletions fakerjs2generator/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import std.stdio;

import parser;
import defis;

void main() {
writeln("Edit source/app.d to start your project.");
Language en = parseLanguage("en");
}
277 changes: 277 additions & 0 deletions fakerjs2generator/source/defis.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
module defis;

import std.typecons : Nullable;

struct Mustache {
string str;
}

struct Number {
string num;
}

struct MustacheWeight {
Mustache value;
int weight;
}

struct MergeArray {
string[] arrayNames;
}

struct Airline {
string name;
string iataCode;
}

struct Airplane {
string name;
string iataTypeCode;
}

struct Airport {
string name;
string iataCode;
}

struct AirlineFolder {
Airline airline;
Airplane airplane;
Airport airport;
}

struct AnimalFolder {
string[] bear;
string[] bird;
string[] cat;
string[] cetacean;
string[] cow;
string[] crocodilia;
string[] dog;
string[] fish;
string[] horse;
string[] insect;
string[] lion;
string[] rabbit;
string[] rodent;
string[] snake;
}

struct AppFolder {
Mustache[] author;
string[] name;
Number[] version_;
}

struct Cell_PhoneFolder {
Number[] formats;
}

struct ColorFolder {
string[] human;
}

struct Product_Name {
string[] adjective;
string[] material;
string[] product;
}

struct CommerceFolder {
string[] departments;
string[] product_description;
Product_Name product_name;
}

struct CompanyFolder {
string[] adjective;
string[] buzz_adjective;
string[] buzz_noun;
string[] buzz_verb;
string[] descriptor;
Mustache[] name_pattern;
string[] noun;
string[] suffix;
}

struct DatabaseFolder {
string[] column;
}

struct DateMonth {
string[] wide;
string[] abbr;
}

struct DateWeekday {
string[] wide;
string[] abbr;
}

struct DateFolder {
DateMonth month;
DateWeekday weekday;
}

struct Credit_CardFolder {
Number[] american_express;
Number[] diners_club;
Number[] discover;
Number[] jcb;
Number[] maestro;
Number[] mastercard;
Number[] visa;
}

struct Currency {
string name;
string code;
string symbol;
}

struct FinanceFolder {
Credit_CardFolder credit_card;
string[] account_type;
Currency currency;
string[] transaction_type;
}

struct HackerFolder {
string[] adjective;
string[] ingverb;
string[] noun;
Mustache[] phrase;
string[] verb;
}

struct InternetFolder {
string[] domain_suffix;
string[] example_email;
string[] free_email;
}

struct LocationFolder {
Number[] building_number;
string[] city_name;
Mustache[] city_pattern;
string[] city_prefix;
string[] city_suffix;
string[] country;
string[] county;
string[] default_country;
string[] direction;
string[] direction_abbr;
Number[] postcode;
Number[] secondary_address;
string[] state;
string[] state_abbr;
Mustache[string] street_address;
string[] street_name;
Mustache[] street_pattern;
string[] street_suffix;
}

struct LoremFolder {
string[] words;
}

struct MusicFolder {
string[] genre;
string[] song_name;
}

struct Title {
string[] descriptor;
string[] level;
string[] job;
}

struct PersonFolder {
string[] bio_part;
Mustache[] bio_pattern;
string[] bio_supporter;
string[] female_first_name;
string[] female_middle_name;
string[] female_prefix;
string[] first_name;
string[] gender;
Mustache[] job_title_pattern;
string[] last_name;
MustacheWeight[] last_name_pattern;
string[] male_first_name;
string[] male_middle_name;
string[] male_prefix;
string[] middle_name;
MustacheWeight[] name;
MergeArray prefix;
string[] sex;
string[] suffix;
Title title;
string[] western_zodiac_sign;
}

struct Phone_NumberFolder {
Number[] formats;
}

struct ChemicalElement {
string symbol;
string name;
int atomicNumber;
}

struct ChemicalUnit {
string name;
string symbol;
}

struct ScienceFolder {
ChemicalElement[] chemicalElement;
ChemicalUnit[] unit;
}

struct TeamFolder {
string[] creature;
Mustache[] name;
}

struct VehicleFolder {
string[] bicycle_type;
string[] fuel;
string[] manufacturer;
string[] model;
string[] type;
}

struct WordFolder {
string[] adjective;
string[] adverb;
string[] conjunction;
string[] interjection;
string[] noun;
string[] preposition;
string[] verb;
}

struct Language {
AirlineFolder airline;
AnimalFolder animal;
AppFolder app;
Cell_PhoneFolder cell_phone;
CommerceFolder commerce;
CompanyFolder company;
DatabaseFolder database;
DateFolder date;
FinanceFolder finance;
HackerFolder hacker;
InternetFolder internet;
LocationFolder location;
LoremFolder lorem;
MusicFolder music;
PersonFolder person;
Phone_NumberFolder phone_number;
ScienceFolder science;
TeamFolder team;
VehicleFolder vehicle;
WordFolder word;
}
64 changes: 64 additions & 0 deletions fakerjs2generator/source/helper.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module helper;

import std.algorithm.searching : endsWith, startsWith;
import std.algorithm.iteration : filter, joiner, map, splitter;
import std.file : exists, readText;
import std.stdio;
import std.range : empty;
import std.conv : to;
import std.string : strip;

bool isImportLine(string l) {
l = l.strip();
return l.startsWith("import")
&& l.endsWith(";");
}

string stripImports(string s) {
string ret;
bool done = false;
foreach(l; s.splitter("\n")) {
if(l.startsWith("//")) {
continue;
}
if(done) {
ret ~= "\n" ~ l;
} else {
if(l.strip.empty()) {
ret ~= "\n" ~ l;
continue;
}
const isImport = l.startsWith("import") && l.endsWith(";");
if(!isImport) {
done = true;
ret ~= "\n" ~ l;
}
}
}
return ret;
}

string openAndTrimFile(string[] path) {
const prefixes = [ "export default" ];
const postfixes = [ ";" ];
string s = "faker/src/locales/" ~ path.joiner("/").to!string() ~ ".ts";
bool e = exists(s);
if(!e) {
return "";
} else {
string r = readText(s);
r = stripImports(r).strip();
foreach(pre; prefixes) {
if(r.startsWith(pre)) {
r = r[pre.length .. $];
}
}
foreach(post; postfixes) {
if(r.startsWith(post)) {
r = r[0 .. $ - post.length];
}
}

return r.strip();
}
}
Loading

0 comments on commit dd56149

Please sign in to comment.