@automattic/calypso-products
Version:
This module contains information about the various products sold within calypso, such as product slugs, plan intervals, etc.
29 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.productMatches = productMatches;
const get_product_from_slug_1 = require("./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
*/
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 = (0, get_product_from_slug_1.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