# elasticpress/5.0.2/assets/js/sync/src/utilities.js

ElasticPress, version 5.0.2. 58 lines.

- Page: https://pluginprobe.com/plugins/elasticpress/5.0.2/code/assets/js/sync/src/utilities.js
- Raw: https://pluginprobe.com/plugins/elasticpress/5.0.2/raw/assets/js/sync/src/utilities.js
- Modified: 2023-11-01T18:08:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elasticpress/5.0.2/code/assets/js/sync/src/utilities.js#L10-L20`.

```javascript
/**
 * Clear sync parameter from the URL.
 *
 * @returns {void}
 */
export const clearSyncParam = () => {
	const url = new URL(document.location.href);
	url.searchParams.delete('do_sync');
	window.history.replaceState({}, document.title, url);
};

/**
 * Get the total number of items from index meta.
 *
 * @param {object} indexMeta Index meta.
 * @returns {number} Number of items.
 */
export const getItemsTotalFromIndexMeta = (indexMeta) => {
	let itemsTotal = 0;

	if (indexMeta.current_sync_item) {
		itemsTotal += indexMeta.current_sync_item.found_items;
	}

	itemsTotal = indexMeta.sync_stack.reduce(
		(itemsTotal, sync) => itemsTotal + sync.found_items,
		itemsTotal,
	);

	itemsTotal += indexMeta.totals.failed;
	itemsTotal += indexMeta.totals.skipped;
	itemsTotal += indexMeta.totals.synced;

	return itemsTotal;
};

/**
 * Get the number of processed items from index meta.
 *
 * @param {object} indexMeta Index meta.
 * @returns {number} Number of processed items.
 */
export const getItemsProcessedFromIndexMeta = (indexMeta) => {
	let itemsProcessed = 0;

	if (indexMeta.current_sync_item) {
		itemsProcessed += indexMeta.current_sync_item.failed;
		itemsProcessed += indexMeta.current_sync_item.skipped;
		itemsProcessed += indexMeta.current_sync_item.synced;
	}

	itemsProcessed += indexMeta.totals.failed;
	itemsProcessed += indexMeta.totals.skipped;
	itemsProcessed += indexMeta.totals.synced;

	return itemsProcessed;
};

```
