File "assertions.js"
Full Path: /home/vantageo/public_html/cache/cache/cache/cache/cache/cache/.wp-cli/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/blocks-registry/payment-methods/assertions.js
File size: 1.33 KB
MIME-type: text/x-java
Charset: utf-8
/**
* External dependencies
*/
import { isValidElement } from '@wordpress/element';
export const assertValidPaymentMethodComponent = (
component,
componentName
) => {
if ( typeof component !== 'function' ) {
throw new TypeError(
`The ${ componentName } property for the payment method must be a functional component`
);
}
};
export const assertValidElement = ( element, elementName ) => {
if ( element !== null && ! isValidElement( element ) ) {
throw new TypeError(
`The ${ elementName } property for the payment method must be a React element or null.`
);
}
};
export const assertValidElementOrString = ( element, elementName ) => {
if (
element !== null &&
! isValidElement( element ) &&
typeof element !== 'string'
) {
throw new TypeError(
`The ${ elementName } property for the payment method must be a React element, a string, or null.`
);
}
};
export const assertConfigHasProperties = (
config,
expectedProperties = []
) => {
const missingProperties = expectedProperties.reduce( ( acc, property ) => {
if ( ! config.hasOwnProperty( property ) ) {
acc.push( property );
}
return acc;
}, [] );
if ( missingProperties.length > 0 ) {
const message =
'The payment method configuration object is missing the following properties:';
throw new TypeError( message + missingProperties.join( ', ' ) );
}
};