[srcset] Add types

This commit is contained in:
Dimitri Benin
2019-01-14 23:15:53 +01:00
parent f5baf4c5a9
commit a4719a48eb
4 changed files with 59 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
// Type definitions for srcset 1.0
// Project: https://github.com/sindresorhus/srcset#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Parse the HTML `<img>`
* [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
*
* @param srcset An srcset string.
*/
export function parse(srcset: string): SrcSetDefinition[];
/**
* Stringify a list of `SrcSetDefinition`s.
*
* @param srcSetDefinitions An array of `SrcSetDefinition` object.
* @returns A srcset string.
*/
export function stringify(srcSetDefinitions: SrcSetDefinition[]): string;
export interface SrcSetDefinition {
url: string;
width?: number;
height?: number;
density?: number;
}
+8
View File
@@ -0,0 +1,8 @@
import srcset = require('srcset');
const parsed = srcset.parse('banner-HD.jpg 2x, banner-phone.jpg 100w');
parsed; // $ExpectType SrcSetDefinition[]
parsed.push({ url: 'banner-phone-HD.jpg', width: 100, density: 2 });
srcset.stringify(parsed); // $ExpectType string
+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",
"srcset-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }