Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ythub/quota-matcher

YouThinkResearch32UNLICENSED1.2.15TypeScript support: included

Hub quota matcher utils

readme

This package is related to the Hub quotas. It contains utils which intended to evaluate which quotas are matching and which are not.

Usage example:

import { matchQuotasWithRespondent, QuotaMatchResult } from '@ythub/quota-matcher'

const ageQualificationId = '304';
const genderQualificationId = '197';

const outcome = matchQuotasWithRespondent(
  // Respondent collection
  {
    [ageQualificationId]: 22,
    [genderQualificationId]: 1857 /* male */
  },
  // Survey quotas collection
  {
    id: 1,
    name: 'Male 18-24',
    remainingCompletes: 10,
    isMandatory: true,
    isEnabled: true,
    conditions: [
      {
        range: [{ to: 24, from: 18 }],
        property: ageProperty,
      },
      {
        options: [1857],
        property: genderProperty,
      },
    ],
  }
)

switch (outcome.matchResult) {
  case QuotaMatchResult.Eligible:
    // outcome.eligibleQuotas
    // ... do something
    break
  case QuotaMatchResult.Ineligible:
  case QuotaMatchResult.Uncertain:
    // ...
}