mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-04 17:20:09 +00:00
Added type definitions for shevyjs (#42050)
* Added type definitions for shevyjs * Removed example code * Fixed typos
This commit is contained in:
7
types/shevyjs/constants/index.d.ts
vendored
Normal file
7
types/shevyjs/constants/index.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { FontScalePresets, Options, Heading } from '../types';
|
||||
|
||||
export const fontScalePresets: FontScalePresets;
|
||||
|
||||
export const defaultOptions: Options;
|
||||
|
||||
export const headings: Heading[];
|
||||
35
types/shevyjs/index.d.ts
vendored
Normal file
35
types/shevyjs/index.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// Type definitions for shevyjs 1.1
|
||||
// Project: https://github.com/kyleshevlin/shevyjs#readme
|
||||
// Definitions by: nonAlgebraic <https://github.com/nonAlgebraic>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { getFontUnit, getFontScale } from './utils';
|
||||
import { Options, RhythmProperties, Factor } from './types';
|
||||
|
||||
export default class Shevy {
|
||||
constructor(options?: Partial<Options>);
|
||||
|
||||
baseFontSize: Options['baseFontSize'];
|
||||
baseFontUnit: ReturnType<typeof getFontUnit>;
|
||||
baseLineHeight: Options['baseLineHeight'];
|
||||
baseFontScale: ReturnType<typeof getFontScale>;
|
||||
addMarginBottom: Options['addMarginBottom'];
|
||||
proximity: Options['proximity'];
|
||||
proximityFactor: Options['proximityFactor'];
|
||||
|
||||
h1: RhythmProperties;
|
||||
h2: RhythmProperties;
|
||||
h3: RhythmProperties;
|
||||
h4: RhythmProperties;
|
||||
h5: RhythmProperties;
|
||||
h6: RhythmProperties;
|
||||
|
||||
body: Pick<RhythmProperties, Exclude<keyof RhythmProperties, 'marginBottom'>>;
|
||||
|
||||
content: RhythmProperties;
|
||||
|
||||
lineHeightSpacing(factor?: Factor): string;
|
||||
|
||||
baseSpacing(factor?: Factor): string;
|
||||
}
|
||||
50
types/shevyjs/shevyjs-tests.ts
Normal file
50
types/shevyjs/shevyjs-tests.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import Shevy from 'shevyjs';
|
||||
import { Options } from 'shevyjs/types';
|
||||
import { headings } from 'shevyjs/constants';
|
||||
import * as utils from 'shevyjs/utils';
|
||||
|
||||
const options: Options = {
|
||||
baseFontSize: '16px',
|
||||
baseLineHeight: 1,
|
||||
baseFontScale: 'majorSecond',
|
||||
addMarginBottom: true,
|
||||
proximity: true,
|
||||
proximityFactor: 1,
|
||||
};
|
||||
|
||||
const shevy = new Shevy(options);
|
||||
|
||||
shevy.baseFontSize; // $ExpectType string
|
||||
shevy.baseFontUnit; // $ExpectType string
|
||||
shevy.baseLineHeight; // $ExpectType number
|
||||
shevy.baseFontScale; // $ExpectType number[]
|
||||
shevy.addMarginBottom; // $ExpectType boolean
|
||||
shevy.proximity; // $ExpectType boolean
|
||||
shevy.proximityFactor; // $ExpectType number
|
||||
|
||||
headings.forEach(heading => {
|
||||
shevy[heading].fontSize; // $ExpectType string
|
||||
shevy[heading].lineHeight; // $ExpectType number
|
||||
shevy[heading].marginBottom; // $ExpectType string
|
||||
});
|
||||
|
||||
shevy.body.fontSize; // $ExpectType string
|
||||
shevy.body.lineHeight; // $ExpectType number
|
||||
|
||||
shevy.content.fontSize; // $ExpectType string
|
||||
shevy.content.lineHeight; // $ExpectType number
|
||||
shevy.content.marginBottom; // $ExpectType string
|
||||
|
||||
shevy.lineHeightSpacing(1); // $ExpectType string
|
||||
|
||||
shevy.baseSpacing(1); // $ExpectType string
|
||||
|
||||
utils.calcHeadingFontSize(shevy, 1); // $ExpectType string
|
||||
utils.calcHeadingLineHeight(shevy, 1); // $ExpectType number
|
||||
utils.calcHeadingMarginBottom(shevy, 1); // $ExpectType string | undefined
|
||||
utils.calcHeadingMarginBottom(shevy, 1, true); // $ExpectType string | undefined
|
||||
utils.getFontScale([1, 2, 3]); // $ExpectType number[]
|
||||
utils.getFontScale('majorSecond'); // $ExpectType number[]
|
||||
utils.getFontUnit('16px'); // $ExpectType string
|
||||
utils.getFontValue('16px'); // $ExpectType number
|
||||
utils.trimArrayToMaxOf6([1, 2, 3, 4, 5, 6, 7, 8]); // $ExpectType number[]
|
||||
23
types/shevyjs/tsconfig.json
Normal file
23
types/shevyjs/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"shevyjs-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/shevyjs/tslint.json
Normal file
1
types/shevyjs/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
28
types/shevyjs/types.d.ts
vendored
Normal file
28
types/shevyjs/types.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
export type Factor = number;
|
||||
|
||||
export type Scale = Factor[];
|
||||
|
||||
export interface FontScalePresets {
|
||||
majorSecond: Scale;
|
||||
minorThird: Scale;
|
||||
majorThird: Scale;
|
||||
perfectFourth: Scale;
|
||||
augmentedFourth: Scale;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
baseFontSize: string;
|
||||
baseLineHeight: number;
|
||||
baseFontScale: Scale | keyof FontScalePresets;
|
||||
addMarginBottom: boolean;
|
||||
proximity: boolean;
|
||||
proximityFactor: Factor;
|
||||
}
|
||||
|
||||
export type Heading = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
||||
|
||||
export interface RhythmProperties {
|
||||
fontSize: string;
|
||||
lineHeight: number;
|
||||
marginBottom: string;
|
||||
}
|
||||
17
types/shevyjs/utils/index.d.ts
vendored
Normal file
17
types/shevyjs/utils/index.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { fontScalePresets } from '../constants';
|
||||
import { Scale, Factor } from '../types';
|
||||
import Shevy from '../index';
|
||||
|
||||
export function getFontValue(size: string): number;
|
||||
|
||||
export function getFontUnit(size: string): string;
|
||||
|
||||
export function trimArrayToMaxOf6<T>(array: ReadonlyArray<T>): T[];
|
||||
|
||||
export function getFontScale(fontScale: Scale | keyof typeof fontScalePresets): number[];
|
||||
|
||||
export function calcHeadingFontSize(thisArg: Shevy, factor: Factor): string;
|
||||
|
||||
export function calcHeadingLineHeight(thisArg: Shevy, factor: Factor): number;
|
||||
|
||||
export function calcHeadingMarginBottom(thisArg: Shevy, factor: Factor, addMarginBottom?: boolean): string | undefined;
|
||||
Reference in New Issue
Block a user