Skip to content

Commit

Permalink
feat(types): provide strong typing for locales (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Feb 1, 2022
1 parent 18b4349 commit 5e6754d
Show file tree
Hide file tree
Showing 50 changed files with 939 additions and 488 deletions.
1 change: 1 addition & 0 deletions src/address.ts
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
@@ -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
@@ -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
@@ -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'
);

0 comments on commit 5e6754d

Please sign in to comment.