Server IP : 104.21.14.103 / Your IP : 3.133.129.97 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/context/ |
Upload File : |
/** * This is an assertion utility for validating that the incoming value prop * value on a given context provider is valid and throws an error if it isn't. * * Note: this asserts values that are expected to be an object. * * The validationMap is expected to be an object in the following shape. * * { * [expectedPropertyName<String>]: { * required: [expectedRequired<Boolean>] * type: [expectedType<String>] * } * } * * @param {string} contextName The name of the context provider being * validated. * @param {Object} validationMap A map for validating the incoming value against. * @param {Object} value The value being validated. * * @throws {Error} */ export const assertValidContextValue = ( contextName, validationMap, value ) => { if ( typeof value !== 'object' ) { throw new Error( `${ contextName } expects an object for its context value` ); } const errors = []; for ( const expectedProperty in validationMap ) { if ( validationMap[ expectedProperty ].required && typeof value[ expectedProperty ] === 'undefined' ) { errors.push( `The ${ expectedProperty } is required and is not present.` ); } else if ( typeof value[ expectedProperty ] !== 'undefined' && typeof value[ expectedProperty ] !== validationMap[ expectedProperty ].type ) { errors.push( `The ${ expectedProperty } must be of ${ validationMap[ expectedProperty ].type } and instead was ${ typeof value[ expectedProperty ] }` ); } } if ( errors.length > 0 ) { throw new Error( `There was a problem with the value passed in on ${ contextName }:\n ${ errors.join( '\n' ) }` ); } };