UNPKG

gift-exchange

Version:

A utility to generate pairs of names for a gift exchange.

3 lines (2 loc) 1.21 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).GiftExchange={})}(this,function(e){"use strict";function n(e,n,t=[]){return e.length===n.length&&e.every((e,o)=>{const r=n[o];return e.name!==r.name&&((!e.group&&!r.group||e.group!==r.group)&&t.filter(n=>e[n.type]===n.subject).every(e=>r[e.excludedType]!==e.excludedSubject))})}e.calculate=function(e,t){var o,r;if(e.length<2)return e.slice(0);let i,u=1e3;Array.isArray(t)?i=t:(i=null!==(o=null==t?void 0:t.exclusions)&&void 0!==o?o:[],u=null!==(r=null==t?void 0:t.timeout)&&void 0!==r?r:1e3);let l=[],c=[];const f=()=>{const n=function(e){let n,t=e.length;for(;0!==t;){n=Math.floor(Math.random()*t),t-=1;const o=e[t];e[t]=e[n],e[n]=o}return e}(e.slice());l=n.slice(0),c=n.slice(0),c.push(c.shift())},s=Date.now(),a=(...e)=>{if(Date.now()-s>u){const e=new Error("No combinations found");throw e.name="GiftExchangeError",e}return n(...e)};for(f();!a(l,c,i);)f();return e.map(e=>{const n=l.findIndex(n=>n.name===e.name);return c[n]})},e.validateMatches=n}); //# sourceMappingURL=giftexchange.umd.production.js.map