Merge branch 'master' into @types/cryptr

This commit is contained in:
Roman Rogowski
2018-12-06 18:37:59 -05:00
16 changed files with 525 additions and 0 deletions

View File

@@ -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<string | null> = 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 {
// ...
}

159
types/caniuse-lite/index.d.ts vendored Normal file
View File

@@ -0,0 +1,159 @@
// Type definitions for caniuse-lite 1.0
// Project: https://github.com/ben-eb/caniuse-lite#readme
// Definitions by: Michael Utech <https://github.com/mutech>
// 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<Agent> | 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 `#<n>`, 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;
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

72
types/json-server/index.d.ts vendored Normal file
View File

@@ -0,0 +1,72 @@
// Type definitions for json-server 0.14
// Project: https://github.com/typicode/json-server
// Definitions by: Jeremy Bensimon <https://github.com/jeremyben>
// 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;
}

View File

@@ -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');
});

View File

@@ -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"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -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 <https://github.com/stackbuilders>
// Esteban Ibarra <https://github.com/ibarrae>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { VirtualizedListWithoutRenderItemProps } from "react-native";
import { Component } from "react";
export interface RenderItemInfo<ItemR> {
item: ItemR;
index: number;
move: () => void;
moveEnd: () => void;
isActive: boolean;
}
export interface OnMoveEndInfo<ItemM> {
data: ReadonlyArray<ItemM> | null;
to: number;
from: number;
row: ItemM;
}
interface DraggableFlatListProps<Item> extends VirtualizedListWithoutRenderItemProps<Item> {
/**
* Items to be rendered.
*/
data: ReadonlyArray<Item> | null;
/**
* Function that returns updated ordering of data
*/
onMoveEnd?: (info: OnMoveEndInfo<Item>) => 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<Item>) => React.ReactElement<any> | null;
}
declare class DraggableFlatList<Item> extends Component<DraggableFlatListProps<Item>> {
constructor(props: DraggableFlatListProps<Item>);
}
export default DraggableFlatList;

View File

@@ -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<Item>) {
return (
<TouchableOpacity
onLongPress={move}
onPressOut={moveEnd}
>
<Text>{index}</Text>
<Text>{item.name}</Text>
<Text>{item.mail}</Text>
</TouchableOpacity>
);
}
render() {
const { data } = this.state;
return (
<DraggableFlatList
data={data}
renderItem={this.renderItem}
keyExtractor={(_item, index) => `draggable-item-${index}`}
scrollPercent={10}
onMoveEnd={({ data }) => this.setState({ data })}
ListFooterComponent={<Text>{'Hello'}</Text>}
/>
);
}
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

8
types/tildify/index.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
// Type definitions for tildify 1.2
// Project: https://github.com/sindresorhus/tildify#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = tildify;
declare function tildify(str: string): string;

View File

@@ -0,0 +1,4 @@
import tildify = require('tildify');
// $ExpectType string
tildify('/Users/sindresorhus/dev');

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }