# wp-parsely/3.8.4/src/blocks/shared/utils/api.ts

Parse.ly, version 3.8.4. 48 lines.

- Page: https://pluginprobe.com/plugins/wp-parsely/3.8.4/code/src/blocks/shared/utils/api.ts
- Raw: https://pluginprobe.com/plugins/wp-parsely/3.8.4/raw/src/blocks/shared/utils/api.ts
- Modified: 2023-03-06T17:01:10+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/wp-parsely/3.8.4/code/src/blocks/shared/utils/api.ts#L10-L20`.

```typescript
import { removeDaysFromDate } from './date';

export interface AnalyticsApiQueryParams extends AnalyticsApiOptionalQueryParams {
	type: string,
}

export interface AnalyticsApiOptionalQueryParams extends ApiPeriodRange {
	pub_date_start?: string;
	pub_date_end?: string;
	sort?: string;
	limit?: number;
	page?: number;
	author?: string;
	tag?: string;
	section?: string;
	segment?: string;
}

export interface ApiPeriodRange {
	period_start?: string; // Defaults to 3 days ago.
	period_end?: string; // Defaults to current date and time.
}

/**
 * Gets `period_start` and `period_end` params for API.
 *
 * @param {number} days Number of days for which to calculate the period range.
 *
 * @return {ApiPeriodRange} API query params.
 */
export function getApiPeriodParams( days: number ): ApiPeriodRange {
	return {
		period_start: `${ days }d`,
		period_end: '',
	};
}

/**
 * Gets period start date for API.
 *
 * @param {number} days Number of days for which to calculate the period start date.
 *
 * @return {string} period start date.
 */
export function getApiPeriodStartDate( days: number ): string {
	return removeDaysFromDate( new Date().toISOString(), days - 1 ) + 'T00:00';
}

```
