Skip to content

Commit a2da7c4

Browse files
authored
refactor!: reorganize src folder (#909)
1 parent cc46a0c commit a2da7c4

File tree

41 files changed

+92
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+92
-89
lines changed

scripts/bundle.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ buildSync({
2525
// entryPoints: [
2626
// './src/index.ts',
2727
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
28-
// './src/mersenne.ts',
2928
// ],
3029
outdir: './dist/cjs',
3130
bundle: false, // Creates 390MiB bundle ...
@@ -42,7 +41,6 @@ buildSync({
4241
entryPoints: [
4342
'./src/index.ts',
4443
...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
45-
'./src/mersenne.ts',
4644
],
4745
outdir: './dist/esm',
4846
bundle: true,

src/definitions/internet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EmojiType } from '../internet';
1+
import type { EmojiType } from '../modules/internet';
22

33
/**
44
* The possible definitions related to internet stuff.

src/faker.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
1-
import { Address } from './address';
2-
import { Animal } from './animal';
3-
import { Commerce } from './commerce';
4-
import { Company } from './company';
5-
import { Database } from './database';
6-
import { Datatype } from './datatype';
7-
import { _Date } from './date';
81
import type { LocaleDefinition } from './definitions';
92
import { FakerError } from './errors/faker-error';
10-
import { Fake } from './fake';
11-
import { Finance } from './finance';
12-
import { Git } from './git';
13-
import { Hacker } from './hacker';
14-
import { Helpers } from './helpers';
15-
import { Image } from './image';
163
import { deprecated } from './internal/deprecated';
17-
import { Internet } from './internet';
184
import type { KnownLocale } from './locales';
19-
import { Lorem } from './lorem';
20-
import { Mersenne } from './mersenne';
21-
import { Music } from './music';
22-
import { Name } from './name';
23-
import { Phone } from './phone';
24-
import { Random } from './random';
25-
import { System } from './system';
26-
import { Time } from './time';
27-
import { Unique } from './unique';
28-
import { Vehicle } from './vehicle';
29-
import { Word } from './word';
30-
31-
// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
32-
export type LiteralUnion<T extends U, U = string> =
33-
| T
34-
| (U & { zz_IGNORE_ME?: never });
5+
import { Address } from './modules/address';
6+
import { Animal } from './modules/animal';
7+
import { Commerce } from './modules/commerce';
8+
import { Company } from './modules/company';
9+
import { Database } from './modules/database';
10+
import { Datatype } from './modules/datatype';
11+
import { _Date } from './modules/date';
12+
import { Fake } from './modules/fake';
13+
import { Finance } from './modules/finance';
14+
import { Git } from './modules/git';
15+
import { Hacker } from './modules/hacker';
16+
import { Helpers } from './modules/helpers';
17+
import { Image } from './modules/image';
18+
import { Internet } from './modules/internet';
19+
import { Lorem } from './modules/lorem';
20+
import { Mersenne } from './modules/mersenne';
21+
import { Music } from './modules/music';
22+
import { Name } from './modules/name';
23+
import { Phone } from './modules/phone';
24+
import { Random } from './modules/random';
25+
import { System } from './modules/system';
26+
import { Time } from './modules/time';
27+
import { Unique } from './modules/unique';
28+
import { Vehicle } from './modules/vehicle';
29+
import { Word } from './modules/word';
30+
import type { LiteralUnion } from './utils/types';
3531

3632
export type UsableLocale = LiteralUnion<KnownLocale>;
3733
export type UsedLocales = Partial<Record<UsableLocale, LocaleDefinition>>;

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export type {
2828
} from './definitions';
2929
export { FakerError } from './errors/faker-error';
3030
export type { FakerOptions, UsableLocale, UsedLocales } from './faker';
31-
export { Gender } from './name';
32-
export type { GenderType } from './name';
31+
export { Gender } from './modules/name';
32+
export type { GenderType } from './modules/name';
3333
export { Faker };
3434

3535
// since we are requiring the top level of faker, load all locales by default

src/address.ts renamed to src/modules/address/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate addresses and locations.

src/animal.ts renamed to src/modules/animal/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate animal related entries.

src/commerce.ts renamed to src/modules/commerce/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate commerce and product related entries.

src/company.ts renamed to src/modules/company/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate company related entries.

src/database.ts renamed to src/modules/database/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate database related entries.

src/datatype.ts renamed to src/modules/datatype/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Faker } from '.';
2-
import { FakerError } from './errors/faker-error';
3-
import { deprecated } from './internal/deprecated';
1+
import type { Faker } from '../..';
2+
import { FakerError } from '../../errors/faker-error';
3+
import { deprecated } from '../../internal/deprecated';
44

55
/**
66
* Module to generate various primitive values and data types.

src/date.ts renamed to src/modules/date/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '.';
2-
import type { DateEntryDefinition } from './definitions';
1+
import type { Faker } from '../..';
2+
import type { DateEntryDefinition } from '../../definitions';
33

44
/**
55
* Converts date passed as a string, number or Date to a Date object.

src/fake.ts renamed to src/modules/fake/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '.';
2-
import { FakerError } from './errors/faker-error';
1+
import type { Faker } from '../..';
2+
import { FakerError } from '../../errors/faker-error';
33

44
/**
55
* Generator method for combining faker methods based on string input.
File renamed without changes.

src/finance.ts renamed to src/modules/finance/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Faker } from '.';
2-
import { FakerError } from './errors/faker-error';
3-
import iban from './utils/iban';
1+
import type { Faker } from '../..';
2+
import { FakerError } from '../../errors/faker-error';
3+
import iban from './iban';
44

55
/**
66
* Module to generate finance related entries.

src/git.ts renamed to src/modules/git/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate git related entries.

src/hacker.ts renamed to src/modules/hacker/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate hacker/IT words and phrases.

src/helpers.ts renamed to src/modules/helpers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '.';
2-
import { deprecated } from './internal/deprecated';
1+
import type { Faker } from '../..';
2+
import { deprecated } from '../../internal/deprecated';
33

44
/**
55
* A full card with various details.

src/image.ts renamed to src/modules/image/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { Faker } from '.';
2-
import { LoremPicsum } from './image_providers/lorempicsum';
3-
import { Lorempixel } from './image_providers/lorempixel';
4-
import { Unsplash } from './image_providers/unsplash';
5-
import type { MethodsOf } from './utils/types';
1+
import type { Faker } from '../..';
2+
import type { MethodsOf } from '../../utils/types';
3+
import { LoremPicsum } from './providers/lorempicsum';
4+
import { Lorempixel } from './providers/lorempixel';
5+
import { Unsplash } from './providers/unsplash';
66

77
/**
88
* Module to generate placeholder images.

src/image_providers/lorempicsum.ts renamed to src/modules/image/providers/lorempicsum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '..';
1+
import type { Faker } from '../../..';
22

33
/**
44
* Module to generate links to random images on `https://picsum.photos/`.

src/image_providers/lorempixel.ts renamed to src/modules/image/providers/lorempixel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '..';
2-
import type { MethodsOf } from '../utils/types';
1+
import type { Faker } from '../../..';
2+
import type { MethodsOf } from '../../../utils/types';
33

44
/**
55
* Module to generate links to random images on `https://lorempixel.com/`.

src/image_providers/unsplash.ts renamed to src/modules/image/providers/unsplash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '..';
1+
import type { Faker } from '../../..';
22

33
/**
44
* Module to generate links to random images on `https://source.unsplash.com/`.

src/internet.ts renamed to src/modules/internet/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '.';
2-
import * as random_ua from './utils/user-agent';
1+
import type { Faker } from '../..';
2+
import * as random_ua from './user-agent';
33

44
export type EmojiType =
55
| 'smiley'

src/utils/user-agent.ts renamed to src/modules/internet/user-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* this stuff is worth it, you can buy me a beer in return. Luka Pusic
4343
*/
4444

45-
import type { Faker } from '..';
45+
import type { Faker } from '../..';
4646

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

src/lorem.ts renamed to src/modules/lorem/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate random texts and words.

src/mersenne.ts renamed to src/modules/mersenne/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { FakerError } from './errors/faker-error';
2-
import Gen from './utils/mersenne';
1+
import { FakerError } from '../../errors/faker-error';
2+
import Gen from './twister';
33

44
/**
55
* Module to generate seed based random numbers.
File renamed without changes.

src/music.ts renamed to src/modules/music/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate music related entries.

src/name.ts renamed to src/modules/name/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Faker } from '.';
2-
import { deprecated } from './internal/deprecated';
1+
import type { Faker } from '../..';
2+
import { deprecated } from '../../internal/deprecated';
33

44
export enum Gender {
55
female = 'female',

src/phone.ts renamed to src/modules/phone/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate phone-related data.

src/random.ts renamed to src/modules/random/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Faker } from '.';
2-
import { FakerError } from './errors/faker-error';
3-
import { deprecated } from './internal/deprecated';
1+
import type { Faker } from '../..';
2+
import { FakerError } from '../../errors/faker-error';
3+
import { deprecated } from '../../internal/deprecated';
44

55
/**
66
* Method to reduce array of characters.

src/system.ts renamed to src/modules/system/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

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

src/time.ts renamed to src/modules/time/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { LiteralUnion } from './faker';
2-
import { deprecated } from './internal/deprecated';
1+
import { deprecated } from '../../internal/deprecated';
2+
import type { LiteralUnion } from '../../utils/types';
33

44
/**
55
* Module to generate time of dates in various formats.

src/unique.ts renamed to src/modules/unique/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { deprecated } from './internal/deprecated';
2-
import type { RecordKey } from './utils/unique';
3-
import * as uniqueExec from './utils/unique';
1+
import { deprecated } from '../../internal/deprecated';
2+
import type { RecordKey } from './unique';
3+
import * as uniqueExec from './unique';
44

55
/**
66
* Module to generate unique entries.

src/utils/unique.ts renamed to src/modules/unique/unique.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FakerError } from '../errors/faker-error';
1+
import { FakerError } from '../../errors/faker-error';
22

33
export type RecordKey = string | number | symbol;
44

src/vehicle.ts renamed to src/modules/vehicle/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Module to generate vehicle related entries.

src/word.ts renamed to src/modules/word/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Faker } from '.';
1+
import type { Faker } from '../..';
22

33
/**
44
* Filters a string array for values with a specific length.

src/utils/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Type that provides auto-suggestions but also any string.
3+
*
4+
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
5+
*/
6+
export type LiteralUnion<T extends U, U = string> =
7+
| T
8+
| (U & { zz_IGNORE_ME?: never });
9+
110
/**
211
* Type that represents a single method/function name of the given type.
312
*/

test/finance.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { afterEach, describe, expect, it } from 'vitest';
22
import { faker } from '../src';
33
import { FakerError } from '../src/errors/faker-error';
4-
import ibanLib from '../src/utils/iban';
4+
import ibanLib from '../src/modules/finance/iban';
55
import { luhnCheck } from './support/luhnCheck';
66

77
const seedRuns = [

test/finance_iban.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import validator from 'validator';
22
import { describe, expect, it } from 'vitest';
33
import { faker } from '../src';
4-
import ibanLib from '../src/utils/iban';
4+
import ibanLib from '../src/modules/finance/iban';
55

66
const NON_SEEDED_BASED_RUN = 25;
77

test/mersenne.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
22
import { FakerError } from '../src/errors/faker-error';
3-
import { Mersenne } from '../src/mersenne';
3+
import { Mersenne } from '../src/modules/mersenne';
44

55
type SeededRun = {
66
seed: number | number[];

test/scripts/apidoc/signature.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LiteralUnion } from '../../../src/faker';
1+
import type { LiteralUnion } from '../../../src/utils/types';
22

33
/**
44
* Parameter options type with default from signature.

0 commit comments

Comments
 (0)