From a5c7386e2ed858e62c5591f53b78b6b9cdfd733f Mon Sep 17 00:00:00 2001 From: Oren Trutner Date: Thu, 24 May 2018 17:03:35 -0700 Subject: [PATCH] Add bin-pack typings --- types/bin-pack/bin-pack-tests.ts | 8 +++++ types/bin-pack/index.d.ts | 60 ++++++++++++++++++++++++++++++++ types/bin-pack/tsconfig.json | 23 ++++++++++++ types/bin-pack/tslint.json | 1 + 4 files changed, 92 insertions(+) create mode 100644 types/bin-pack/bin-pack-tests.ts create mode 100644 types/bin-pack/index.d.ts create mode 100644 types/bin-pack/tsconfig.json create mode 100644 types/bin-pack/tslint.json diff --git a/types/bin-pack/bin-pack-tests.ts b/types/bin-pack/bin-pack-tests.ts new file mode 100644 index 0000000000..f913d53520 --- /dev/null +++ b/types/bin-pack/bin-pack-tests.ts @@ -0,0 +1,8 @@ +import * as pack from "bin-pack"; + +// $ExpectType PackResult<{ width: number; height: number; }> +const packResult = pack([ + { width: 50, height: 50 }, + { width: 25, height: 25 }, + { width: 25, height: 20 } +]); diff --git a/types/bin-pack/index.d.ts b/types/bin-pack/index.d.ts new file mode 100644 index 0000000000..0d3df98899 --- /dev/null +++ b/types/bin-pack/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for bin-pack 1.0 +// Project: https://github.com/bryanburgers/bin-pack +// Definitions by: Oren Trutner +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Packs objects that have a width and a height into as small of a square as + * possible, using a binary tree bin packing algorithm. After packing, each + * object is given an (x, y) coordinate of where it would be optimally packed. + * @param bins List of rectangular bins to pack + * @param options Packing options. Use inPlace: true to modify the bins + * argument in-place. + */ +declare function pack(bins: T[], options?: pack.Options): pack.PackResult; + +declare namespace pack { + /** Packing options. */ + interface Options { + /** Use inPlace=true to add x,y fields to the bins argument. */ + inPlace?: boolean; + } + + /** Specifies the dimensions of a bin to pack. */ + interface Bin { + width: number; + height: number; + } + + /** Describes the location of a packed bin. */ + interface PackedItem { + /** X coordinate of the packed bin. */ + x: number; + + /** Y coordinate of the packed bin. */ + y: number; + + /** Width of the bin. */ + width: number; + + /** Height of the bin. */ + height: number; + + /** The original bin object. */ + item: T; + } + + /** The return value from the pack function. */ + interface PackResult { + /** Width of the bounding box around all bins. */ + width: number; + + /** Height of the bounding box around all bins. */ + height: number; + + /** List of packed bins. */ + items: Array>; + } +} + +export = pack; diff --git a/types/bin-pack/tsconfig.json b/types/bin-pack/tsconfig.json new file mode 100644 index 0000000000..6c6a41a37a --- /dev/null +++ b/types/bin-pack/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", + "bin-pack-tests.ts" + ] +} diff --git a/types/bin-pack/tslint.json b/types/bin-pack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/bin-pack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }