@stacksjs/faker 0.70.369 → 0.70.371

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,8 +1,31 @@
1
1
  import { faker as baseFaker } from '@stacksjs/ts-faker';
2
- import type { Faker as BaseFaker } from '@stacksjs/ts-faker';
3
2
  declare function randomCount(range: NumberRange, minimum?: number): number;
4
3
  // datatype module for boolean, number generation (compatibility with @faker-js/faker)
5
4
  declare const datatype: DatatypeCompatibility;
5
+ declare const number: EnhancedNumber
6
+ number.int = (options?: number | { min?: number, max?: number, precision?: number }): number => {
7
+ return baseFaker.number.int(typeof options === 'number' ? { max: options } : options)
8
+ }
9
+ number.float = (options?: { min?: number, max?: number, precision?: number, fractionDigits?: number }): number => {
10
+ if (!options) return baseFaker.number.float()
11
+ const { fractionDigits, ...rest } = options
12
+ return baseFaker.number.float({
13
+ ...rest,
14
+ precision: rest.precision ?? fractionDigits,
15
+ })
16
+ };
17
+ declare const string: EnhancedString
18
+ string.alpha = (options?: number | { length?: number, casing?: 'upper' | 'lower' | 'mixed' }): string => {
19
+ return baseFaker.string.alpha(typeof options === 'number' ? { length: options } : options)
20
+ }
21
+ string.alphanumeric = (options?: number | { length?: number, casing?: 'upper' | 'lower' | 'mixed' }): string => {
22
+ return baseFaker.string.alphanumeric(typeof options === 'number' ? { length: options } : options)
23
+ };
24
+ declare const finance: EnhancedFinance
25
+ finance.creditCardNumber = (options?: string | { issuer?: string, formatted?: boolean }): string => {
26
+ if (typeof options !== 'string') return baseFaker.finance.creditCardNumber(options)
27
+ return options.replace(/#/g, () => baseFaker.string.numeric(1))
28
+ };
6
29
  /**
7
30
  * Keep seeded image URLs usable in real UI previews. The underlying faker's
8
31
  * generic URL still targets the retired via.placeholder.com service, so
@@ -63,13 +86,24 @@ export declare const faker: EnhancedFaker;
63
86
  * @stacksjs/ts-faker uses different module names, so we create aliases
64
87
  */
65
88
  declare interface DatatypeCompatibility {
66
- boolean: () => boolean
89
+ boolean: (options?: { probability?: number }) => boolean
67
90
  number: (options?: { min?: number; max?: number }) => number
68
91
  float: (options?: { min?: number; max?: number; precision?: number }) => number
69
92
  uuid: () => string
70
93
  string: (length?: number) => string
71
94
  array: <T>(generator: () => T, length?: number) => T[]
72
95
  }
96
+ declare interface NumberCompatibility {
97
+ int: (options?: number | { min?: number, max?: number, precision?: number }) => number
98
+ float: (options?: { min?: number, max?: number, precision?: number, fractionDigits?: number }) => number
99
+ }
100
+ declare interface StringCompatibility {
101
+ alpha: (options?: number | { length?: number, casing?: 'upper' | 'lower' | 'mixed' }) => string
102
+ alphanumeric: (options?: number | { length?: number, casing?: 'upper' | 'lower' | 'mixed' }) => string
103
+ }
104
+ declare interface FinanceCompatibility {
105
+ creditCardNumber: (options?: string | { issuer?: string, formatted?: boolean }) => string
106
+ }
73
107
  // company module enhancements
74
108
  declare interface CompanyCompatibility {
75
109
  name: () => string
@@ -94,6 +128,7 @@ declare interface HelpersCompatibility {
94
128
  maybe: <T>(callback: () => T, options?: { probability?: number }) => T | undefined
95
129
  objectKey: <T extends object>(obj: T) => keyof T
96
130
  objectValue: <T extends object>(obj: T) => T[keyof T]
131
+ slugify: (value: string) => string
97
132
  }
98
133
  /**
99
134
  * Enhanced lorem module with better API
@@ -124,10 +159,16 @@ declare interface FakerCompatibility {
124
159
  company: typeof company
125
160
  vehicle: typeof vehicle
126
161
  helpers: typeof helpers
162
+ number: typeof number
163
+ string: typeof string
164
+ finance: typeof finance
127
165
  }
166
+ declare type EnhancedNumber = Omit<typeof baseFaker.number, keyof NumberCompatibility> & NumberCompatibility;
167
+ declare type EnhancedString = Omit<typeof baseFaker.string, keyof StringCompatibility> & StringCompatibility;
168
+ declare type EnhancedFinance = Omit<typeof baseFaker.finance, keyof FinanceCompatibility> & FinanceCompatibility;
128
169
  declare type EnhancedCompany = Omit<typeof baseFaker.company, keyof CompanyCompatibility> & CompanyCompatibility;
129
170
  declare type EnhancedVehicle = Omit<typeof baseFaker.vehicle, keyof VehicleCompatibility> & VehicleCompatibility;
130
171
  declare type EnhancedHelpers = Omit<typeof baseFaker.helpers, keyof HelpersCompatibility> & HelpersCompatibility;
131
172
  declare type EnhancedLorem = Omit<typeof baseFaker.lorem, keyof LoremCompatibility> & LoremCompatibility;
132
- declare type EnhancedFaker = Omit<typeof baseFaker, keyof FakerCompatibility> & FakerCompatibility;
133
- export type Faker = BaseFaker;
173
+ export type EnhancedFaker = Omit<typeof baseFaker, keyof FakerCompatibility> & FakerCompatibility;
174
+ export type Faker = EnhancedFaker;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
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??`
2
+ import{faker as z}from"@stacksjs/ts-faker";var T={boolean(q){return z.random.boolean(q?.probability)},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 G=[],H=B??z.number.int({min:1,max:10});for(let J=0;J<H;J++)G.push(q());return G}},K=Object.create(z.number);K.int=(q)=>{return z.number.int(typeof q==="number"?{max:q}:q)};K.float=(q)=>{if(!q)return z.number.float();let{fractionDigits:B,...G}=q;return z.number.float({...G,precision:G.precision??B})};var M=Object.create(z.string);M.alpha=(q)=>{return z.string.alpha(typeof q==="number"?{length:q}:q)};M.alphanumeric=(q)=>{return z.string.alphanumeric(typeof q==="number"?{length:q}:q)};var O=Object.create(z.finance);O.creditCardNumber=(q)=>{if(typeof q!=="string")return z.finance.creditCardNumber(q);return q.replace(/#/g,()=>z.string.numeric(1))};var Q=Object.create(z.image);Q.url=(q)=>{let B=q?.width??640,G=q?.height??480;return`https://picsum.photos/seed/${z.string.alphanumeric({length:12}).toLowerCase()}/${B}/${G}`};var U={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()}},V={...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)}},X={...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 G=0;G<17;G++)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"}},R={...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 G=B??Math.floor(Math.random()*q.length)+1;return R.shuffle(q).slice(0,Math.min(G,q.length))},shuffle(q){let B=[...q];for(let G=B.length-1;G>0;G--){let H=Math.floor(Math.random()*(G+1)),J=B[G],S=B[H];B[G]=S,B[H]=J}return B},maybe(q,B){let G=B?.probability??0.5;return Math.random()<G?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)]},slugify(q){return q.normalize("NFKD").replace(/[\u0300-\u036F]/g,"").toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}};function N(q,B=1){let G=Math.max(B,Math.floor(Math.min(q.min,q.max))),H=Math.max(G,Math.floor(Math.max(q.min,q.max)));return Math.floor(Math.random()*(H-G+1))+G}var Y={...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(N(q));if(q!==void 0){let B=Math.max(1,Math.floor(q)),G=Math.min(3,B),H=Math.floor(Math.random()*(B-G+1))+G;return z.lorem.sentence(H)}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 G=typeof q==="object"?N(q):q??3;return z.lorem.paragraphs(G,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)}},V={...z,lorem:T,datatype:O,image:K,location:Q,company:R,vehicle:S,helpers:M};export{V 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)}},_={...z,lorem:Y,datatype:T,image:Q,location:U,company:V,vehicle:X,helpers:R,number:K,string:M,finance:O};export{_ 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.369",
4
+ "version": "0.70.371",
5
5
  "description": "Faker functions.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -58,8 +58,8 @@
58
58
  "prepublishOnly": "bun run build"
59
59
  },
60
60
  "devDependencies": {
61
- "@stacksjs/cli": "0.70.369",
62
- "@stacksjs/config": "0.70.369",
61
+ "@stacksjs/cli": "0.70.371",
62
+ "@stacksjs/config": "0.70.371",
63
63
  "better-dx": "^0.2.17",
64
64
  "@stacksjs/ts-faker": "^0.1.7"
65
65
  },