2022-06-09 15:52:19 +00:00
# Utilities <!-- omit in toc -->
2021-10-12 14:23:52 +00:00
## Table of Contents <!-- omit in toc -->
2022-09-12 04:29:24 +00:00
- [`extensionCartUpdate` ](#extensioncartupdate )
- [Usage ](#usage )
- [Options ](#options )
- [`args (object, required)` ](#args-object-required )
- [`mustContain` ](#mustcontain )
- [Usage ](#usage-1 )
- [Options ](#options-1 )
- [`value (string, required)` ](#value-string-required )
- [`requiredValue (string, required)` ](#requiredvalue-string-required )
2022-06-09 15:52:19 +00:00
Miscellaneous utility functions for dealing with checkout functionality.
2021-10-12 14:23:52 +00:00
## `extensionCartUpdate`
When executed, this will call the cart/extensions REST API endpoint. The new cart is then received into the client-side store.
### Usage
2022-06-09 15:52:19 +00:00
```ts
2021-10-12 14:23:52 +00:00
// Aliased import
import { extensionCartUpdate } from '@woocommerce/blocks-checkout';
// Global import
// const { extensionCartUpdate } = wc.blocksCheckout;
extensionCartUpdate( {
namespace: 'extension-unique-namespace',
data: {
key: 'value',
},
} );
```
### Options
The following options are available:
#### `args (object, required)`
2022-09-12 04:29:24 +00:00
Args to pass to the Rest API endpoint. This can contain data and a namespace to trigger extension specific functionality on the server-side. [You can read more about this, and the server-side implementation, in this doc. ](../../../docs/third-party-developers/extensibility/rest-api/extend-rest-api-update-cart.md )
2021-10-12 14:23:52 +00:00
## `mustContain`
Ensures that a given value contains a string, or throws an error.
### Usage
```js
// Aliased import
import { mustContain } from '@woocommerce/blocks-checkout';
// Global import
// const { mustContain } = wc.blocksCheckout;
mustContain( 'This is a string containing a < price / > ', '< price / > ' ); // This will not throw an error
mustContain( 'This is a string', '< price / > ' ); // This will throw an error
```
### Options
The following options are available:
#### `value (string, required)`
Value being checked. Must be a string.
#### `requiredValue (string, required)`
What value must contain. If this is not found within `value` , and error will be thrown.
2022-02-02 14:27:46 +00:00
<!-- FEEDBACK -->
2022-06-09 12:43:17 +00:00
2022-02-02 14:27:46 +00:00
---
[We're hiring! ](https://woocommerce.com/careers/ ) Come work with us!
2022-08-01 08:56:28 +00:00
🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here. ](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./packages/checkout/utils/README.md )
2022-06-09 12:43:17 +00:00
2022-02-02 14:27:46 +00:00
<!-- /FEEDBACK -->