@noeldemartin/faker
Version:
Generate massive amounts of fake contextual data
2 lines (1 loc) • 2.86 kB
JavaScript
;var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=(m,e)=>{for(var r in e)u(m,r,{get:e[r],enumerable:!0})},h=(m,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!f.call(m,t)&&t!==r&&u(m,t,{get:()=>e[t],enumerable:!(n=l(e,t))||n.enumerable});return m};var d=m=>h(u({},"__esModule",{value:!0}),m);var p={};g(p,{DatatypeModule:()=>b});module.exports=d(p);var x=require("../../errors/faker-error"),s=require("../../internal/deprecated");class b{constructor(e){this.faker=e;for(const r of Object.getOwnPropertyNames(b.prototype))r==="constructor"||typeof this[r]!="function"||(this[r]=this[r].bind(this))}number(e=99999){var a;typeof e=="number"&&(e={max:e});const{min:r=0,precision:n=1}=e,t=(a=e.max)!=null?a:r+99999;if(t===r)return r;if(t<r)throw new x.FakerError(`Max ${t} should be greater than min ${r}.`);return Math.floor(this.faker.mersenne.rand(t/n+1,r/n))/(1/n)}float(e){typeof e=="number"&&(e={precision:e}),e=e||{};const r={};for(const n in e)r[n]=e[n];return r.precision==null&&(r.precision=.01),this.number(r)}datetime(e={}){let n=typeof e=="number"?void 0:e.min,t=typeof e=="number"?e:e.max;return(n==null||n<864e13*-1)&&(n=Date.UTC(1990,0)),(t==null||t>864e13)&&(t=Date.UTC(2100,0)),new Date(this.number({min:n,max:t}))}string(e=10){const r=Math.pow(2,20);e>=r&&(e=r);const n={min:33,max:125};let t="";for(let i=0;i<e;i++)t+=String.fromCharCode(this.number(n));return t}uuid(){const e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",r=n=>{const t=this.number({min:0,max:15});return(n==="x"?t:t&3|8).toString(16)};return e.replace(/[xy]/g,r)}boolean(){return!!this.number(1)}hexadecimal(e={}){typeof e=="number"&&((0,s.deprecated)({deprecated:"faker.datatype.hexadecimal(length)",proposed:"faker.datatype.hexadecimal({ length })",since:"7.5",until:"8.0"}),e={length:e});const{length:r=1,prefix:n="0x",case:t="mixed"}=e;let i="";for(let a=0;a<r;a++)i+=this.faker.helpers.arrayElement(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","A","B","C","D","E","F"]);return t==="upper"?i=i.toUpperCase():t==="lower"&&(i=i.toLowerCase()),`${n}${i}`}json(){const e=["foo","bar","bike","a","b","name","prop"],r={};return e.forEach(n=>{r[n]=this.boolean()?this.string():this.number()}),JSON.stringify(r)}array(e=10){return Array.from({length:e}).map(()=>this.boolean()?this.string():this.number())}bigInt(e){var a,o;let r,n;if(typeof e=="object"?(r=BigInt((a=e.min)!=null?a:0),n=BigInt((o=e.max)!=null?o:r+BigInt(999999999999999))):(r=BigInt(0),n=BigInt(e!=null?e:999999999999999)),n===r)return r;if(n<r)throw new x.FakerError(`Max ${n} should be larger then min ${r}.`);const t=n-r,i=BigInt(this.faker.random.numeric(t.toString(10).length,{allowLeadingZeros:!0}))%(t+BigInt(1));return r+i}}0&&(module.exports={DatatypeModule});