UNPKG

@noeldemartin/faker

Version:

Generate massive amounts of fake contextual data

2 lines (1 loc) 2.46 kB
"use strict";var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(i,e)=>{for(var r in e)o(i,r,{get:e[r],enumerable:!0})},f=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!p.call(i,n)&&n!==r&&o(i,n,{get:()=>e[n],enumerable:!(t=g(e,n))||t.enumerable});return i};var d=i=>f(o({},"__esModule",{value:!0}),i);var U={};c(U,{ImageModule:()=>a});module.exports=d(U);var m=require("./providers/lorempicsum"),l=require("./providers/lorempixel"),u=require("./providers/placeholder"),b=require("./providers/unsplash");class a{constructor(e){this.faker=e;for(const r of Object.getOwnPropertyNames(a.prototype))r==="constructor"||typeof this[r]!="function"||(this[r]=this[r].bind(this));this.lorempixel=new l.Lorempixel(this.faker),this.unsplash=new b.Unsplash(this.faker),this.lorempicsum=new m.LoremPicsum(this.faker),this.placeholder=new u.Placeholder(this.faker)}image(e,r,t){const n=["abstract","animals","business","cats","city","food","nightlife","fashion","people","nature","sports","technics","transport"];return this[this.faker.helpers.arrayElement(n)](e,r,t)}avatar(){return this.faker.internet.avatar()}imageUrl(e,r,t,n){e=e||640,r=r||480;let s=`https://loremflickr.com/${e}/${r}`;return t!=null&&(s+=`/${t}`),n&&(s+=`?lock=${this.faker.datatype.number()}`),s}abstract(e,r,t){return this.imageUrl(e,r,"abstract",t)}animals(e,r,t){return this.imageUrl(e,r,"animals",t)}business(e,r,t){return this.imageUrl(e,r,"business",t)}cats(e,r,t){return this.imageUrl(e,r,"cats",t)}city(e,r,t){return this.imageUrl(e,r,"city",t)}food(e,r,t){return this.imageUrl(e,r,"food",t)}nightlife(e,r,t){return this.imageUrl(e,r,"nightlife",t)}fashion(e,r,t){return this.imageUrl(e,r,"fashion",t)}people(e,r,t){return this.imageUrl(e,r,"people",t)}nature(e,r,t){return this.imageUrl(e,r,"nature",t)}sports(e,r,t){return this.imageUrl(e,r,"sports",t)}technics(e,r,t){return this.imageUrl(e,r,"technics",t)}transport(e,r,t){return this.imageUrl(e,r,"transport",t)}dataUri(e,r,t="grey"){const n=`<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="${e}" height="${r}"><rect width="100%" height="100%" fill="${t}"/><text x="${e/2}" y="${r/2}" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">${e}x${r}</text></svg>`;return"data:image/svg+xml;charset=UTF-8,"+encodeURIComponent(n)}}0&&(module.exports={ImageModule});