Merge pull request #32687 from BendingBender/expired

[expired] Add types
This commit is contained in:
Pranav Senthilnathan
2019-02-01 12:43:53 -08:00
committed by GitHub
4 changed files with 82 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import expired = require('expired');
const headers = `
Age: 0
Cache-Control: public, max-age=300
Content-Encoding: gzip
Content-Type: application/json;charset=utf-8
Date: Fri, 23 Dec 2016 05:50:31 GMT
Last-Modified: Fri, 23 Dec 2016 05:23:23 GMT`;
expired(headers); // $ExpectType boolean
expired.in(headers); // $ExpectType number
expired.on(headers); // $ExpectType Date
const parsedHeaders = {
age: '0',
'cache-control': 'public, max-age=300',
'content-encoding': 'gzip',
'content-type': 'application/json;charset=utf-8',
date: 'Fri, 23 Dec 2016 05:50:31 GMT',
'last-modified': 'Fri, 23 Dec 2016 05:23:23 GMT',
};
expired(parsedHeaders); // $ExpectType boolean
const date = new Date();
expired(headers, date); // $ExpectType boolean
expired.in(headers, date); // $ExpectType number
+29
View File
@@ -0,0 +1,29 @@
// Type definitions for expired 1.3
// Project: https://github.com/lukechilds/expired
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = expired;
declare const expired: expired;
interface expired {
/**
* @returns A boolean relating to whether the resource has expired or not.
* `true` means it's expired, `false` means it's fresh.
*/
(headers: expired.Headers, compareWith?: Date): boolean;
/**
* @returns The amount of milliseconds from the current date until the resource will expire.
* If the resource has already expired it will return a negative integer.
*/
in(headers: expired.Headers, compareWith?: Date): number;
/**
* @returns A JavaScript `Date` object for the date the resource will expire.
*/
on(headers: expired.Headers): Date;
}
declare namespace expired {
type Headers = string | { [header: string]: string | string[] | undefined };
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"expired-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }