From 622559c8f6adfaf6f2c469e3bb856500f196d42d Mon Sep 17 00:00:00 2001 From: Michael Utech Date: Wed, 5 Dec 2018 17:51:24 +0100 Subject: [PATCH 1/4] add types for caniuse-lite --- types/caniuse-lite/caniuse-lite-tests.ts | 48 +++++++ types/caniuse-lite/index.d.ts | 159 +++++++++++++++++++++++ types/caniuse-lite/tsconfig.json | 23 ++++ types/caniuse-lite/tslint.json | 1 + 4 files changed, 231 insertions(+) create mode 100644 types/caniuse-lite/caniuse-lite-tests.ts create mode 100644 types/caniuse-lite/index.d.ts create mode 100644 types/caniuse-lite/tsconfig.json create mode 100644 types/caniuse-lite/tslint.json diff --git a/types/caniuse-lite/caniuse-lite-tests.ts b/types/caniuse-lite/caniuse-lite-tests.ts new file mode 100644 index 0000000000..38b09230de --- /dev/null +++ b/types/caniuse-lite/caniuse-lite-tests.ts @@ -0,0 +1,48 @@ +import { + agents, features, feature, Agent, Feature, PackedFeature, StatsByAgentID, SupportStatusByVersion, SupportStatus +} from "caniuse-lite"; + +const chrome: Agent | undefined = agents.chrome; +if (chrome !== undefined) { + const browser: string = chrome.browser; + const prefix: string = chrome.prefix; + const prefixExceptions: any = chrome.prefix_exceptions; + const usageGlobal: { [version: string]: number | undefined } = chrome.usage_global; + const releaseDate: { [version: string]: number | undefined } = chrome.release_date; + const versions: Array = chrome.versions; + consume(browser, prefix, prefixExceptions, usageGlobal, releaseDate, versions); +} + +const unpackedFeatures = Object.keys(features).map((id: string) => { + const packed: PackedFeature = features[id]; + const unpacked: Feature = feature(packed); + + const status: string = unpacked.status; + const title: string = unpacked.title; + const stats: StatsByAgentID = unpacked.stats; + Object.keys(stats).forEach((agentID: string) => { + const byVersion: SupportStatusByVersion = stats[agentID]; + Object.keys(byVersion).forEach(version => { + const supportStatus: SupportStatus = byVersion[version]; + consume(supportStatus); + }); + + const supportStatusByVersion: SupportStatusByVersion = stats[agentID]; + const agent: Agent = agents[agentID]!; + return { + feature: unpacked, + agent, + versions: Object.keys(supportStatusByVersion).map(version => { + return { + version, + releaseDate: agent.release_date[version], + [`feature_${id}`]: supportStatusByVersion[version] + }; + }) + }; + }); +}); + +function consume(...anything: any[]): void { + // ... +} diff --git a/types/caniuse-lite/index.d.ts b/types/caniuse-lite/index.d.ts new file mode 100644 index 0000000000..ce4f91a35f --- /dev/null +++ b/types/caniuse-lite/index.d.ts @@ -0,0 +1,159 @@ +// Type definitions for caniuse-lite 1.0 +// Project: https://github.com/ben-eb/caniuse-lite#readme +// Definitions by: Michael Utech +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/** + * Information about user agents (browsers, platforms) indexed by their ID. + */ +export const agents: AgentsByID; + +/** + * Features index by their ID. The feature ID is a human readable identifier. The + * associated value is a packed version of information about the feature that + * can be unpacked using the function `feature(packed)` + */ +export const features: { [featureID: string]: PackedFeature; }; + +/** + * @param packedFeature a packed feature obtained from `features[key]` for some valid key. + * @return the unpacked information as `Feature`. + */ +export function feature(packedFeature: PackedFeature): Feature; + +/** + * @param packedRegion a packed version of regional usage data by agent OD. + * @return the unpacked usage data indexed by agent ID and then version. + */ +export function region(packedRegion: PackedRegion): { [agentID: string]: UsageByVersion }; + +/** + * Agents indexed by their ID. . + */ +export type AgentsByID = Readonly<{ [id: string]: Readonly | undefined }>; + +/** + * Feature support status by version indexed by agent ID. + */ +export type StatsByAgentID = Readonly<{ [agentID: string]: SupportStatusByVersion }>; + +/** + * Feature support status indexed by an agent's versions. + */ +export type SupportStatusByVersion = Readonly<{ [version: string]: SupportStatus }>; + +/** + * Usage (percentage/market share) indexed by an agent's versions. + */ +export type UsageByVersion = Readonly<{ [version: string]: number | undefined }>; + +/** + * The standardization status of a feature: + * * ls - WHATWG living standard + * * rec - W3C recommendation + * * pr - W3C proposed recommendation + * * cr - W3C candidate recommendation + * * wd - W3C working draft + * * other - Non-W3C, but reputable + * * unoff - Unofficial + */ +export type FeatureStatus = "ls" | "rec" | "pr" | "cr" | "wd" | "other" | "unoff" | string; + +/** + * Encoded support status: + * * `n` - not supported + * * `p` - not supported, polyfill available + * * `u` - unknown + * * `a x` - partially supported, vendor prefix + * * `a` - partially supported + * * `y x` - fully supported, vendor prefix + * * `y` - fully supported + * + * The support status can additionally have one or more footnote references as `#`, f.e. + * `a x #1 #3`. + */ +export type SupportStatus = 'n' | 'p' | 'u' | "a x" | 'a' | "y x" | 'y' | string; + +/** + * Provides information about the Agent. + */ +export interface Agent { + /** + * Global agent usage by version + */ + usage_global: UsageByVersion; + + /** + * The agents vendor prefix + */ + prefix: string; + + /** + * Version matrix. See [caniuse](https://caniuse.com) + */ + versions: [ // Tuple of 70 version slots: + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null, + string|null, string|null, string|null, string|null, string|null ]; + + /** + * The agent's name + */ + browser: string; + + /** + * Release dates as seconds since epoch by version. + */ + release_date: { [version: string]: number | undefined }; + + /** + * Exceptions to vendor prefix use. + */ + prefix_exceptions?: { [version: string]: string | undefined }; +} + +/** + * Specifies a feature and its support status in all known agent versions. + */ +export interface Feature { + /** + * Specification status of the feature. + */ + status: FeatureStatus; + + /** + * Descriptive title of the feature. + */ + title: string; + + /** + * Agent support matrix for this feature. + */ + stats: StatsByAgentID; +} + +/** + * A space optimized version of Feature that can be unpacked using `feature(PackedFeature)`. + */ +export interface PackedFeature { + [encodedKey: string]: any; +} + +/** + * A space optimized version of Region that can be unpacked using `region(PackedFeature)`. + */ +export interface PackedRegion { + [encodedKey: string]: any; +} diff --git a/types/caniuse-lite/tsconfig.json b/types/caniuse-lite/tsconfig.json new file mode 100644 index 0000000000..adcea4d555 --- /dev/null +++ b/types/caniuse-lite/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", + "caniuse-lite-tests.ts" + ] +} diff --git a/types/caniuse-lite/tslint.json b/types/caniuse-lite/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/caniuse-lite/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 36e268033babcc716200192c72ba839daa43d7f9 Mon Sep 17 00:00:00 2001 From: jeremy Date: Wed, 5 Dec 2018 23:21:11 +0100 Subject: [PATCH 2/4] Add types for json-server --- types/json-server/index.d.ts | 72 ++++++++++++++++++++++++++ types/json-server/json-server-tests.ts | 41 +++++++++++++++ types/json-server/tsconfig.json | 16 ++++++ types/json-server/tslint.json | 1 + 4 files changed, 130 insertions(+) create mode 100644 types/json-server/index.d.ts create mode 100644 types/json-server/json-server-tests.ts create mode 100644 types/json-server/tsconfig.json create mode 100644 types/json-server/tslint.json diff --git a/types/json-server/index.d.ts b/types/json-server/index.d.ts new file mode 100644 index 0000000000..c52a4b220e --- /dev/null +++ b/types/json-server/index.d.ts @@ -0,0 +1,72 @@ +// Type definitions for json-server 0.14 +// Project: https://github.com/typicode/json-server +// Definitions by: Jeremy Bensimon +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { NextHandleFunction } from 'connect'; +import { Application, RequestHandler, Router } from 'express'; + +/** + * Returns an Express server. + */ +export function create(): Application; + +/** + * Returns middlewares used by JSON Server. + */ +export function defaults(options?: MiddlewaresOptions): RequestHandler[]; + +/** + * Returns JSON Server router. + * @param source Either a path to a json file (e.g. `'db.json'`) or an object in memory + * @param options Set foreign key suffix (default: `'Id'`) + */ +export function router(source: string | object, options?: { foreignKeySuffix: string }): Router; + +/** + * Add custom rewrite rules. + */ +export function rewriter(rules: { [rule: string]: string }): Router; + +/** + * Returns body-parser middleware used by JSON Server router. + * + * @returns + * ``` + * [bodyParser.json({ limit: '10mb', extended: false }), bodyParser.urlencoded({ extended: false })] + * ``` + */ +export const bodyParser: [NextHandleFunction, NextHandleFunction]; + +export interface MiddlewaresOptions { + /** + * Path to static files + * @default "public" (if folder exists) + */ + static?: string; + + /** + * Enable logger middleware + * @default true + */ + logger?: boolean; + + /** + * Enable body-parser middleware + * @default true + */ + bodyParser?: boolean; + + /** + * Disable CORS + * @default false + */ + noCors?: boolean; + + /** + * Accept only GET requests + * @default false + */ + readOnly?: boolean; +} diff --git a/types/json-server/json-server-tests.ts b/types/json-server/json-server-tests.ts new file mode 100644 index 0000000000..d68484b1ff --- /dev/null +++ b/types/json-server/json-server-tests.ts @@ -0,0 +1,41 @@ +import * as jsonServer from 'json-server'; + +const server = jsonServer.create(); + +const inMemoryDbRouter = jsonServer.router({ todos: [] as any[], users: [] as any[] }); + +const router = jsonServer.router('db.json', { foreignKeySuffix: '_id' }); + +const middlewaresOptions: jsonServer.MiddlewaresOptions = { + bodyParser: true, + logger: false, + noCors: true, + readOnly: true, + static: 'assets', +}; + +const middlewares = jsonServer.defaults(middlewaresOptions); + +const rewriter = jsonServer.rewriter({ + '/api/*': '/$1', + '/blog/:resource/:id/show': '/:resource/:id', +}); + +server.use(jsonServer.bodyParser); + +server.use((req, res, next) => { + if (req.method === 'POST') { + req.body.createdAt = Date.now(); + } + next(); +}); + +server.use(rewriter); + +server.use(middlewares); + +server.use(router); + +server.listen(3000, () => { + console.log('JSON Server is running'); +}); diff --git a/types/json-server/tsconfig.json b/types/json-server/tsconfig.json new file mode 100644 index 0000000000..e923ac1d7a --- /dev/null +++ b/types/json-server/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "json-server-tests.ts"] +} diff --git a/types/json-server/tslint.json b/types/json-server/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/json-server/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b19ba7a9a3b4f548bc350956847a5b6644c7ce8b Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Thu, 6 Dec 2018 19:27:28 +0100 Subject: [PATCH 3/4] Add types for tildify --- types/tildify/index.d.ts | 8 ++++++++ types/tildify/tildify-tests.ts | 4 ++++ types/tildify/tsconfig.json | 23 +++++++++++++++++++++++ types/tildify/tslint.json | 1 + 4 files changed, 36 insertions(+) create mode 100644 types/tildify/index.d.ts create mode 100644 types/tildify/tildify-tests.ts create mode 100644 types/tildify/tsconfig.json create mode 100644 types/tildify/tslint.json diff --git a/types/tildify/index.d.ts b/types/tildify/index.d.ts new file mode 100644 index 0000000000..a0dd100bf9 --- /dev/null +++ b/types/tildify/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for tildify 1.2 +// Project: https://github.com/sindresorhus/tildify#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = tildify; + +declare function tildify(str: string): string; diff --git a/types/tildify/tildify-tests.ts b/types/tildify/tildify-tests.ts new file mode 100644 index 0000000000..109f5f6c6e --- /dev/null +++ b/types/tildify/tildify-tests.ts @@ -0,0 +1,4 @@ +import tildify = require('tildify'); + +// $ExpectType string +tildify('/Users/sindresorhus/dev'); diff --git a/types/tildify/tsconfig.json b/types/tildify/tsconfig.json new file mode 100644 index 0000000000..4375409ba0 --- /dev/null +++ b/types/tildify/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", + "tildify-tests.ts" + ] +} diff --git a/types/tildify/tslint.json b/types/tildify/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tildify/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 225b004f4a13bfde2ce2e847aeda60262a8d9f65 Mon Sep 17 00:00:00 2001 From: Esteban Ibarra Date: Thu, 6 Dec 2018 15:01:57 -0500 Subject: [PATCH 4/4] Revert "Revert changes of react-native-draggable-flatlist" This reverts commit ca53c065a52c288b7d8d3fb3bde5709c6d496f7c. --- .../index.d.ts | 59 +++++++++++++++++++ .../react-native-draggable-flatlist-tests.tsx | 44 ++++++++++++++ .../tsconfig.json | 24 ++++++++ .../tslint.json | 1 + 4 files changed, 128 insertions(+) create mode 100644 types/react-native-draggable-flatlist/index.d.ts create mode 100644 types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx create mode 100644 types/react-native-draggable-flatlist/tsconfig.json create mode 100644 types/react-native-draggable-flatlist/tslint.json diff --git a/types/react-native-draggable-flatlist/index.d.ts b/types/react-native-draggable-flatlist/index.d.ts new file mode 100644 index 0000000000..0b96f0b3cd --- /dev/null +++ b/types/react-native-draggable-flatlist/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for react-native-draggable-flatlist 1.1 +// Project: https://github.com/computerjazz/react-native-draggable-flatlist#readme +// Definitions by: Stack Builders +// Esteban Ibarra +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { VirtualizedListWithoutRenderItemProps } from "react-native"; +import { Component } from "react"; + +export interface RenderItemInfo { + item: ItemR; + index: number; + move: () => void; + moveEnd: () => void; + isActive: boolean; +} + +export interface OnMoveEndInfo { + data: ReadonlyArray | null; + to: number; + from: number; + row: ItemM; +} + +interface DraggableFlatListProps extends VirtualizedListWithoutRenderItemProps { + /** + * Items to be rendered. + */ + data: ReadonlyArray | null; + + /** + * Function that returns updated ordering of data + */ + onMoveEnd?: (info: OnMoveEndInfo) => void; + + /** + * Function that is called when row becomes active. + */ + onMoveBegin?: (index: number) => void; + + /** + * Sets where scrolling begins. + * + * Default is 5 + */ + scrollPercent?: number; + + /** + * Function that calls move when the row should become active (in an onPress, onLongPress, etc). Calls moveEnd when the gesture is complete (in onPressOut). + */ + renderItem: (info: RenderItemInfo) => React.ReactElement | null; +} + +declare class DraggableFlatList extends Component> { + constructor(props: DraggableFlatListProps); +} + +export default DraggableFlatList; diff --git a/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx new file mode 100644 index 0000000000..40d613e4ea --- /dev/null +++ b/types/react-native-draggable-flatlist/react-native-draggable-flatlist-tests.tsx @@ -0,0 +1,44 @@ +import * as React from 'react'; +import { TouchableOpacity, Text } from 'react-native'; +import DraggableFlatList, { RenderItemInfo } from 'react-native-draggable-flatlist'; + +interface Item { + name: string; + mail: string; +} + +class Example extends React.Component { + state = { + data: [ + { name: 'Esteban', mail: 'foo@foo.com' }, + { name: 'Xavier', mail: 'foo2@foo.com' }, + ] + }; + + renderItem({ item, index, move, moveEnd, isActive }: RenderItemInfo) { + return ( + + {index} + {item.name} + {item.mail} + + ); + } + + render() { + const { data } = this.state; + return ( + `draggable-item-${index}`} + scrollPercent={10} + onMoveEnd={({ data }) => this.setState({ data })} + ListFooterComponent={{'Hello'}} + /> + ); + } +} diff --git a/types/react-native-draggable-flatlist/tsconfig.json b/types/react-native-draggable-flatlist/tsconfig.json new file mode 100644 index 0000000000..b3c009feac --- /dev/null +++ b/types/react-native-draggable-flatlist/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react-native" + }, + "files": [ + "index.d.ts", + "react-native-draggable-flatlist-tests.tsx" + ] +} diff --git a/types/react-native-draggable-flatlist/tslint.json b/types/react-native-draggable-flatlist/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-draggable-flatlist/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }