Skip to content

Commit c25ecd0

Browse files
authored
feat: phone IMEI (#829)
1 parent 301ad54 commit c25ecd0

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/phone.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Faker } from '.';
22

33
/**
4-
* Module to generate phone numbers.
4+
* Module to generate phone-related data.
55
*/
66
export class Phone {
77
constructor(private readonly faker: Faker) {
@@ -60,4 +60,17 @@ export class Phone {
6060
this.faker.definitions.phone_number.formats
6161
);
6262
}
63+
64+
/**
65+
* Generates IMEI number.
66+
*
67+
* @example
68+
* faker.phone.imei() // '13-850175-913761-7'
69+
*/
70+
imei(): string {
71+
return this.faker.helpers.replaceCreditCardSymbols(
72+
'##-######-######-L',
73+
'#'
74+
);
75+
}
6376
}

test/phone.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { beforeEach, describe, expect, it } from 'vitest';
22
import { faker } from '../src';
3+
import { luhnCheck } from './support/luhnCheck';
34

45
const seededRuns = [
56
{
@@ -15,6 +16,9 @@ const seededRuns = [
1516
phoneFormats: {
1617
noArgs: '!##.!##.####',
1718
},
19+
imei: {
20+
noArgs: '37-917755-141004-5',
21+
},
1822
},
1923
},
2024
{
@@ -30,6 +34,9 @@ const seededRuns = [
3034
phoneFormats: {
3135
noArgs: '(!##) !##-####',
3236
},
37+
imei: {
38+
noArgs: '25-122540-325523-6',
39+
},
3340
},
3441
},
3542
{
@@ -45,11 +52,19 @@ const seededRuns = [
4552
phoneFormats: {
4653
noArgs: '1-!##-!##-#### x#####',
4754
},
55+
imei: {
56+
noArgs: '94-872190-616274-6',
57+
},
4858
},
4959
},
5060
];
5161

52-
const functionNames = ['phoneNumber', 'phoneNumberFormat', 'phoneFormats'];
62+
const functionNames = [
63+
'phoneNumber',
64+
'phoneNumberFormat',
65+
'phoneFormats',
66+
'imei',
67+
];
5368

5469
const NON_SEEDED_BASED_RUN = 25;
5570

@@ -125,6 +140,23 @@ describe('phone', () => {
125140
expect(faker.definitions.phone_number.formats).contain(phoneFormat);
126141
});
127142
});
143+
144+
describe('imei()', () => {
145+
it('should return a string', () => {
146+
const imei = faker.phone.imei();
147+
expect(imei).toBeTypeOf('string');
148+
});
149+
150+
it('should have a length of 18', () => {
151+
const imei = faker.phone.imei();
152+
expect(imei).toHaveLength(18);
153+
});
154+
155+
it('should be Luhn-valid', () => {
156+
const imei = faker.phone.imei();
157+
expect(imei).satisfy(luhnCheck);
158+
});
159+
});
128160
}
129161
});
130162
});

0 commit comments

Comments
 (0)