Types for JQuery FormatDateTime

This commit is contained in:
AndersonFriaca
2018-10-31 17:43:11 -04:00
parent 4485251300
commit bf710712b4
4 changed files with 129 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
// Type definitions for JQuery formatDateTime 1.1
// Project: https://github.com/agschwender/jquery.formatDateTime
// Definitions by: Anderson Friaça <https://github.com/AndersonFriaca>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jquery" />
export type Options = Partial<{
/**
* Names of the months, e.g. January
*/
monthNames: string[];
/**
* Shortened names of the months, e.g. Jan
*/
monthNamesShort: string[];
/**
* Names of the days, e.g. Sunday
*/
dayNames: string[];
/**
* Shortened names of the days, e.g. Sun
*/
dayNamesShort: string[];
/**
* Names of the 12-hour clock periods, e.g. AM
*/
ampmNames: string[];
/**
* Callback to convert number to ordinal suffix, e.g. 1 to st
*/
getSuffix: ((num: number) => string);
/**
* Attribute which contains the datetime
*/
attribute: string;
/**
* Attribute which contains the datetime format
*/
formatAttribute: string;
/**
* Render dates in UTC instead of local timezone
*/
utc: boolean;
}>;
declare global {
interface JQuery {
formatDateTime(format: string, options?: Options): JQuery;
}
interface JQueryStatic {
formatDateTime(format: string, date: Date, options?: Options): string;
}
}
@@ -0,0 +1,40 @@
import { Options } from "jquery-formatdatetime";
// basic usage
$('#example').formatDateTime('mm/dd/y g:ii a');
const date = new Date('2012/07/05 09:55:03');
$.formatDateTime('mm/dd/y g:ii a', date);
// with options
const options: Options = {
monthNames: [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro'
],
dayNames: [
'Domingo',
'Segunda-Feira',
'Terça-Feira',
'Quarta-Feira',
'Quinta-Feira',
'Sexta-Feira',
'Sábado'
],
ampmNames: ['AM', 'PM']
};
$.formatDateTime('mm/dd/y g:ii a', date, options);
$('#example').formatDateTime('mm/dd/y g:ii a', options);
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jquery-formatdatetime-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{"extends": "dtslint/dt.json"}