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

refactor!: reorganize src folder #909

Merged
merged 10 commits into from
May 3, 2022
2 changes: 0 additions & 2 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ buildSync({
// entryPoints: [
// './src/index.ts',
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
// './src/mersenne.ts',
// ],
outdir: './dist/cjs',
bundle: false, // Creates 390MiB bundle ...
Expand All @@ -42,7 +41,6 @@ buildSync({
entryPoints: [
'./src/index.ts',
...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
'./src/mersenne.ts',
],
outdir: './dist/esm',
bundle: true,
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/internet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EmojiType } from '../internet';
import type { EmojiType } from '../modules/internet';

/**
* The possible definitions related to internet stuff.
Expand Down
56 changes: 26 additions & 30 deletions src/faker.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import { Address } from './address';
import { Animal } from './animal';
import { Commerce } from './commerce';
import { Company } from './company';
import { Database } from './database';
import { Datatype } from './datatype';
import { _Date } from './date';
import type { LocaleDefinition } from './definitions';
import { FakerError } from './errors/faker-error';
import { Fake } from './fake';
import { Finance } from './finance';
import { Git } from './git';
import { Hacker } from './hacker';
import { Helpers } from './helpers';
import { Image } from './image';
import { deprecated } from './internal/deprecated';
import { Internet } from './internet';
import type { KnownLocale } from './locales';
import { Lorem } from './lorem';
import { Mersenne } from './mersenne';
import { Music } from './music';
import { Name } from './name';
import { Phone } from './phone';
import { Random } from './random';
import { System } from './system';
import { Time } from './time';
import { Unique } from './unique';
import { Vehicle } from './vehicle';
import { Word } from './word';

// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
export type LiteralUnion<T extends U, U = string> =
| T
| (U & { zz_IGNORE_ME?: never });
import { Address } from './modules/address';
import { Animal } from './modules/animal';
import { Commerce } from './modules/commerce';
import { Company } from './modules/company';
import { Database } from './modules/database';
import { Datatype } from './modules/datatype';
import { _Date } from './modules/date';
import { Fake } from './modules/fake';
import { Finance } from './modules/finance';
import { Git } from './modules/git';
import { Hacker } from './modules/hacker';
import { Helpers } from './modules/helpers';
import { Image } from './modules/image';
import { Internet } from './modules/internet';
import { Lorem } from './modules/lorem';
import { Mersenne } from './modules/mersenne';
import { Music } from './modules/music';
import { Name } from './modules/name';
import { Phone } from './modules/phone';
import { Random } from './modules/random';
import { System } from './modules/system';
import { Time } from './modules/time';
import { Unique } from './modules/unique';
import { Vehicle } from './modules/vehicle';
import { Word } from './modules/word';
import type { LiteralUnion } from './utils/types';

export type UsableLocale = LiteralUnion<KnownLocale>;
export type UsedLocales = Partial<Record<UsableLocale, LocaleDefinition>>;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export type {
} from './definitions';
export { FakerError } from './errors/faker-error';
export type { FakerOptions, UsableLocale, UsedLocales } from './faker';
export { Gender } from './name';
export type { GenderType } from './name';
export { Gender } from './modules/name';
export type { GenderType } from './modules/name';
export { Faker };

// since we are requiring the top level of faker, load all locales by default
Expand Down
2 changes: 1 addition & 1 deletion src/address.ts → src/modules/address/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate addresses and locations.
Expand Down
2 changes: 1 addition & 1 deletion src/animal.ts → src/modules/animal/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate animal related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/commerce.ts → src/modules/commerce/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate commerce and product related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/company.ts → src/modules/company/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate company related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/database.ts → src/modules/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate database related entries.
Expand Down
6 changes: 3 additions & 3 deletions src/datatype.ts → src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Faker } from '.';
import { FakerError } from './errors/faker-error';
import { deprecated } from './internal/deprecated';
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';

/**
* Module to generate various primitive values and data types.
Expand Down
4 changes: 2 additions & 2 deletions src/date.ts → src/modules/date/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '.';
import type { DateEntryDefinition } from './definitions';
import type { Faker } from '../..';
import type { DateEntryDefinition } from '../../definitions';

/**
* Converts date passed as a string, number or Date to a Date object.
Expand Down
4 changes: 2 additions & 2 deletions src/fake.ts → src/modules/fake/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '.';
import { FakerError } from './errors/faker-error';
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';

/**
* Generator method for combining faker methods based on string input.
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/finance.ts → src/modules/finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Faker } from '.';
import { FakerError } from './errors/faker-error';
import iban from './utils/iban';
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';
import iban from './iban';

/**
* Module to generate finance related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/git.ts → src/modules/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate git related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/hacker.ts → src/modules/hacker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate hacker/IT words and phrases.
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts → src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '.';
import { deprecated } from './internal/deprecated';
import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';

/**
* A full card with various details.
Expand Down
10 changes: 5 additions & 5 deletions src/image.ts → src/modules/image/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Faker } from '.';
import { LoremPicsum } from './image_providers/lorempicsum';
import { Lorempixel } from './image_providers/lorempixel';
import { Unsplash } from './image_providers/unsplash';
import type { MethodsOf } from './utils/types';
import type { Faker } from '../..';
import type { MethodsOf } from '../../utils/types';
import { LoremPicsum } from './providers/lorempicsum';
import { Lorempixel } from './providers/lorempixel';
import { Unsplash } from './providers/unsplash';

/**
* Module to generate placeholder images.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '..';
import type { Faker } from '../../..';

/**
* Module to generate links to random images on `https://picsum.photos/`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '..';
import type { MethodsOf } from '../utils/types';
import type { Faker } from '../../..';
import type { MethodsOf } from '../../../utils/types';

/**
* Module to generate links to random images on `https://lorempixel.com/`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '..';
import type { Faker } from '../../..';

/**
* Module to generate links to random images on `https://source.unsplash.com/`.
Expand Down
4 changes: 2 additions & 2 deletions src/internet.ts → src/modules/internet/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '.';
import * as random_ua from './utils/user-agent';
import type { Faker } from '../..';
import * as random_ua from './user-agent';

export type EmojiType =
| 'smiley'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* this stuff is worth it, you can buy me a beer in return. Luka Pusic
*/

import type { Faker } from '..';
import type { Faker } from '../..';

export type Arch = 'lin' | 'mac' | 'win';

Expand Down
2 changes: 1 addition & 1 deletion src/lorem.ts → src/modules/lorem/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate random texts and words.
Expand Down
4 changes: 2 additions & 2 deletions src/mersenne.ts → src/modules/mersenne/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FakerError } from './errors/faker-error';
import Gen from './utils/mersenne';
import { FakerError } from '../../errors/faker-error';
import Gen from './twister';

/**
* Module to generate seed based random numbers.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/music.ts → src/modules/music/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate music related entries.
Expand Down
4 changes: 2 additions & 2 deletions src/name.ts → src/modules/name/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Faker } from '.';
import { deprecated } from './internal/deprecated';
import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';

export enum Gender {
female = 'female',
Expand Down
2 changes: 1 addition & 1 deletion src/phone.ts → src/modules/phone/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate phone-related data.
Expand Down
6 changes: 3 additions & 3 deletions src/random.ts → src/modules/random/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Faker } from '.';
import { FakerError } from './errors/faker-error';
import { deprecated } from './internal/deprecated';
import type { Faker } from '../..';
import { FakerError } from '../../errors/faker-error';
import { deprecated } from '../../internal/deprecated';

/**
* Method to reduce array of characters.
Expand Down
2 changes: 1 addition & 1 deletion src/system.ts → src/modules/system/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

const commonFileTypes = ['video', 'audio', 'image', 'text', 'application'];

Expand Down
4 changes: 2 additions & 2 deletions src/time.ts → src/modules/time/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LiteralUnion } from './faker';
import { deprecated } from './internal/deprecated';
import { deprecated } from '../../internal/deprecated';
import type { LiteralUnion } from '../../utils/types';

/**
* Module to generate time of dates in various formats.
Expand Down
6 changes: 3 additions & 3 deletions src/unique.ts → src/modules/unique/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deprecated } from './internal/deprecated';
import type { RecordKey } from './utils/unique';
import * as uniqueExec from './utils/unique';
import { deprecated } from '../../internal/deprecated';
import type { RecordKey } from './unique';
import * as uniqueExec from './unique';

/**
* Module to generate unique entries.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/unique.ts → src/modules/unique/unique.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FakerError } from '../errors/faker-error';
import { FakerError } from '../../errors/faker-error';

export type RecordKey = string | number | symbol;

Expand Down
2 changes: 1 addition & 1 deletion src/vehicle.ts → src/modules/vehicle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Module to generate vehicle related entries.
Expand Down
2 changes: 1 addition & 1 deletion src/word.ts → src/modules/word/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faker } from '.';
import type { Faker } from '../..';

/**
* Filters a string array for values with a specific length.
Expand Down
9 changes: 9 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Type that provides auto-suggestions but also any string.
*
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
*/
export type LiteralUnion<T extends U, U = string> =
| T
| (U & { zz_IGNORE_ME?: never });

/**
* Type that represents a single method/function name of the given type.
*/
Expand Down
2 changes: 1 addition & 1 deletion test/finance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { FakerError } from '../src/errors/faker-error';
import ibanLib from '../src/utils/iban';
import ibanLib from '../src/modules/finance/iban';
import { luhnCheck } from './support/luhnCheck';

const seedRuns = [
Expand Down
2 changes: 1 addition & 1 deletion test/finance_iban.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import validator from 'validator';
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
import ibanLib from '../src/utils/iban';
import ibanLib from '../src/modules/finance/iban';

const NON_SEEDED_BASED_RUN = 25;

Expand Down
2 changes: 1 addition & 1 deletion test/mersenne.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
import { FakerError } from '../src/errors/faker-error';
import { Mersenne } from '../src/mersenne';
import { Mersenne } from '../src/modules/mersenne';

type SeededRun = {
seed: number | number[];
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidoc/signature.example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LiteralUnion } from '../../../src/faker';
import type { LiteralUnion } from '../../../src/utils/types';

/**
* Parameter options type with default from signature.
Expand Down