@stacksjs/faker 0.70.229 → 0.70.230

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  import { faker as baseFaker } from '@stacksjs/ts-faker';
2
2
  import type { Faker as BaseFaker } from '@stacksjs/ts-faker';
3
+ declare function randomCount(range: NumberRange, minimum?: number): number;
3
4
  // datatype module for boolean, number generation (compatibility with @faker-js/faker)
4
5
  declare const datatype: DatatypeCompatibility;
6
+ /**
7
+ * Keep seeded image URLs usable in real UI previews. The underlying faker's
8
+ * generic URL still targets the retired via.placeholder.com service, so
9
+ * factories otherwise persist broken images into commerce and content data.
10
+ */
11
+ declare const image: typeof baseFaker.image
12
+ image.url = (options?: { width?: number, height?: number }): string => {
13
+ const width = options?.width ?? 640
14
+ const height = options?.height ?? 480
15
+ const seed = baseFaker.string.alphanumeric({ length: 12 }).toLowerCase()
16
+
17
+ return `https://picsum.photos/seed/${seed}/${width}/${height}`
18
+ };
5
19
  /**
6
20
  * location module (alias to address for @faker-js/faker compatibility)
7
21
  * @defaultValue
@@ -87,20 +101,25 @@ declare interface HelpersCompatibility {
87
101
  declare interface LoremCompatibility {
88
102
  word: () => string
89
103
  words: (count?: number) => string
90
- sentence: (maxWords?: number) => string
104
+ sentence: (wordCount?: number | NumberRange) => string
91
105
  sentences: (count?: number, separator?: string) => string
92
106
  paragraph: (sentenceCount?: number) => string
93
- paragraphs: (count?: number, separator?: string) => string
107
+ paragraphs: (count?: number | NumberRange, separator?: string) => string
94
108
  text: (length?: number) => string
95
109
  slug: (wordCount?: number) => string
96
110
  lines: (count?: number) => string
97
111
  }
112
+ declare interface NumberRange {
113
+ min: number
114
+ max: number
115
+ }
98
116
  /**
99
117
  * Enhanced faker instance with improved lorem API and @faker-js/faker compatibility
100
118
  */
