From 0558f655978ed0d3fd46207d9a6d59adf8d041cb Mon Sep 17 00:00:00 2001 From: Graham Dyson Date: Mon, 29 Apr 2019 07:59:44 +0100 Subject: [PATCH] Added type definition for `string-pixel-width` (#35046) --- types/string-pixel-width/index.d.ts | 18 +++++++++++++++ .../string-pixel-width-tests.ts | 14 +++++++++++ types/string-pixel-width/tsconfig.json | 23 +++++++++++++++++++ types/string-pixel-width/tslint.json | 1 + 4 files changed, 56 insertions(+) create mode 100644 types/string-pixel-width/index.d.ts create mode 100644 types/string-pixel-width/string-pixel-width-tests.ts create mode 100644 types/string-pixel-width/tsconfig.json create mode 100644 types/string-pixel-width/tslint.json diff --git a/types/string-pixel-width/index.d.ts b/types/string-pixel-width/index.d.ts new file mode 100644 index 0000000000..c6c3c76e12 --- /dev/null +++ b/types/string-pixel-width/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for string-pixel-width 1.7 +// Project: https://github.com/adambisek/string-pixel-width#readme +// Definitions by: Graham Dyson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = getWidth; + +declare function getWidth( + string: string, + settings?: Settings, +): number; + +interface Settings { + bold?: boolean; + font?: "andale mono"|"arial"|"avenir next"|"avenir"|"comic sans ms"|"courier new"|"georgia"|"impact"|"open sans"|"tahoma"|"times new roman"|"trebuchet ms"|"verdana"|"webdings"; + italic?: boolean; + size?: number; +} diff --git a/types/string-pixel-width/string-pixel-width-tests.ts b/types/string-pixel-width/string-pixel-width-tests.ts new file mode 100644 index 0000000000..5b0f290049 --- /dev/null +++ b/types/string-pixel-width/string-pixel-width-tests.ts @@ -0,0 +1,14 @@ +import stringPixelWidth = require('string-pixel-width'); + +// $ExpectType number +stringPixelWidth("test"); +// $ExpectType number +stringPixelWidth("test", {}); +// $ExpectType number +stringPixelWidth("test", { bold: true }); +// $ExpectType number +stringPixelWidth("test", { font: "arial" }); +// $ExpectType number +stringPixelWidth("test", { italic: true }); +// $ExpectType number +stringPixelWidth("test", { size: 10 }); diff --git a/types/string-pixel-width/tsconfig.json b/types/string-pixel-width/tsconfig.json new file mode 100644 index 0000000000..312bc609c3 --- /dev/null +++ b/types/string-pixel-width/tsconfig.json @@ -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", + "string-pixel-width-tests.ts" + ] +} \ No newline at end of file diff --git a/types/string-pixel-width/tslint.json b/types/string-pixel-width/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/string-pixel-width/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }