2021-02-17 13:01:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
/**
|
2021-03-05 14:03:48 +00:00
|
|
|
* Checks if value passed contain passed label.
|
2021-02-17 13:01:20 +00:00
|
|
|
*/
|
2021-03-05 14:03:48 +00:00
|
|
|
export const mustContain = ( value: string, label: string ): true | Error => {
|
2021-02-17 13:01:20 +00:00
|
|
|
if ( ! value.includes( label ) ) {
|
|
|
|
throw Error(
|
|
|
|
sprintf(
|
2021-02-19 11:58:44 +00:00
|
|
|
/* translators: %1$s value passed to filter, %2$s : value that must be included. */
|
2021-02-17 13:01:20 +00:00
|
|
|
__(
|
|
|
|
'Returned value must include %1$s, you passed "%2$s"',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
value,
|
|
|
|
label
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function that always return true.
|
|
|
|
* We need to have a single instance of this function so it doesn't
|
|
|
|
* invalidate our memo comparison.
|
|
|
|
*/
|
2021-03-05 14:03:48 +00:00
|
|
|
export const returnTrue = (): true => true;
|