Skip to content

Commit

Permalink
Feature and data parity with faker.js 6/20/2020. (#306)
Browse files Browse the repository at this point in the history
* Feature and data parity with faker.js 6/20/2020.

* Added `Finance.Litecoin()`.
* Added `Commerce.ProductDescription()`.
* Add PlaceIMG image service. `Image.PlaceImgUrl()`.
* Data parity with faker.js. Deterministic sequences may have changed.
* New `en_NG` Nigerian locale.
* `en` updated.
* `nl_BE` updated.
* `de` updated.
* `ru` updated.
* `zh_CN` updated.
* `zh_TW` updated.
* `ar` updated.
* `cz` updated.
* `es_MX` updated.
* `sk` updated.
* `it` updated.

* Fix deterministic test due to new en_NG locale.
  • Loading branch information
bchavez authored Jun 21, 2020
1 parent f95dd4a commit 7d3cda1
Show file tree
Hide file tree
Showing 32 changed files with 6,338 additions and 456 deletions.
21 changes: 21 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
## v30.0.1-beta-2
Release Date: TBA

* Added `Finance.Litecoin()`.
* Added `Commerce.ProductDescription()`.
* Add PlaceIMG image service. `Image.PlaceImgUrl()`.
* Data parity with faker.js. Deterministic sequences may have changed.
* New `en_NG` Nigerian locale.
* `en` updated.
* `nl_BE` updated.
* `de` updated.
* `ru` updated.
* `zh_CN` updated.
* `zh_TW` updated.
* `ar` updated.
* `cz` updated.
* `es_MX` updated.
* `sk` updated.
* `it` updated.

## v30.0.1-beta-1
Release Date: 2020-06-14

* PR 300: `Random.Number()` now inclusive of `max: int.MaxValue`.
* PR 300: `Random.Even()` better random distribution and range checking.
* PR 300: `Random.Odd()` better random distribution and range checking.
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,30 +171,30 @@ public void With_Korean_Locale()

| Locale Code | Language | | Locale Code | Language |
|:--------------:|:-----------------------:|-|:--------------:|:------------------------:|
|`af_ZA `|South Africa (Afrikaans) ||`ge `|Georgian |
|`ar `|Arabic ||`id_ID `|Indonesia |
|`az `|Azerbaijani ||`it `|Italian |
|`cz `|Czech ||`ja `|Japanese |
|`de `|German ||`ko `|Korean |
|`de_AT `|German (Austria) ||`lv `|Latvian |
|`de_CH `|German (Switzerland) ||`nb_NO `|Norwegian |
|`el `|Greek ||`nep `|Nepalese |
|`en `|English ||`nl `|Dutch |
|`en_AU `|Australia (English) ||`nl_BE `|Dutch (Belgium) |
|`en_au_ocker `|Australia Ocker (English) ||`pl `|Polish |
|`en_BORK `|Bork (English) ||`pt_BR `|Portuguese (Brazil) |
|`en_CA `|Canada (English) ||`pt_PT `|Portuguese (Portugal) |
|`en_GB `|Great Britain (English) ||`ro `|Romanian |
|`en_IE `|Ireland (English) ||`ru `|Russian |
|`en_IND `|India (English) ||`sk `|Slovakian |
|`af_ZA `|South Africa (Afrikaans) ||`fr_CH `|French (Switzerland) |
|`ar `|Arabic ||`ge `|Georgian |
|`az `|Azerbaijani ||`id_ID `|Indonesia |
|`cz `|Czech ||`it `|Italian |
|`de `|German ||`ja `|Japanese |
|`de_AT `|German (Austria) ||`ko `|Korean |
|`de_CH `|German (Switzerland) ||`lv `|Latvian |
|`el `|Greek ||`nb_NO `|Norwegian |
|`en `|English ||`nep `|Nepalese |
|`en_AU `|Australia (English) ||`nl `|Dutch |
|`en_au_ocker `|Australia Ocker (English) ||`nl_BE `|Dutch (Belgium) |
|`en_BORK `|Bork (English) ||`pl `|Polish |
|`en_CA `|Canada (English) ||`pt_BR `|Portuguese (Brazil) |
|`en_GB `|Great Britain (English) ||`pt_PT `|Portuguese (Portugal) |
|`en_IE `|Ireland (English) ||`ro `|Romanian |
|`en_IND `|India (English) ||`ru `|Russian |
|`en_NG `|Nigeria (English) ||`sk `|Slovakian |
|`en_US `|United States (English) ||`sv `|Swedish |
|`en_ZA `|South Africa (English) ||`tr `|Turkish |
|`es `|Spanish ||`uk `|Ukrainian |
|`es_MX `|Spanish Mexico ||`vi `|Vietnamese |
|`fa `|Farsi ||`zh_CN `|Chinese |
|`fr `|French ||`zh_TW `|Chinese (Taiwan) |
|`fr_CA `|Canada (French) ||`zu_ZA `|South Africa (Zulu) |
|`fr_CH `|French (Switzerland) ||||


***Note:*** Some locales may not have a complete data set. For example, [`zh_CN`](https://github.com/Marak/faker.js/tree/master/lib/locales/zh_CN) does not have a `lorem` data set, but [`ko`](https://github.com/Marak/faker.js/tree/master/lib/locales/ko) has a `lorem` data set. **Bogus** will default to `en` if a *locale-specific* data set is not found. To further illustrate the previous example, the missing `zh_CN:lorem` data set will default to the `en:lorem` data set.
Expand Down Expand Up @@ -1177,7 +1177,7 @@ Upon a successful build, the following folders will be created:
#### Rebundling Locales
Re-bundling the latest locale data from **faker.js** requires the following software installed:

* [**NodeJS**](https://nodejs.org/) `v12.14.1` or higher.
* [**NodeJS**](https://nodejs.org/) `v12.18.1` or higher.
* [**gulp**](https://gulpjs.com/) `v4` or higher.

Steps to re-bundle locale data from **faker.js**:
Expand All @@ -1188,7 +1188,7 @@ Steps to re-bundle locale data from **faker.js**:
1. Ensure **NodeJS** and `gulp` are properly installed.
1. `cd Source\Builder`
1. `npm install` to install required dev dependencies.
1. `gulp importLocales` to regenerate locales in `Source\Bogus\data`.
1. `npx gulp importLocales` to regenerate locales in `Source\Bogus\data`.
1. Finally, run `build.cmd`.

### License
Expand Down
6 changes: 6 additions & 0 deletions Source/Bogus.Tests/DataSetTests/CommerceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public void can_get_a_product_name()
commerce.ProductName().Should().Be("Generic Wooden Bacon");
}

[Fact]
public void can_get_a_product_description()
{
commerce.ProductDescription().Should().Be("Carbonite web goalkeeper gloves are ergonomically designed to give easy fit");
}

[Fact]
public void can_get_categories()
{
Expand Down
6 changes: 6 additions & 0 deletions Source/Bogus.Tests/DataSetTests/FinanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void can_generate_a_random_ethereum_address()
finance.EthereumAddress().Should().Be("0x91da090b74f2b910be0dd5991af6398351ac2ef3");
}

[Fact]
public void can_generate_a_random_litecoin_address()
{
finance.LitecoinAddress().Should().Be("L7PE5D8HxpXjM3igcWbTeyKns2YdAfL");
}

[Fact]
public void can_generate_aba_routing_number()
{
Expand Down
23 changes: 23 additions & 0 deletions Source/Bogus.Tests/DataSetTests/ImageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,28 @@ public void can_use_loremflickr()

img.Should().Be("https://loremflickr.com/g/100/100/cat,bird/all?lock=227");
}


[Fact]
public void can_use_placeimg_url()
{
var img = image.PlaceImgUrl(640, 480, PlaceImgCategory.Animals);
img.Should().Be("https://placeimg.com/640/480/animals");

img = image.PlaceImgUrl();
img.Should().Be("https://placeimg.com/640/480/any");

img = image.PlaceImgUrl(777, 222, filter: PlaceImgFilter.Grayscale);
img.Should().Be("https://placeimg.com/777/222/any/grayscale");

img = image.PlaceImgUrl(777, 222, PlaceImgCategory.Architecture, PlaceImgFilter.Sepia);
img.Should().Be("https://placeimg.com/777/222/arch/sepia");

img = image.PlaceImgUrl(777, 333, PlaceImgCategory.Architecture);
img.Should().Be("https://placeimg.com/777/333/arch");

img = image.PlaceImgUrl(777, 444, PlaceImgCategory.Tech);
img.Should().Be("https://placeimg.com/777/444/tech");
}
}
}
2 changes: 1 addition & 1 deletion Source/Bogus.Tests/RandomizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void can_shuffle_some_enumerable()
[Fact]
public void can_get_random_locale()
{
r.RandomLocale().Should().Be("ko");
r.RandomLocale().Should().Be("ja");
}

[Fact]
Expand Down
9 changes: 9 additions & 0 deletions Source/Bogus/DataSets/Commerce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ public string ProductMaterial()
return GetRandomArrayItem("product_name.material");
}

/// <summary>
/// Random product description.
/// </summary>
/// <returns>A random product description.</returns>
public string ProductDescription()
{
return GetRandomArrayItem("product_description");
}

/// <summary>
/// EAN-8 checksum weights.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Source/Bogus/DataSets/Finance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,26 @@ public string EthereumAddress()
return Random.Hexadecimal(40);
}

