Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): provide strong typing for locales #363

Merged
merged 42 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3e0ffb2
feat(types): provide strong typing for locales
ST-DDT Jan 30, 2022
41419d7
fix: use only a single definitions instance
ST-DDT Jan 30, 2022
f5dc95a
chore: cleanup
ST-DDT Jan 30, 2022
72c7da2
chore: improve comment
ST-DDT Jan 30, 2022
798e4fe
chore: move definitions to separate files
ST-DDT Jan 30, 2022
d389048
feat: migrate company definitions
ST-DDT Jan 30, 2022
80efc20
chore: move LocaleDefinition to definitions
ST-DDT Jan 30, 2022
fcbb754
docs: add some jsdocs
ST-DDT Jan 30, 2022
fd6da92
feat: split commerce to its own file
ST-DDT Jan 30, 2022
8d970e4
feat: split database to its own file
ST-DDT Jan 30, 2022
8865608
feat: split database to its own file
ST-DDT Jan 30, 2022
8b3f166
feat: split date to its own file
ST-DDT Jan 30, 2022
b09cfc7
chore: cleanup
ST-DDT Jan 30, 2022
74c8bcc
feat: split finance to its own file
ST-DDT Jan 30, 2022
e73248e
chore: fix definitions to match new linting rules
ST-DDT Jan 30, 2022
8eeff0b
feat: split hacker to its own file
ST-DDT Jan 30, 2022
30e13ba
feat: split internet to its own file
ST-DDT Jan 30, 2022
09d13e8
feat: split lorem to its own file
ST-DDT Jan 30, 2022
fcd1de5
Merge branch 'main' into locales/strong-types
ST-DDT Jan 30, 2022
e2f759b
chore: merge main
ST-DDT Jan 30, 2022
61e8787
chore: add lorem jsdocs
ST-DDT Jan 30, 2022
74f6085
feat: split music to its own file
ST-DDT Jan 30, 2022
ebe421f
feat: split phone_number to its own file
ST-DDT Jan 30, 2022
139bf61
feat: split system into onw file
ST-DDT Jan 30, 2022
02ae943
feat: split vehicle into own file
ST-DDT Jan 30, 2022
36b0a84
feat: split word into own file
ST-DDT Jan 30, 2022
7ad4597
feat: remove non-api entries from locale definitions
ST-DDT Jan 30, 2022
0ea2ef8
chore: fix some style differences
ST-DDT Jan 30, 2022
c7e7eea
chore: fix some style differences
ST-DDT Jan 30, 2022
332429e
chore: add missing type
ST-DDT Jan 30, 2022
fdb57b2
chore: fix typo
ST-DDT Jan 31, 2022
98c4d58
chore: applychanges from review
ST-DDT Jan 31, 2022
c0b519c
chore: type magic
ST-DDT Jan 31, 2022
5f00c39
chore: type magic^2
ST-DDT Jan 31, 2022
3a51350
chore: type magic fixes
ST-DDT Jan 31, 2022
6ed3e79
chore: remove simple type aliases
ST-DDT Jan 31, 2022
42bf901
chore: inline more types
ST-DDT Jan 31, 2022
a576e95
chore: merge import and export statements
ST-DDT Jan 31, 2022
bf157fa
chore: merge main
ST-DDT Jan 31, 2022
eba1e93
chore: apply feedback
ST-DDT Jan 31, 2022
16930d5
Merge branch 'main' into locales/strong-types
prisis Feb 1, 2022
5463859
Merge branch 'main' into locales/strong-types
prisis Feb 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class Address {
*/
secondaryAddress(): string {
return this.Helpers.replaceSymbolWithNumber(
// TODO ST-DDT 2022-01-30: this.faker.definitions.address.secondary_address
this.faker.random.arrayElement(['Apt. ###', 'Suite ###'])
);
}
Expand Down
131 changes: 0 additions & 131 deletions src/definitions.ts

This file was deleted.

115 changes: 115 additions & 0 deletions src/definitions/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { allOf } from './utils';

/**
* The possible definitions related to addresses.
*/
export interface AddressDefinitions {
/**
* Postcodes patterns by state
*/
// TODO ST-DDT 2022-01-31: address.zipCodeByState() expects only { [state: string]: { min: number; max: number } }
postcode_by_state:
| string[]
| { [state: string]: { min: number; max: number } };
/**
* Postcodes patterns (Fake-Pattern | Fake-Pattern[]).
*/
postcode: string | string[];

/**
* Names of actual cities
*/
city_name?: string[];
/**
* Common city prefixes
*/
city_prefix: string[];
/**
* Common city suffixes
*/
city_suffix: string[];

/**
* The names of all countries
*/
country: string[];
/**
* The names of this country's states
*/
state: string[];
/**
* The abbreviated names of this country's states
*/
state_abbr: string[];
/**
* The names of counties inside the country or state
*/
county: string[];

/**
* The names of the compass directions.
* First the 4 cardinal directions, then the 4 ordinal directions
*/
direction: string[];
/**
* The abbreviated names of the compass directions.
* First the 4 cardinal directions, then the 4 ordinal directions
*/
direction_abbr: string[];

/**
* Common street prefixes
*/
street_prefix: string[];
/**
* Common street suffixes
*/
street_suffix: string[];

/**
* The address "inside" an address/e.g. an apartment or office.
*/
secondary_address: string[];

/**
* The ISO-3166-1 ALPHA-2 country codes
*/
country_code: string[];
/**
* The ISO-3166-1 ALPHA-3 country codes
*/
country_code_alpha_3: string[];

// A list of timezones names.
time_zone: string[];
}

/**
* Internal: A list of all keys for the AddressDefinitions.
*/
export const ADDRESS = allOf<keyof AddressDefinitions>()(
'postcode_by_state',
'postcode',

'city_name',
'city_prefix',
'city_suffix',

'country',
'state',
'state_abbr',
'county',

'direction_abbr',
'direction',

'street_prefix',
'street_suffix',

'secondary_address',

'country_code',
'country_code_alpha_3',

'time_zone'
);
41 changes: 41 additions & 0 deletions src/definitions/animal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { allOf } from './utils';

/**
* The possible definitions related to animals.
*/
export interface AnimalDefinitions {
bear: string[];
bird: string[];
cat: string[];
cetacean: string[];
cow: string[];
crocodilia: string[];
dog: string[];
fish: string[];
horse: string[];
insect: string[];
lion: string[];
rabbit: string[];
snake: string[];
type: string[];
}

/**
* Internal: A list of all keys for the AnimalDefinitions.
*/
export const ANIMAL = allOf<keyof AnimalDefinitions>()(
'dog',
'cat',
'snake',
'bear',
'lion',
'cetacean',
'insect',
'crocodilia',
'cow',
'bird',
'fish',
'rabbit',
'horse',
'type'
);
51 changes: 51 additions & 0 deletions src/definitions/commerce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { allOf } from './utils';

/**
* The possible definitions related to commerce.
*/
export interface CommerceDefinitions {
/**
* Human readable color names
*/
color: string[];
/**
* Department names inside a shop.
*/
department: string[];
/**
* Product name generation definitions.
*/
product_name: CommerceProductNameDefinitions;
/**
* Descriptions for products.
*/
product_description: string[];
}

/**
* The possible definitions related to product name generation.
*/
export interface CommerceProductNameDefinitions {
/**
* Adjectives describing a product (e.g. tasty).
*/
adjective: string[];
/**
* Materials describing a product (e.g. wood).
*/
material: string[];
/**
* Types of products (e.g. chair).
*/
product: string[];
}

/**
* Internal: A list of all keys for the CommerceDefinitions.
*/
export const COMMERCE = allOf<keyof CommerceDefinitions>()(
'color',
'department',
'product_name',
'product_description'
);
Loading