mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@wordpress/date] add new definitions (#36698)
This commit is contained in:
parent
3b0f471911
commit
e5dcaed742
99
types/wordpress__date/index.d.ts
vendored
Normal file
99
types/wordpress__date/index.d.ts
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
// Type definitions for @wordpress/date 3.3
|
||||
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/date/README.md
|
||||
// Definitions by: Derek Sifford <https://github.com/dsifford>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
import { Moment, MomentInput } from 'moment';
|
||||
|
||||
export interface DateSettings {
|
||||
formats: {
|
||||
date: string;
|
||||
datetime: string;
|
||||
datetimeAbbreviated: string;
|
||||
time: string;
|
||||
};
|
||||
l10n: {
|
||||
locale: string;
|
||||
meridiem: {
|
||||
AM: string;
|
||||
PM: string;
|
||||
am: string;
|
||||
pm: string;
|
||||
};
|
||||
months: string[];
|
||||
monthsShort: string[];
|
||||
relative: {
|
||||
future: string;
|
||||
past: string;
|
||||
}
|
||||
weekdays: string[];
|
||||
weekdaysShort: string[];
|
||||
};
|
||||
timezone: {
|
||||
offset: string;
|
||||
string: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a date (like `date()` in PHP), in the site's timezone.
|
||||
*
|
||||
* @param dateFormat - PHP-style formatting string. See {@link https://php.net/date }.
|
||||
* @param [dateValue] - Date object or string, parsable by moment.js.
|
||||
*
|
||||
* @returns - Formatted date.
|
||||
*/
|
||||
export function date(dateFormat: string, dateValue?: MomentInput): string;
|
||||
|
||||
/**
|
||||
* Formats a date (like `date_i18n()` in PHP).
|
||||
*
|
||||
* @param dateFormat - PHP-style formatting string. See {@link https://php.net/date }.
|
||||
* @param [dateValue] - Date object or string, parsable by moment.js.
|
||||
* @param [gmt=false] - `true` for GMT/UTC, `false` for site's timezone.
|
||||
*
|
||||
* @returns - Formatted date.
|
||||
*/
|
||||
export function dateI18n(dateFormat: string, dateValue?: MomentInput, gmt?: boolean): string;
|
||||
|
||||
/**
|
||||
* Formats a date. Does not alter the date's timezone.
|
||||
*
|
||||
* @param dateFormat - PHP-style formatting string. See {@link https://php.net/date }.
|
||||
* @param [dateValue] - Date object or string, parsable by moment.js.
|
||||
*
|
||||
* @return - Formatted date.
|
||||
*/
|
||||
export function format(dateFormat: string, dateValue?: MomentInput): string;
|
||||
|
||||
/**
|
||||
* Create and return a JavaScript Date Object from a date string in the WP timezone.
|
||||
*
|
||||
* @param [dateValue] - Date formatted in the WP timezone.
|
||||
*/
|
||||
export function getDate(dateValue?: MomentInput): Date;
|
||||
|
||||
/**
|
||||
* Formats a date (like `date()` in PHP), in the UTC timezone.
|
||||
*
|
||||
* @param dateFormat - PHP-style formatting string. See {@link https://php.net/date }.
|
||||
* @param [dateValue] - Date object or string, parsable by moment.js.
|
||||
*
|
||||
* @return - Formatted date.
|
||||
*/
|
||||
export function gmdate(dateFormat: string, dateValue?: MomentInput): string;
|
||||
|
||||
/**
|
||||
* Check whether a date is considered in the future according to the WordPress settings.
|
||||
*
|
||||
* @param dateValue - Value parsable by moment.js in the Defined WP Timezone.
|
||||
*/
|
||||
export function isInTheFuture(dateValue: MomentInput): boolean;
|
||||
|
||||
/**
|
||||
* Adds a locale to moment, using the format supplied by `wp_localize_script()`.
|
||||
*
|
||||
* @param dateSettings - Settings, including locale data.
|
||||
*/
|
||||
export function setSettings(dateSettings: DateSettings): void;
|
||||
6
types/wordpress__date/package.json
Normal file
6
types/wordpress__date/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"moment": "^2.24.0"
|
||||
}
|
||||
}
|
||||
19
types/wordpress__date/tsconfig.json
Normal file
19
types/wordpress__date/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@wordpress/date": ["wordpress__date"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "wordpress__date-tests.ts"]
|
||||
}
|
||||
1
types/wordpress__date/tslint.json
Normal file
1
types/wordpress__date/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
104
types/wordpress__date/wordpress__date-tests.ts
Normal file
104
types/wordpress__date/wordpress__date-tests.ts
Normal file
@ -0,0 +1,104 @@
|
||||
import * as moment from 'moment';
|
||||
import * as date from '@wordpress/date';
|
||||
|
||||
//
|
||||
// date
|
||||
//
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l');
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l', new Date());
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l', '2019/01/01');
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l', 2019);
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l', [2019, '01', 1]);
|
||||
|
||||
// $ExpectType string
|
||||
date.date('l', moment());
|
||||
|
||||
//
|
||||
// dateI18n
|
||||
//
|
||||
|
||||
// $ExpectType string
|
||||
date.dateI18n('l');
|
||||
|
||||
// $ExpectType string
|
||||
date.dateI18n('l', new Date());
|
||||
|
||||
// $ExpectType string
|
||||
date.dateI18n('l', moment(), true);
|
||||
|
||||
//
|
||||
// format
|
||||
//
|
||||
|
||||
// $ExpectType string
|
||||
date.format('l');
|
||||
|
||||
// $ExpectType string
|
||||
date.format('l', '2019');
|
||||
|
||||
// $ExpectType string
|
||||
date.format('l', moment());
|
||||
|
||||
//
|
||||
// getDate
|
||||
//
|
||||
|
||||
// $ExpectType Date
|
||||
date.getDate();
|
||||
|
||||
// $ExpectType Date
|
||||
date.getDate('2019');
|
||||
|
||||
// $ExpectType Date
|
||||
date.getDate(new Date());
|
||||
|
||||
// $ExpectType Date
|
||||
date.getDate(moment());
|
||||
|
||||
//
|
||||
// gmdate
|
||||
//
|
||||
|
||||
// $ExpectType string
|
||||
date.gmdate('l');
|
||||
|
||||
// $ExpectType string
|
||||
date.gmdate('l', '2019');
|
||||
|
||||
// $ExpectType string
|
||||
date.gmdate('l', Date.now());
|
||||
|
||||
// $ExpectType string
|
||||
date.gmdate('l', [2019]);
|
||||
|
||||
//
|
||||
// isInTheFuture
|
||||
//
|
||||
|
||||
// $ExpectType boolean
|
||||
date.isInTheFuture('2019');
|
||||
|
||||
// $ExpectType boolean
|
||||
date.isInTheFuture(Date.now());
|
||||
|
||||
// $ExpectType boolean
|
||||
date.isInTheFuture(moment());
|
||||
|
||||
//
|
||||
// setSettings
|
||||
//
|
||||
|
||||
declare const settings: date.DateSettings;
|
||||
|
||||
// $ExpectType void
|
||||
date.setSettings(settings);
|
||||
Loading…
Reference in New Issue
Block a user