UNPKG

@automattic/calypso-products

Version:

This module contains information about the various products sold within calypso, such as product slugs, plan intervals, etc.

26 lines 1.12 kB
import { getProductFromSlug } from './get-product-from-slug'; /** * Matches plan specified by `productSlug` against `query`. * Only compares `type` and `term` properties. * * For example: * * > productMatches( PRODUCT_JETPACK_BACKUP_DAILY, { term: TERM_ANNUALLY, type: PRODUCT_JETPACK_BACKUP_DAILY } ); * true * * > productMatches( PRODUCT_JETPACK_BACKUP_DAILY, { term: TERM_BIENNIALLY } ); * false */ export function productMatches(productSlug, query = {}) { const acceptedKeys = ['type', 'term']; const unknownKeys = Object.keys(query).filter((key) => !acceptedKeys.includes(key)); if (unknownKeys.length) { throw new Error(`productMatches can only match against ${acceptedKeys.join(',')}, ` + `but unknown keys ${unknownKeys.join(',')} were passed.`); } const planFromSlug = getProductFromSlug(productSlug); const plan = typeof planFromSlug === 'string' ? { term: '', type: '' } : planFromSlug; return ((query.term ? plan.term === query.term : true) && (query.type ? plan.type === query.type : true)); } //# sourceMappingURL=product-matches.js.map