gift-exchange
Version:
A utility to generate pairs of names for a gift exchange.
38 lines (37 loc) • 1.25 kB
TypeScript
export interface Person {
name: string;
group?: string;
}
export interface Exclusion {
/**
* Which property on the Person interface the `subject` refers to when
* selecting the current person.
*
* @example 'name' or 'group'
*/
type: keyof Person;
/**
* The value of the given type to select the current person.
* Internally, we use `person[exclusion.type] === exclusion.subject` to select
* the current person.
*/
subject: string;
/**
* Which property on the Person interface the `subject` refers to when
* selecting the excluded person.
*
* @example 'name' or 'group'
*/
excludedType: keyof Person;
/**
* The value of the given type to select the current person.
* Internally, we use `person[exclusion.excludedType] !== exclusion.excludedSubject`
* to check if a the current person is allowed to match with the exclusion rule
*/
excludedSubject: string;
}
export declare function validateMatches(a: Person[], b: Person[], exclusions?: Exclusion[]): boolean;
export declare function calculate(people: Person[], exclusionsOrOptions?: {
exclusions?: Exclusion[];
timeout?: number;
} | Exclusion[]): Person[];