@noeldemartin/faker
Version:
Generate massive amounts of fake contextual data
7 lines (5 loc) • 1.56 kB
JavaScript
;var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var T=(t,r)=>{for(var e in r)s(t,e,{get:r[e],enumerable:!0})},h=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of l(r))!b.call(t,n)&&n!==e&&s(t,n,{get:()=>r[n],enumerable:!(o=f(r,n))||o.enumerable});return t};var g=t=>h(s({},"__esModule",{value:!0}),t);var M={};T(M,{exec:()=>K});module.exports=g(M);var x=require("../../errors/faker-error");const I={},E=[];function w(t,r){return t[r]===void 0?-1:0}function R(t,r,e,o,n){throw console.error("Error",e),console.log(`Found ${Object.keys(o).length} unique entries before throwing error.
retried: ${n}
total time: ${r-t}ms`),new x.FakerError(`${e} for uniqueness check.
May not be able to generate any more unique values with current settings.
Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`)}function K(t,r,e={}){var y;const o=new Date().getTime(),{startTime:n=new Date().getTime(),maxTime:d=50,maxRetries:i=50,compare:m=w,store:a=I}=e;let{exclude:c=E}=e;if(e.currentIterations=(y=e.currentIterations)!=null?y:0,Array.isArray(c)||(c=[c]),o-n>=d)return R(n,o,`Exceeded maxTime: ${d}`,a,e.currentIterations);if(e.currentIterations>=i)return R(n,o,`Exceeded maxRetries: ${i}`,a,e.currentIterations);const u=t.apply(this,r);return m(a,u)===-1&&c.indexOf(u)===-1?(a[u]=u,e.currentIterations=0,u):(e.currentIterations++,K(t,r,{...e,startTime:n,maxTime:d,maxRetries:i,compare:m,exclude:c}))}0&&(module.exports={exec});