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(phone)!: add new style parameter #2578

Merged
merged 20 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
15 changes: 15 additions & 0 deletions docs/guide/upgrading_v9/2578.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### faker.phone.number `style` replaces explicit `format`

`faker.phone.number()` generates a phone number for the current locale. However, previously there was little control over the generated number, which might or might not include country codes, extensions, white space and punctuation.

If you wanted more control over the number, it was previously necessary to pass an explicit `format` parameter. This has now been removed. Instead, you can consider one of two options:

1. The new `style` parameter has convenient options for common use cases. There are three possible values.

- - `'human'`: (default, existing behavior) A human-input phone number, e.g. `555-770-7727` or `555.770.7727 x1234`
- - `'national'`: A phone number in a standardized national format, e.g. `(555) 123-4567`.
- - `'raw'`: A phone number in a raw international forma with country code, e.g. `+15551234567`
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved

The styles are locale-aware, so for example if you use pt_PT, phone numbers suitable for Portugal would be generated.

2. If none of the `style`s match your needs, you can use `faker.string.numeric()` or `faker.helpers.fromRegExp()` to create a custom pattern.
4 changes: 3 additions & 1 deletion src/definitions/phone_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
*
* @see faker.helpers.replaceSymbolWithNumber(format): For more information about how the patterns are used.
*/
formats: string[];
human: string[];
national: string[];
raw: string[];

Check warning on line 17 in src/definitions/phone_number.ts

View check run for this annotation

Codecov / codecov/patch

src/definitions/phone_number.ts#L15-L17

Added lines #L15 - L17 were not covered by tests
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}>;
8 changes: 6 additions & 2 deletions src/locales/af_ZA/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
9 changes: 9 additions & 0 deletions src/locales/af_ZA/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'1#########',
'2#########',
'3#########',
'4#########',
'5#########',
'080 0## ####',
'0860 ### ###',
];
9 changes: 9 additions & 0 deletions src/locales/af_ZA/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'+271#########',
'+272#########',
'+273#########',
'+274#########',
'+275#########',
'+27800######',
'+27860######',
];
8 changes: 6 additions & 2 deletions src/locales/az/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/az/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['9#########'];
1 change: 1 addition & 0 deletions src/locales/az/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+9949#########'];
8 changes: 6 additions & 2 deletions src/locales/cs_CZ/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/cs_CZ/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['601 ### ###', '737 ### ###', '736 ### ###', '### ### ###'];
6 changes: 6 additions & 0 deletions src/locales/cs_CZ/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default [
'+420601######',
'+420737######',
'+420736######',
'+420#########',
];
8 changes: 6 additions & 2 deletions src/locales/da/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/da/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['!# ## ## ##'];
1 change: 1 addition & 0 deletions src/locales/da/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+45!#######'];
8 changes: 6 additions & 2 deletions src/locales/de/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/de/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['0#### ########', '0#### #######', '0#### ######'];
1 change: 1 addition & 0 deletions src/locales/de/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+49############', '+49###########', '+49##########'];
8 changes: 6 additions & 2 deletions src/locales/de_AT/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/de_AT/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['01 #######', '0#### ####', '0#### #####'];
1 change: 1 addition & 0 deletions src/locales/de_AT/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+431#######', '+43########', '+43#########'];
8 changes: 6 additions & 2 deletions src/locales/de_CH/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
8 changes: 8 additions & 0 deletions src/locales/de_CH/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
'0800 ### ###',
'0## ### ## ##',
'0900 ### ###',
'076 ### ## ##',
'078 ### ## ##',
'079 ### ## ##',
];
8 changes: 8 additions & 0 deletions src/locales/de_CH/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
'+41800######',
'+41#########',
'+41900######',
'+4176#######',
'+4178#######',
'+4179#######',
];
8 changes: 6 additions & 2 deletions src/locales/dv/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
9 changes: 9 additions & 0 deletions src/locales/dv/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'3##-####',
'4##-####',
'5######',
'6##-####',
'7##-####',
'8######',
'9##-####',
];
9 changes: 9 additions & 0 deletions src/locales/dv/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'+9603######',
'+9604######',
'+9605######',
'+9606######',
'+9607######',
'+9608######',
'+9609######',
];
8 changes: 6 additions & 2 deletions src/locales/el/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
54 changes: 54 additions & 0 deletions src/locales/el/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export default [
'231 0## ####',
'231 2## ####',
'231 3## ####',
'222# ######',
'223# ######',
'227# ######',
'224# ######',
'226# ######',
'225# ######',
'232# ######',
'229# ######',
'228# ######',
'233# ######',
'234# ######',
'235# ######',
'237# ######',
'238# ######',
'239# ######',
'241 ### ####',
'242# ######',
'243# ######',
'244# ######',
'246# ######',
'249# ######',
'251 ### ####',
'252# ######',
'253# ######',
'254# ######',
'255# ######',
'259# ######',
'261 ### ####',
'262# ######',
'263# ######',
'264# ######',
'265# ######',
'266# ######',
'267# ######',
'268# ######',
'269# ######',
'271 ### ####',
'272# ######',
'273# ######',
'274# ######',
'275# ######',
'276# ######',
'279# ######',
'281 ### ####',
'282# ######',
'283# ######',
'284# ######',
'289# ######',
'0800######',
];
54 changes: 54 additions & 0 deletions src/locales/el/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
export default [
'+302310######',
'+302312######',
'+302313######',
'+30222#######',
'+30223#######',
'+30227#######',
'+30224#######',
'+30226#######',
'+30225#######',
'+30232#######',
'+30229#######',
'+30228#######',
'+30233#######',
'+30234#######',
'+30235#######',
'+30237#######',
'+30238#######',
'+30239#######',
'+30241#######',
'+30242#######',
'+30243#######',
'+30244#######',
'+30246#######',
'+30249#######',
'+30251#######',
'+30252#######',
'+30253#######',
'+30254#######',
'+30255#######',
'+30259#######',
'+30261#######',
'+30262#######',
'+30263#######',
'+30264#######',
'+30265#######',
'+30266#######',
'+30267#######',
'+30268#######',
'+30269#######',
'+30271#######',
'+30272#######',
'+30273#######',
'+30274#######',
'+30275#######',
'+30276#######',
'+30279#######',
'+30281#######',
'+30282#######',
'+30283#######',
'+30284#######',
'+30289#######',
'+300800######',
];
8 changes: 6 additions & 2 deletions src/locales/en/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import human from './human';
import national from './national';
import raw from './raw';

const phone_number: PhoneNumberDefinition = {
formats,
human,
national,
raw,
};

export default phone_number;
1 change: 1 addition & 0 deletions src/locales/en/phone_number/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['(!##) !##-####'];
1 change: 1 addition & 0 deletions src/locales/en/phone_number/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+1!##!######'];
Loading
Loading