@stacksjs/faker
Version:
134 lines (132 loc) • 5.12 kB
TypeScript
import { faker as baseFaker } from '@stacksjs/ts-faker';
import type { Faker as BaseFaker } from '@stacksjs/ts-faker';
declare function randomCount(range: NumberRange, minimum?: number): number;
// datatype module for boolean, number generation (compatibility with @faker-js/faker)
declare const datatype: DatatypeCompatibility;
/**
* Keep seeded image URLs usable in real UI previews. The underlying faker's
* generic URL still targets the retired via.placeholder.com service, so
* factories otherwise persist broken images into commerce and content data.
*/
declare const image: typeof baseFaker.image
image.url = (options?: { width?: number, height?: number }): string => {
const width = options?.width ?? 640
const height = options?.height ?? 480
const seed = baseFaker.string.alphanumeric({ length: 12 }).toLowerCase()
return `https://picsum.photos/seed/${seed}/${width}/${height}`
};
/**
* location module (alias to address for @faker-js/faker compatibility)
* @defaultValue
* ```ts
* {
* street: () => string,
* streetAddress: (useFullAddress?: boolean) => string,
* city: () => string,
* state: () => string,
* stateAbbr: () => string,
* country: () => string,
* countryCode: () => string,
* zipCode: () => string,
* latitude: (options?: { min?: number; max?: number; precision?: number }) => number,
* longitude: (options?: { min?: number; max?: number; precision?: number }) => number,
* direction: () => string,
* buildingNumber: () => string
* }
* ```
*/
declare const location: {
street: () => string;
streetAddress: (useFullAddress?: boolean) => string;
city: () => string;
state: () => string;
stateAbbr: () => string;
country: () => string;
countryCode: () => string;
zipCode: () => string;
latitude: (options?: { min?: number; max?: number; precision?: number }) => number;
longitude: (options?: { min?: number; max?: number; precision?: number }) => number;
direction: () => string;
buildingNumber: () => string
};
declare const company: EnhancedCompany;
declare const vehicle: EnhancedVehicle;
// helpers module enhancements for @faker-js/faker compatibility
// Keep this annotation explicit. bun-plugin-dtsx cannot reliably infer a
// declaration for a spread object that also contains documented generic methods.
declare const helpers: EnhancedHelpers;
declare const enhancedLorem: EnhancedLorem;
export declare const faker: EnhancedFaker;
/**
* Compatibility layer for @faker-js/faker API
* @stacksjs/ts-faker uses different module names, so we create aliases
*/
declare interface DatatypeCompatibility {
boolean: () => boolean
number: (options?: { min?: number; max?: number }) => number
float: (options?: { min?: number; max?: number; precision?: number }) => number
uuid: () => string
string: (length?: number) => string
array: <T>(generator: () => T, length?: number) => T[]
}
// company module enhancements
declare interface CompanyCompatibility {
name: () => string
catchPhrase: () => string
buzzPhrase: () => string
}
// vehicle module enhancements
declare interface VehicleCompatibility {
vrm: () => string
vehicle: () => string
type: () => string
manufacturer: () => string
model: () => string
fuel: () => string
vin: () => string
color: () => string
}
declare interface HelpersCompatibility {
arrayElement: <T>(array: T[]) => T
arrayElements: <T>(array: T[], count?: number) => T[]
shuffle: <T>(array: T[]) => T[]
maybe: <T>(callback: () => T, options?: { probability?: number }) => T | undefined
objectKey: <T extends object>(obj: T) => keyof T
objectValue: <T extends object>(obj: T) => T[keyof T]
}
/**
* Enhanced lorem module with better API
*/
declare interface LoremCompatibility {
word: () => string
words: (count?: number) => string
sentence: (wordCount?: number | NumberRange) => string
sentences: (count?: number, separator?: string) => string
paragraph: (sentenceCount?: number) => string
paragraphs: (count?: number | NumberRange, separator?: string) => string
text: (length?: number) => string
slug: (wordCount?: number) => string
lines: (count?: number) => string
}
declare interface NumberRange {
min: number
max: number
}
/**
* Enhanced faker instance with improved lorem API and @faker-js/faker compatibility
*/
declare interface FakerCompatibility {
lorem: typeof enhancedLorem
datatype: typeof datatype
image: typeof image
location: typeof location
company: typeof company
vehicle: typeof vehicle
helpers: typeof helpers
}
declare type EnhancedCompany = Omit<typeof baseFaker.company, keyof CompanyCompatibility> & CompanyCompatibility;
declare type EnhancedVehicle = Omit<typeof baseFaker.vehicle, keyof VehicleCompatibility> & VehicleCompatibility;
declare type EnhancedHelpers = Omit<typeof baseFaker.helpers, keyof HelpersCompatibility> & HelpersCompatibility;
declare type EnhancedLorem = Omit<typeof baseFaker.lorem, keyof LoremCompatibility> & LoremCompatibility;
declare type EnhancedFaker = Omit<typeof baseFaker, keyof FakerCompatibility> & FakerCompatibility;
export type Faker = BaseFaker;