101
119
  declare interface FakerCompatibility {
102
120
  lorem: typeof enhancedLorem
103
121
  datatype: typeof datatype
122
+ image: typeof image
104
123
  location: typeof location
105
124
  company: typeof company
106
125
  vehicle: typeof vehicle
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{faker as z}from"@stacksjs/ts-faker";var M={boolean(){return z.random.boolean()},number(q){return z.number.int({min:q?.min??0,max:q?.max??100})},float(q){return z.number.float({min:q?.min??0,max:q?.max??1,precision:q?.precision??2})},uuid(){return z.string.uuid()},string(q){return z.string.alphanumeric({length:q??10})},array(q,B){let D=[],G=B??z.number.int({min:1,max:10});for(let H=0;H<G;H++)D.push(q());return D}},N={street(){return z.address.street()},streetAddress(q){return z.address.streetAddress({useFullAddress:q})},city(){return z.address.city()},state(){return z.address.state()},stateAbbr(){return z.address.stateAbbr()},country(){return z.address.country()},countryCode(){return z.address.countryCode()},zipCode(){return z.address.zipCode()},latitude(q){return z.address.latitude(q)},longitude(q){return z.address.longitude(q)},direction(){return z.address.direction()},buildingNumber(){return z.address.buildingNumber()}},O={...z.company,name(){return z.company.name()},catchPhrase(){let q=z.company;return q.buzzPhrase?.()??q.catchphrase?.()??`${z.word.adjective()} ${z.word.noun()}`},buzzPhrase(){return z.company.buzzPhrase?.()??z.lorem.sentence(3)}},Q={...z.vehicle,vrm(){return`${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"0123456789"[Math.floor(Math.random()*10)]}${"0123456789"[Math.floor(Math.random()*10)]} ${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}`},vehicle(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes","Audi","Tesla","Nissan","Hyundai"],B=["Sedan","SUV","Truck","Coupe","Hatchback","Wagon","Van","Crossover"];return`${q[Math.floor(Math.random()*q.length)]} ${B[Math.floor(Math.random()*B.length)]}`},type(){let q=["Sedan","SUV","Truck","Van","Coupe","Convertible","Wagon","Hatchback"];return q[Math.floor(Math.random()*q.length)]??"Sedan"},manufacturer(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes-Benz","Audi","Tesla","Nissan","Hyundai","Kia","Volkswagen"];return q[Math.floor(Math.random()*q.length)]??"Toyota"},model(){let q=["Camry","Accord","F-150","Silverado","3 Series","C-Class","A4","Model 3","Altima","Elantra"];return q[Math.floor(Math.random()*q.length)]??"Camry"},fuel(){let q=["Gasoline","Diesel","Electric","Hybrid","Plug-in Hybrid"];return q[Math.floor(Math.random()*q.length)]??"Gasoline"},vin(){let B="";for(let D=0;D<17;D++)B+="0123456789ABCDEFGHJKLMNPRSTUVWXYZ"[Math.floor(Math.random()*33)];return B},color(){let q=["Black","White","Silver","Gray","Red","Blue","Green","Brown","Orange","Yellow"];return q[Math.floor(Math.random()*q.length)]??"Black"}},J={...z.helpers,arrayElement(q){if(q.length===0)throw Error("arrayElement: cannot pick from an empty array");return q[Math.floor(Math.random()*q.length)]},arrayElements(q,B){let D=B??Math.floor(Math.random()*q.length)+1;return J.shuffle(q).slice(0,Math.min(D,q.length))},shuffle(q){let B=[...q];for(let D=B.length-1;D>0;D--){let G=Math.floor(Math.random()*(D+1)),H=B[D],K=B[G];B[D]=K,B[G]=H}return B},maybe(q,B){let D=B?.probability??0.5;return Math.random()<D?q():void 0},objectKey(q){let B=Object.keys(q);if(B.length===0)throw Error("objectKey: object has no keys");return B[Math.floor(Math.random()*B.length)]},objectValue(q){let B=Object.values(q);if(B.length===0)throw Error("objectValue: object has no values");return B[Math.floor(Math.random()*B.length)]}},R={...z.lorem,word(){return z.lorem.word()},words(q){return z.lorem.words(q??3)},sentence(q){if(q!==void 0){let B=Math.min(3,q),D=Math.floor(Math.random()*(q-B+1))+B;return z.lorem.sentence(D)}return z.lorem.sentence()},sentences(q,B){return z.lorem.sentences(q??3,B??" ")},paragraph(q){return z.lorem.paragraph(q)},paragraphs(q,B){return z.lorem.paragraphs(q??3,B??`
2
+ import{faker as z}from"@stacksjs/ts-faker";var O={boolean(){return z.random.boolean()},number(q){return z.number.int({min:q?.min??0,max:q?.max??100})},float(q){return z.number.float({min:q?.min??0,max:q?.max??1,precision:q?.precision??2})},uuid(){return z.string.uuid()},string(q){return z.string.alphanumeric({length:q??10})},array(q,B){let D=[],G=B??z.number.int({min:1,max:10});for(let H=0;H<G;H++)D.push(q());return D}},K=Object.create(z.image);K.url=(q)=>{let B=q?.width??640,D=q?.height??480;return`https://picsum.photos/seed/${z.string.alphanumeric({length:12}).toLowerCase()}/${B}/${D}`};var Q={street(){return z.address.street()},streetAddress(q){return z.address.streetAddress({useFullAddress:q})},city(){return z.address.city()},state(){return z.address.state()},stateAbbr(){return z.address.stateAbbr()},country(){return z.address.country()},countryCode(){return z.address.countryCode()},zipCode(){return z.address.zipCode()},latitude(q){return z.address.latitude(q)},longitude(q){return z.address.longitude(q)},direction(){return z.address.direction()},buildingNumber(){return z.address.buildingNumber()}},R={...z.company,name(){return z.company.name()},catchPhrase(){let q=z.company;return q.buzzPhrase?.()??q.catchphrase?.()??`${z.word.adjective()} ${z.word.noun()}`},buzzPhrase(){return z.company.buzzPhrase?.()??z.lorem.sentence(3)}},S={...z.vehicle,vrm(){return`${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"0123456789"[Math.floor(Math.random()*10)]}${"0123456789"[Math.floor(Math.random()*10)]} ${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}${"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(Math.random()*26)]}`},vehicle(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes","Audi","Tesla","Nissan","Hyundai"],B=["Sedan","SUV","Truck","Coupe","Hatchback","Wagon","Van","Crossover"];return`${q[Math.floor(Math.random()*q.length)]} ${B[Math.floor(Math.random()*B.length)]}`},type(){let q=["Sedan","SUV","Truck","Van","Coupe","Convertible","Wagon","Hatchback"];return q[Math.floor(Math.random()*q.length)]??"Sedan"},manufacturer(){let q=["Toyota","Honda","Ford","Chevrolet","BMW","Mercedes-Benz","Audi","Tesla","Nissan","Hyundai","Kia","Volkswagen"];return q[Math.floor(Math.random()*q.length)]??"Toyota"},model(){let q=["Camry","Accord","F-150","Silverado","3 Series","C-Class","A4","Model 3","Altima","Elantra"];return q[Math.floor(Math.random()*q.length)]??"Camry"},fuel(){let q=["Gasoline","Diesel","Electric","Hybrid","Plug-in Hybrid"];return q[Math.floor(Math.random()*q.length)]??"Gasoline"},vin(){let B="";for(let D=0;D<17;D++)B+="0123456789ABCDEFGHJKLMNPRSTUVWXYZ"[Math.floor(Math.random()*33)];return B},color(){let q=["Black","White","Silver","Gray","Red","Blue","Green","Brown","Orange","Yellow"];return q[Math.floor(Math.random()*q.length)]??"Black"}},M={...z.helpers,arrayElement(q){if(q.length===0)throw Error("arrayElement: cannot pick from an empty array");return q[Math.floor(Math.random()*q.length)]},arrayElements(q,B){let D=B??Math.floor(Math.random()*q.length)+1;return M.shuffle(q).slice(0,Math.min(D,q.length))},shuffle(q){let B=[...q];for(let D=B.length-1;D>0;D--){let G=Math.floor(Math.random()*(D+1)),H=B[D],N=B[G];B[D]=N,B[G]=H}return B},maybe(q,B){let D=B?.probability??0.5;return Math.random()<D?q():void 0},objectKey(q){let B=Object.keys(q);if(B.length===0)throw Error("objectKey: object has no keys");return B[Math.floor(Math.random()*B.length)]},objectValue(q){let B=Object.values(q);if(B.length===0)throw Error("objectValue: object has no values");return B[Math.floor(Math.random()*B.length)]}};function J(q,B=1){let D=Math.max(B,Math.floor(Math.min(q.min,q.max))),G=Math.max(D,Math.floor(Math.max(q.min,q.max)));return Math.floor(Math.random()*(G-D+1))+D}var T={...z.lorem,word(){return z.lorem.word()},words(q){return z.lorem.words(q??3)},sentence(q){if(typeof q==="object")return z.lorem.sentence(J(q));if(q!==void 0){let B=Math.max(1,Math.floor(q)),D=Math.min(3,B),G=Math.floor(Math.random()*(B-D+1))+D;return z.lorem.sentence(G)}return z.lorem.sentence()},sentences(q,B){return z.lorem.sentences(q??3,B??" ")},paragraph(q){return z.lorem.paragraph(q)},paragraphs(q,B){let D=typeof q==="object"?J(q):q??3;return z.lorem.paragraphs(D,B??`
3
3
 
4
- `)},text(q){return z.lorem.text(q)},slug(q){return z.lorem.slug(q??3)},lines(q){return z.lorem.lines(q??3)}},T={...z,lorem:R,datatype:M,location:N,company:O,vehicle:Q,helpers:J};export{T as faker};
4
+ `)},text(q){return z.lorem.text(q)},slug(q){return z.lorem.slug(q??3)},lines(q){return z.lorem.lines(q??3)}},V={...z,lorem:T,datatype:O,image:K,location:Q,company:R,vehicle:S,helpers:M};export{V as faker};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/faker",
3
3
  "type": "module",
4
- "version": "0.70.229",
4
+ "version": "0.70.230",
5
5
  "description": "Faker functions.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -53,8 +53,8 @@
53
53
  "prepublishOnly": "bun run build"
54
54
  },
55
55
  "devDependencies": {
56
- "@stacksjs/cli": "0.70.229",
57
- "@stacksjs/config": "0.70.229",
56
+ "@stacksjs/cli": "0.70.230",
57
+ "@stacksjs/config": "0.70.230",
58
58
  "better-dx": "^0.2.17",
59
59
  "@stacksjs/ts-faker": "^0.1.7"
60
60
  },