From cf66dbf9f7b3631fb71657c265f37503db6b0ab8 Mon Sep 17 00:00:00 2001 From: Mike Fowler Date: Sat, 22 Dec 2018 17:05:06 -0500 Subject: [PATCH] Add type definitions for modular-scale module --- types/modular-scale/index.d.ts | 41 ++++++++++++++++++++++ types/modular-scale/modular-scale-tests.ts | 5 +++ types/modular-scale/tsconfig.json | 23 ++++++++++++ types/modular-scale/tslint.json | 1 + 4 files changed, 70 insertions(+) create mode 100644 types/modular-scale/index.d.ts create mode 100644 types/modular-scale/modular-scale-tests.ts create mode 100644 types/modular-scale/tsconfig.json create mode 100644 types/modular-scale/tslint.json diff --git a/types/modular-scale/index.d.ts b/types/modular-scale/index.d.ts new file mode 100644 index 0000000000..ba3f9379b7 --- /dev/null +++ b/types/modular-scale/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for modular-scale 5.1 +// Project: https://github.com/kristoferjoseph/modular-scale +// Definitions by: Mike Fowler +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface ModularScaleOptions { + /** The ratio to use in the generated type scale function. Defaults to ModularScaleRatio.goldenSection */ + ratio?: number; + + /** The base font size (in pixels) to use for the type scale. Defaults to 16 */ + base?: number; +} + +export interface ModularScaleRatio { + minorSecond: number; + majorSecond: number; + minorThird: number; + majorThird: number; + perfectFourth: number; + augFourth: number; + perfectFifth: number; + minorSixth: number; + goldenSection: number; + majorSixth: number; + minorSeventh: number; + majorSeventh: number; + octave: number; + majorTenth: number; + majorEleventh: number; + majorTwelfth: number; + doubleOctave: number; +} + +export interface modularScale { + (step: number, relative?: boolean): number; + steps(steps: number, relative?: boolean): number[]; +} + +export const ratios: ModularScaleRatio; + +export default function ModularScale(options: ModularScaleOptions): modularScale; diff --git a/types/modular-scale/modular-scale-tests.ts b/types/modular-scale/modular-scale-tests.ts new file mode 100644 index 0000000000..574cf702b0 --- /dev/null +++ b/types/modular-scale/modular-scale-tests.ts @@ -0,0 +1,5 @@ +import ModularScale, { ratios } from 'modular-scale'; + +const ms = ModularScale({ ratio: ratios.doubleOctave }); // $ExpectType modularScale +ms(1); // $ExpectType number +ms.steps(1); // $ExpectType number[] diff --git a/types/modular-scale/tsconfig.json b/types/modular-scale/tsconfig.json new file mode 100644 index 0000000000..85c1460c77 --- /dev/null +++ b/types/modular-scale/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", + "modular-scale-tests.ts" + ] +} diff --git a/types/modular-scale/tslint.json b/types/modular-scale/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/modular-scale/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }