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(modules): export module interfaces #932

Merged
merged 5 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function processModuleMethods(project: ProjectReflection): PageIndex {
}

export function extractModuleName(module: DeclarationReflection): string {
return module.name.replace('_', '');
return module.name.replace(/Module$/, '');
}

function extractModuleFieldName(module: DeclarationReflection): string {
Expand All @@ -50,7 +50,7 @@ function extractModuleFieldName(module: DeclarationReflection): string {
/**
* Analyzes and writes the documentation for a module and its methods such as `faker.animal.cat()`.
*
* @param direct The module to process.
* @param module The module to process.
* @returns The generated pages.
*/
function processModuleMethod(module: DeclarationReflection): PageIndex {
Expand Down
104 changes: 52 additions & 52 deletions src/faker.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import type { LocaleDefinition } from './definitions';
import { FakerError } from './errors/faker-error';
import type { KnownLocale } from './locales';
import { Address } from './modules/address';
import { Animal } from './modules/animal';
import { Color } from './modules/color';
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 { Science } from './modules/science';
import { System } from './modules/system';
import { Unique } from './modules/unique';
import { Vehicle } from './modules/vehicle';
import { Word } from './modules/word';
import { AddressModule } from './modules/address';
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
import { AnimalModule } from './modules/animal';
import { ColorModule } from './modules/color';
import { CommerceModule } from './modules/commerce';
import { CompanyModule } from './modules/company';
import { DatabaseModule } from './modules/database';
import { DatatypeModule } from './modules/datatype';
import { DateModule } from './modules/date';
import { FakeModule } from './modules/fake';
import { FinanceModule } from './modules/finance';
import { GitModule } from './modules/git';
import { HackerModule } from './modules/hacker';
import { HelpersModule } from './modules/helpers';
import { ImageModule } from './modules/image';
import { InternetModule } from './modules/internet';
import { LoremModule } from './modules/lorem';
import { MersenneModule } from './modules/mersenne';
import { MusicModule } from './modules/music';
import { NameModule } from './modules/name';
import { PhoneModule } from './modules/phone';
import { RandomModule } from './modules/random';
import { ScienceModule } from './modules/science';
import { SystemModule } from './modules/system';
import { UniqueModule } from './modules/unique';
import { VehicleModule } from './modules/vehicle';
import { WordModule } from './modules/word';
import type { LiteralUnion } from './utils/types';

export type UsableLocale = LiteralUnion<KnownLocale>;
Expand Down Expand Up @@ -76,36 +76,36 @@ export class Faker {

readonly definitions: LocaleDefinition = this.initDefinitions();

readonly fake: Fake['fake'] = new Fake(this).fake;
readonly unique: Unique['unique'] = new Unique(this).unique;
readonly fake: FakeModule['fake'] = new FakeModule(this).fake;
readonly unique: UniqueModule['unique'] = new UniqueModule(this).unique;

readonly mersenne: Mersenne = new Mersenne();
readonly random: Random = new Random(this);
readonly mersenne: MersenneModule = new MersenneModule();
readonly random: RandomModule = new RandomModule(this);

readonly helpers: Helpers = new Helpers(this);
readonly helpers: HelpersModule = new HelpersModule(this);

readonly datatype: Datatype = new Datatype(this);
readonly datatype: DatatypeModule = new DatatypeModule(this);

readonly address: Address = new Address(this);
readonly animal: Animal = new Animal(this);
readonly color: Color = new Color(this);
readonly commerce: Commerce = new Commerce(this);
readonly company: Company = new Company(this);
readonly database: Database = new Database(this);
readonly date: _Date = new _Date(this);
readonly finance = new Finance(this);
readonly git: Git = new Git(this);
readonly hacker: Hacker = new Hacker(this);
readonly image: Image = new Image(this);
readonly internet: Internet = new Internet(this);
readonly lorem: Lorem = new Lorem(this);
readonly music: Music = new Music(this);
readonly name: Name = new Name(this);
readonly phone: Phone = new Phone(this);
readonly science: Science = new Science(this);
readonly system: System = new System(this);
readonly vehicle: Vehicle = new Vehicle(this);
readonly word: Word = new Word(this);
readonly address: AddressModule = new AddressModule(this);
readonly animal: AnimalModule = new AnimalModule(this);
readonly color: ColorModule = new ColorModule(this);
readonly commerce: CommerceModule = new CommerceModule(this);
readonly company: CompanyModule = new CompanyModule(this);
readonly database: DatabaseModule = new DatabaseModule(this);
readonly date: DateModule = new DateModule(this);
readonly finance = new FinanceModule(this);
readonly git: GitModule = new GitModule(this);
readonly hacker: HackerModule = new HackerModule(this);
readonly image: ImageModule = new ImageModule(this);
readonly internet: InternetModule = new InternetModule(this);
readonly lorem: LoremModule = new LoremModule(this);
readonly music: MusicModule = new MusicModule(this);
readonly name: NameModule = new NameModule(this);
readonly phone: PhoneModule = new PhoneModule(this);
readonly science: ScienceModule = new ScienceModule(this);
readonly system: SystemModule = new SystemModule(this);
readonly vehicle: VehicleModule = new VehicleModule(this);
readonly word: WordModule = new WordModule(this);

constructor(opts: FakerOptions) {
if (!opts) {
Expand Down
28 changes: 26 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,41 @@ export type {
} from './definitions';
export { FakerError } from './errors/faker-error';
export type { FakerOptions, UsableLocale, UsedLocales } from './faker';
export type { AddressModule } from './modules/address';
export type { AnimalModule } from './modules/animal';
export type {
Casing,
ColorFormat,
ColorModule,
CSSFunction,
CSSSpace,
NumberColorFormat,
StringColorFormat,
} from './modules/color';
export type { CommerceModule } from './modules/commerce';
export type { CompanyModule } from './modules/company';
export type { DatabaseModule } from './modules/database';
export type { DatatypeModule } from './modules/datatype';
export type { DateModule } from './modules/date';
export type { FakeModule } from './modules/fake';
export type { FinanceModule } from './modules/finance';
export type { GitModule } from './modules/git';
export type { HackerModule } from './modules/hacker';
export type { HelpersModule } from './modules/helpers';
export type { ImageModule } from './modules/image';
export type { InternetModule } from './modules/internet';
export type { LoremModule } from './modules/lorem';
export type { MersenneModule } from './modules/mersenne';
export type { MusicModule } from './modules/music';
export { Gender, Sex } from './modules/name';
export type { GenderType, SexType } from './modules/name';
export type { ChemicalElement, Unit } from './modules/science';
export type { GenderType, NameModule, SexType } from './modules/name';
export type { PhoneModule } from './modules/phone';
export type { RandomModule } from './modules/random';
export type { ChemicalElement, ScienceModule, Unit } from './modules/science';
export type { SystemModule } from './modules/system';
export type { UniqueModule } from './modules/unique';
export type { VehicleModule } from './modules/vehicle';
export type { WordModule } from './modules/word';
export { Faker };

// since we are requiring the top level of faker, load all locales by default
Expand Down
4 changes: 2 additions & 2 deletions src/modules/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { deprecated } from '../../internal/deprecated';
/**
* Module to generate addresses and locations.
*/
export class Address {
export class AddressModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Address.prototype)) {
for (const name of Object.getOwnPropertyNames(AddressModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/animal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Faker } from '../..';
/**
* Module to generate animal related entries.
*/
export class Animal {
export class AnimalModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Animal.prototype)) {
for (const name of Object.getOwnPropertyNames(AnimalModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/color/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ function toColorFormat(
/**
* Module to generate colors.
*/
export class Color {
export class ColorModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Color.prototype)) {
for (const name of Object.getOwnPropertyNames(ColorModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/commerce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { deprecated } from '../../internal/deprecated';
/**
* Module to generate commerce and product related entries.
*/
export class Commerce {
export class CommerceModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Commerce.prototype)) {
for (const name of Object.getOwnPropertyNames(CommerceModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/company/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { deprecated } from '../../internal/deprecated';
/**
* Module to generate company related entries.
*/
export class Company {
export class CompanyModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Company.prototype)) {
for (const name of Object.getOwnPropertyNames(CompanyModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Faker } from '../..';
/**
* Module to generate database related entries.
*/
export class Database {
export class DatabaseModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Database.prototype)) {
for (const name of Object.getOwnPropertyNames(DatabaseModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { deprecated } from '../../internal/deprecated';
/**
* Module to generate various primitive values and data types.
*/
export class Datatype {
export class DatatypeModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Datatype.prototype)) {
for (const name of Object.getOwnPropertyNames(DatatypeModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
6 changes: 2 additions & 4 deletions src/modules/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ function toDate(date?: string | Date | number): Date {
/**
* Module to generate dates.
*/
// disabled until modules are renamed to something with a suffix
// eslint-disable-next-line @typescript-eslint/naming-convention
export class _Date {
export class DateModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(_Date.prototype)) {
for (const name of Object.getOwnPropertyNames(DateModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/fake/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { deprecated } from '../../internal/deprecated';
*
* @deprecated
*/
export class Fake {
export class FakeModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Fake.prototype)) {
for (const name of Object.getOwnPropertyNames(FakeModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import iban from './iban';
/**
* Module to generate finance related entries.
*/
export class Finance {
export class FinanceModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Finance.prototype)) {
for (const name of Object.getOwnPropertyNames(FinanceModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Faker } from '../..';
/**
* Module to generate git related entries.
*/
export class Git {
export class GitModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Git.prototype)) {
for (const name of Object.getOwnPropertyNames(GitModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/hacker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Faker } from '../..';
/**
* Module to generate hacker/IT words and phrases.
*/
export class Hacker {
export class HackerModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Hacker.prototype)) {
for (const name of Object.getOwnPropertyNames(HackerModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import * as uniqueExec from './unique';
* Module with various helper methods that transform the method input rather than returning values from locales.
* The transformation process may call methods that use the locale data.
*/
export class Helpers {
export class HelpersModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Helpers.prototype)) {
for (const name of Object.getOwnPropertyNames(HelpersModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { Unsplash } from './providers/unsplash';
*
* Default provider is unsplash image provider.
*/
export class Image {
export class ImageModule {
readonly lorempixel: Lorempixel;
readonly unsplash: Unsplash;
readonly lorempicsum: LoremPicsum;
readonly placeholder: Placeholder;

constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Image.prototype)) {
for (const name of Object.getOwnPropertyNames(ImageModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down Expand Up @@ -46,7 +46,7 @@ export class Image {
* @since 2.0.1
*/
image(width?: number, height?: number, randomize?: boolean): string {
const categories: MethodsOf<Image, Image['image']> = [
const categories: MethodsOf<ImageModule, ImageModule['image']> = [
'abstract',
'animals',
'business',
Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export type HTTPStatusCodeType =
/**
* Module to generate internet related entries.
*/
export class Internet {
export class InternetModule {
constructor(private readonly faker: Faker) {
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Internet.prototype)) {
for (const name of Object.getOwnPropertyNames(InternetModule.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
Expand Down
Loading