aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-01-30 18:55:06 +0100
committerGitHub <[email protected]>2022-01-30 18:55:06 +0100
commitd4125e2a7d69042c37ccecea89f1525c4424a45b (patch)
tree99f9a997e0bd32b034c9a15d53a7a3ac957911cf /src
parent730ca6a65a29038636e8cc3eec12eacf929db7fb (diff)
downloadfaker-d4125e2a7d69042c37ccecea89f1525c4424a45b.tar.xz
faker-d4125e2a7d69042c37ccecea89f1525c4424a45b.zip
chore: use explicit-module-boundary-types (#361)
Diffstat (limited to 'src')
-rw-r--r--src/address.ts8
-rw-r--r--src/helpers.ts108
-rw-r--r--src/iban.ts8
-rw-r--r--src/image_providers/unsplash.ts2
-rw-r--r--src/internet.ts2
-rw-r--r--src/lorem.ts8
-rw-r--r--src/mersenne.ts6
-rw-r--r--src/phone.ts4
-rw-r--r--src/random.ts1
-rw-r--r--src/vendor/user-agent.ts2
10 files changed, 125 insertions, 24 deletions
diff --git a/src/address.ts b/src/address.ts
index f45bf487..7e6b0fdc 100644
--- a/src/address.ts
+++ b/src/address.ts
@@ -47,7 +47,7 @@ export class Address {
* @method faker.address.zipCode
* @param format
*/
- zipCode(format?: string) {
+ zipCode(format?: string): string {
// if zip format is not specified, use the zip format defined for the locale
if (typeof format === 'undefined') {
const localeFormat = this.faker.definitions.address.postcode;
@@ -70,7 +70,7 @@ export class Address {
* @method faker.address.zipCodeByState
* @param state
*/
- zipCodeByState(state: string) {
+ zipCodeByState(state: string): string | number {
const zipRange = this.faker.definitions.address.postcode_by_state[state];
if (zipRange) {
return this.faker.datatype.number(zipRange);
@@ -94,7 +94,7 @@ export class Address {
* @method faker.address.city
* @param format
*/
- city(format?: string | number) {
+ city(format?: string | number): string {
const formats = [
'{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}',
'{{address.cityPrefix}} {{name.firstName}}',
@@ -353,7 +353,7 @@ export class Address {
* @method faker.address.direction
* @param useAbbr return direction abbreviation. defaults to false
*/
- direction(useAbbr: boolean = false) {
+ direction(useAbbr: boolean = false): string {
if (!useAbbr) {
return this.faker.random.arrayElement(
this.faker.definitions.address.direction
diff --git a/src/helpers.ts b/src/helpers.ts
index 3968c221..c67a50a6 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -1,5 +1,103 @@
import type { Faker } from '.';
+export interface Card {
+ name: string;
+ username: string;
+ email: string;
+ address: {
+ streetA: string;
+ streetB: string;
+ streetC: string;
+ streetD: string;
+ city: string;
+ state: string;
+ country: string;
+ zipcode: string;
+ geo: {
+ lat: string;
+ lng: string;
+ };
+ };
+ phone: string;
+ website: string;
+ company: {
+ name: string;
+ catchPhrase: string;
+ bs: string;
+ };
+ posts: Array<{
+ words: string;
+ sentence: string;
+ sentences: string;
+ paragraph: string;
+ }>;
+ accountHistory: Array<{
+ amount: string;
+ date: Date;
+ business: string;
+ name: string;
+ type: string;
+ account: string;
+ }>;
+}
+
+export interface ContextualCard {
+ name: string;
+ username: string;
+ avatar: string;
+ email: string;
+ dob: Date;
+ phone: string;
+ address: {
+ street: string;
+ suite: string;
+ city: string;
+ zipcode: string;
+ geo: {
+ lat: string;
+ lng: string;
+ };
+ };
+ website: string;
+ company: {
+ name: string;
+ catchPhrase: string;
+ bs: string;
+ };
+}
+
+export interface UserCard {
+ name: string;
+ username: string;
+ email: string;
+ address: {
+ street: string;
+ suite: string;
+ city: string;
+ zipcode: string;
+ geo: {
+ lat: string;
+ lng: string;
+ };
+ };
+ phone: string;
+ website: string;
+ company: {
+ name: string;
+ catchPhrase: string;
+ bs: string;
+ };
+}
+
+export interface Transaction {
+ amount: string;
+ date: Date;
+ business: string;
+ name: string;
+ type: string;
+ account: string;
+}
+
export class Helpers {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
@@ -160,7 +258,7 @@ export class Helpers {
* @param string
* @param num
*/
- repeatString(string, num = 0): string {
+ repeatString(string: string, num = 0): string {
let text = '';
for (let i = 0; i < num; i++) {
text += string.toString();
@@ -323,7 +421,7 @@ export class Helpers {
*
* @method faker.helpers.createCard
*/
- createCard() {
+ createCard(): Card {
return {
name: this.faker.name.findName(),
username: this.faker.internet.userName(),
@@ -382,7 +480,7 @@ export class Helpers {
*
* @method faker.helpers.contextualCard
*/
- contextualCard() {
+ contextualCard(): ContextualCard {
const name = this.faker.name.firstName();
const userName = this.faker.internet.userName(name);
return {
@@ -421,7 +519,7 @@ export class Helpers {
*
* @method faker.helpers.userCard
*/
- userCard() {
+ userCard(): UserCard {
return {
name: this.faker.name.findName(),
username: this.faker.internet.userName(),
@@ -451,7 +549,7 @@ export class Helpers {
*
* @method faker.helpers.createTransaction
*/
- createTransaction() {
+ createTransaction(): Transaction {
return {
amount: this.faker.finance.amount(),
date: new Date(2012, 1, 2), // TODO: add a ranged date method
diff --git a/src/iban.ts b/src/iban.ts
index 49e6bbac..0c902534 100644
--- a/src/iban.ts
+++ b/src/iban.ts
@@ -37,10 +37,14 @@ export = {
// @ts-expect-error
match.toUpperCase().charCodeAt(0) - 55
),
- mod97: (digitStr): number => {
+ mod97: (digitStr: string): number => {
let m = 0;
for (let i = 0; i < digitStr.length; i++) {
- m = (m * 10 + (digitStr[i] | 0)) % 97;
+ m =
+ (m * 10 +
+ // @ts-expect-error: We need to convert this properly
+ (digitStr[i] | 0)) %
+ 97;
}
return m;
},
diff --git a/src/image_providers/unsplash.ts b/src/image_providers/unsplash.ts
index 269920f2..1d358345 100644
--- a/src/image_providers/unsplash.ts
+++ b/src/image_providers/unsplash.ts
@@ -30,7 +30,7 @@ export class Unsplash {
*
* @method faker.image.unsplash.avatar
*/
- avatar() {
+ avatar(): string {
return this.faker.internet.avatar();
}
diff --git a/src/internet.ts b/src/internet.ts
index 78a16474..b26654d1 100644
--- a/src/internet.ts
+++ b/src/internet.ts
@@ -220,7 +220,7 @@ export class Internet {
* @param firstName
* @param lastName
*/
- exampleEmail(firstName?: string, lastName?: string) {
+ exampleEmail(firstName?: string, lastName?: string): string {
const provider = this.faker.random.arrayElement(
this.faker.definitions.internet.example_email
);
diff --git a/src/lorem.ts b/src/lorem.ts
index eb1395f3..5583b510 100644
--- a/src/lorem.ts
+++ b/src/lorem.ts
@@ -90,7 +90,7 @@ export class Lorem {
* @param sentenceCount defaults to a random number between 2 and 6
* @param separator defaults to `' '`
*/
- sentences(sentenceCount?: number, separator?: string) {
+ sentences(sentenceCount?: number, separator?: string): string {
if (typeof sentenceCount === 'undefined') {
sentenceCount = this.faker.datatype.number({ min: 2, max: 6 });
}
@@ -137,10 +137,8 @@ export class Lorem {
* @method faker.lorem.text
* @param times
*/
- // TODO @Shinigami92 2022-01-11: Is this a function-name alias?
- // Or can we just remove the `loremText`?
// TODO @Shinigami92 2022-01-11: `times` is not in use
- text = function loremText(times?: number) {
+ text(times?: number): string {
const loremMethods = [
'lorem.word',
'lorem.words',
@@ -152,7 +150,7 @@ export class Lorem {
];
const randomLoremMethod = this.faker.random.arrayElement(loremMethods);
return this.faker.fake('{{' + randomLoremMethod + '}}');
- };
+ }
/**
* Returns lines of lorem separated by `'\n'`
diff --git a/src/mersenne.ts b/src/mersenne.ts
index 7f42501e..40ca4578 100644
--- a/src/mersenne.ts
+++ b/src/mersenne.ts
@@ -15,7 +15,7 @@ export class Mersenne {
}
}
- rand(max?: number, min?: number) {
+ rand(max?: number, min?: number): number {
// TODO @Shinigami92 2022-01-11: This is buggy, cause if min is not passed but only max,
// then min will be undefined and this result in NaN for the whole function
if (max === undefined) {
@@ -26,7 +26,7 @@ export class Mersenne {
return Math.floor(this.gen.genrand_real2() * (max - min) + min);
}
- seed(S: number) {
+ seed(S: number): void {
if (typeof S != 'number') {
throw new Error('seed(S) must take numeric argument; is ' + typeof S);
}
@@ -34,7 +34,7 @@ export class Mersenne {
this.gen.init_genrand(S);
}
- seed_array(A) {
+ seed_array(A: number[]): void {
if (typeof A != 'object') {
throw new Error(
'seed_array(A) must take array of numbers; is ' + typeof A
diff --git a/src/phone.ts b/src/phone.ts
index 1db85eae..614e7f4a 100644
--- a/src/phone.ts
+++ b/src/phone.ts
@@ -18,7 +18,7 @@ export class Phone {
* @param format
* @memberOf faker.phone
*/
- phoneNumber(format?: string) {
+ phoneNumber(format?: string): string {
format ||= this.faker.phone.phoneFormats();
return this.faker.helpers.replaceSymbolWithNumber(format);
}
@@ -31,7 +31,7 @@ export class Phone {
* @param phoneFormatsArrayIndex
* @memberOf faker.phone
*/
- phoneNumberFormat(phoneFormatsArrayIndex: number = 0) {
+ phoneNumberFormat(phoneFormatsArrayIndex: number = 0): string {
return this.faker.helpers.replaceSymbolWithNumber(
this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
);
diff --git a/src/random.ts b/src/random.ts
index 627e603f..5f475936 100644
--- a/src/random.ts
+++ b/src/random.ts
@@ -124,6 +124,7 @@ export class Random {
* @param object
* @param field
*/
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
objectElement(object: any = { foo: 'bar', too: 'car' }, field?: string) {
const array = Object.keys(object);
const key = this.faker.random.arrayElement(array);
diff --git a/src/vendor/user-agent.ts b/src/vendor/user-agent.ts
index b2982b99..81cbeb3e 100644
--- a/src/vendor/user-agent.ts
+++ b/src/vendor/user-agent.ts
@@ -30,7 +30,7 @@ import type { Faker } from '..';
export type Arch = 'lin' | 'mac' | 'win';
-export function generate(faker: Faker) {
+export function generate(faker: Faker): string {
function rnd(
a?: string[] | number | Record<string, number>,
b?: number