2021-02-17 13:01:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
|
|
|
|
/**
|
2021-10-12 14:23:52 +00:00
|
|
|
* Ensures that a given value contains a string, or throws an error.
|
2021-02-17 13:01:20 +00:00
|
|
|
*/
|
2021-10-12 14:23:52 +00:00
|
|
|
export const mustContain = (
|
|
|
|
value: string,
|
|
|
|
requiredValue: string
|
|
|
|
): true | Error => {
|
|
|
|
if ( ! value.includes( requiredValue ) ) {
|
2021-02-17 13:01:20 +00:00
|
|
|
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'
|
|
|
|
),
|
2021-11-19 12:31:16 +00:00
|
|
|
requiredValue,
|
|
|
|
value
|
2021-02-17 13:01:20 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|