/// <summary>
/// Generate a random Litecoin address.
/// </summary>
public string LitecoinAddress()
{
var addressLength = this.Random.Number(26, 33);
var lastBits = new string(this.Random.ArrayElements(BtcCharset, addressLength));
var prefix = this.Random.Number(0, 2);

if( prefix == 0 )
{
return $"L{lastBits}";
}
if( prefix == 1 )
{
return $"M{lastBits}";
}
return $"3{lastBits}";
}

/// <summary>
/// Generates an ABA routing number with valid check digit.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions Source/Bogus/DataSets/Images.PlaceImg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Bogus.DataSets
{
public enum PlaceImgFilter
{
Grayscale,
Sepia
}

public static class PlaceImgCategory
{
public const string Animals = "animals";
public const string Architecture = "arch";
public const string Nature = "nature";
public const string People = "people";
public const string Tech = "tech";
public const string Any = "any";
}
}
37 changes: 36 additions & 1 deletion Source/Bogus/DataSets/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ public string DataUri(int width, int height, string htmlColor = "grey")
return rawPrefix + Uri.EscapeDataString(svgString);
}

/// <summary>
/// Get an image from the https://placeimg.com service.
/// </summary>
/// <param name="width">Width of the image.</param>
/// <param name="height">Height of the image.</param>
/// <param name="category">Category of the image. See <seealso cref="PlaceImgCategory"/> for string categories.</param>
/// <param name="filter">The filter to apply to the image. See <seealso cref="PlaceImgFilter"/>.</param>
/// <returns></returns>
public string PlaceImgUrl(
int width = 640, int height = 480,
string category = PlaceImgCategory.Any,
PlaceImgFilter? filter = null)
{
//https://placeimg.com/640/480/nature/grayscale
//https://placeimg.com/640/480/nature
//https://placeimg.com/640/480/any/sepia
//https://placeimg.com/640/480/any

const string Url = "https://placeimg.com";

var sb = new StringBuilder(Url);
sb.Append($"/{width}/{height}/{category}");

if (filter is PlaceImgFilter.Grayscale)
{
sb.Append("/grayscale");
}
else if ( filter is PlaceImgFilter.Sepia )
{
sb.Append("/sepia");
}

return sb.ToString();

}

/// <summary>
/// Get an image from the https://picsum.photos service.
/// </summary>
Expand All @@ -48,7 +84,6 @@ public string PicsumUrl(int width = 640, int height = 480, bool grayscale = fals
if (grayscale)
{
sb.Append("/g");

}

sb.Append($"/{width}/{height}");
Expand Down
Binary file modified Source/Bogus/data/cz.locale.bson
Binary file not shown.
20 changes: 10 additions & 10 deletions Source/Bogus/data/cz.locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -13745,16 +13745,16 @@
]
},
"name": [
"#{prefix} #{man_first_name} #{man_last_name}",
"#{prefix} #{woman_first_name} #{woman_last_name}",
"#{man_first_name} #{man_last_name} #{suffix}",
"#{woman_first_name} #{woman_last_name} #{suffix}",
"#{man_first_name} #{man_last_name}",
"#{man_first_name} #{man_last_name}",
"#{man_first_name} #{man_last_name}",
"#{woman_first_name} #{woman_last_name}",
"#{woman_first_name} #{woman_last_name}",
"#{woman_first_name} #{woman_last_name}"
"#{prefix} #{male_first_name} #{male_last_name}",
"#{prefix} #{female_first_name} #{female_last_name}",
"#{male_first_name} #{male_last_name} #{suffix}",
"#{female_first_name} #{female_last_name} #{suffix}",
"#{male_first_name} #{male_last_name}",
"#{male_first_name} #{male_last_name}",
"#{male_first_name} #{male_last_name}",
"#{female_first_name} #{female_last_name}",
"#{female_first_name} #{female_last_name}",
"#{female_first_name} #{female_last_name}"
]
},
"phone_number": {
Expand Down
Binary file modified Source/Bogus/data/de.locale.bson
Binary file not shown.
Loading

0 comments on commit 7d3cda1

Please sign in to comment.