diff --git a/types/detect-port/detect-port-tests.ts b/types/detect-port/detect-port-tests.ts new file mode 100644 index 0000000000..5ffd01ca7c --- /dev/null +++ b/types/detect-port/detect-port-tests.ts @@ -0,0 +1,23 @@ +import * as detect from "detect-port"; + +const port: number = 8000; + +/** + * callback usage + */ +detect(port, (err: Error, _port: number) => { +}); + + +function* yieldSyntax() { + const _port: number = yield detect(port); +}; + +/** + * use as a promise + */ +detect(port) + .then((_port: number) => { + }) + .catch(err => { + }); diff --git a/types/detect-port/index.d.ts b/types/detect-port/index.d.ts new file mode 100644 index 0000000000..a0fa185ece --- /dev/null +++ b/types/detect-port/index.d.ts @@ -0,0 +1,11 @@ +// Type definitions for detect-port 1.1 +// Project: https://github.com/node-modules/detect-port +// Definitions by: François Nguyen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface DetectPort { + (port: number, callback: (err: Error, _port: number) => void): void; + (port: number): Promise; +} +declare const detectPort: DetectPort; +export = detectPort; diff --git a/types/detect-port/tsconfig.json b/types/detect-port/tsconfig.json new file mode 100644 index 0000000000..dde5cf6683 --- /dev/null +++ b/types/detect-port/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "target": "es2015", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "detect-port-tests.ts" + ] +} \ No newline at end of file diff --git a/types/detect-port/tslint.json b/types/detect-port/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/types/detect-port/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file diff --git a/types/react-helmet/index.d.ts b/types/react-helmet/index.d.ts index 730bfb6df3..26e4a8994c 100644 --- a/types/react-helmet/index.d.ts +++ b/types/react-helmet/index.d.ts @@ -1,48 +1,45 @@ -// Type definitions for react-helmet +// Type definitions for react-helmet 5.0 // Project: https://github.com/nfl/react-helmet -// Definitions by: Evan Bremer , Isman Usoh +// Definitions by: Evan Bremer , Isman Usoh , François Nguyen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 -/// - import * as React from "react"; -declare function ReactHelmet(): ReactHelmet.HelmetComponent; - -declare namespace ReactHelmet { - function peek(): ReactHelmet.HelmetData; - function rewind(): ReactHelmet.HelmetData; - - interface HelmetProps { - base?: any; - defaultTitle?: string; - htmlAttributes?: any; - link?: Array; - meta?: Array; - script?: Array; - style?: Array; - title?: string; - titleTemplate?: string; - onChangeClientState?: (newState: any) => void; - } - - interface HelmetData { - base: HelmetDatum; - htmlAttributes: HelmetDatum; - link: HelmetDatum; - meta: HelmetDatum; - script: HelmetDatum; - style: HelmetDatum; - title: HelmetDatum; - } - - interface HelmetDatum { - toString(): string; - toComponent(): React.Component; - } - - class HelmetComponent extends React.Component {} +interface HelmetProps { + encodeSpecialCharacters?: boolean; + titleTemplate?: string; + defaultTitle?: string; + onChangeClientState?: (nextState: any) => any } -export = ReactHelmet; +export class Helmet extends React.Component { + static peek(): HelmetData; + static rewind(): HelmetData; + static renderStatic(): HelmetData; + static canUseDOM: boolean; +} + +export interface HelmetData { + base: HelmetDatum; + bodyAttributes: HelmetDatum; + htmlAttributes: HelmetDatum; + link: HelmetDatum; + meta: HelmetDatum; + noscript: HelmetDatum; + script: HelmetDatum; + style: HelmetDatum; + title: HelmetDatum; + titleAttributes: HelmetDatum; +} + +export interface HelmetDatum { + toString(): string; + toComponent(): React.Component; +} + +export const peek: () => HelmetData; +export const rewind: () => HelmetData; +export const renderStatic: () => HelmetData; +export const canUseDOM: boolean; +export default Helmet; diff --git a/types/react-helmet/react-helmet-tests.tsx b/types/react-helmet/react-helmet-tests.tsx index e6b78955b3..ef2939a985 100644 --- a/types/react-helmet/react-helmet-tests.tsx +++ b/types/react-helmet/react-helmet-tests.tsx @@ -1,18 +1,37 @@ -import * as React from 'react'; -import * as Helmet from 'react-helmet'; +import * as React from "react"; +import { Helmet, HelmetData } from "react-helmet"; - +const Application = () => +
+ + + My Title + + + + My Title + + + +
+ + Nested Title + + +
+
; + +const helmet: HelmetData = Helmet.renderStatic(); -const head = Helmet.rewind(); const html = ` - + - ${ head.title.toString() } - ${ head.meta.toString() } - ${ head.link.toString() } + ${helmet.title.toString()} + ${helmet.meta.toString()} + ${helmet.link.toString()} - +
// React stuff here
@@ -21,24 +40,65 @@ const html = ` `; function HTML() { + const htmlAttrs = helmet.htmlAttributes.toComponent(); + const bodyAttrs = helmet.bodyAttributes.toComponent(); + return ( - + - { head.title.toComponent() } - { head.meta.toComponent() } - { head.link.toComponent() } + {helmet.title.toComponent()} + {helmet.meta.toComponent()} + {helmet.link.toComponent()} - +
- // React stuff here
); } -function log(datum: Helmet.HelmetDatum) { - return console.log('logging a helmet datum:', datum.toString()); -} + console.log(newState)} +> + + + + + My Title + + + + + + + + + + + + + + + + diff --git a/types/react-helmet/v4/index.d.ts b/types/react-helmet/v4/index.d.ts new file mode 100644 index 0000000000..0b013f25bf --- /dev/null +++ b/types/react-helmet/v4/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for react-helmet 4.0 +// Project: https://github.com/nfl/react-helmet +// Definitions by: Evan Bremer , Isman Usoh +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +import * as React from "react"; + +declare function ReactHelmet(): ReactHelmet.HelmetComponent; + +declare namespace ReactHelmet { + function peek(): ReactHelmet.HelmetData; + function rewind(): ReactHelmet.HelmetData; + + interface HelmetProps { + base?: any; + defaultTitle?: string; + htmlAttributes?: any; + link?: Array; + meta?: Array; + script?: Array; + style?: Array; + title?: string; + titleTemplate?: string; + onChangeClientState?: (newState: any) => void; + } + + interface HelmetData { + base: HelmetDatum; + htmlAttributes: HelmetDatum; + link: HelmetDatum; + meta: HelmetDatum; + script: HelmetDatum; + style: HelmetDatum; + title: HelmetDatum; + } + + interface HelmetDatum { + toString(): string; + toComponent(): React.Component; + } + + class HelmetComponent extends React.Component {} +} + +export = ReactHelmet; diff --git a/types/react-helmet/v4/react-helmet-tests.tsx b/types/react-helmet/v4/react-helmet-tests.tsx new file mode 100644 index 0000000000..e6b78955b3 --- /dev/null +++ b/types/react-helmet/v4/react-helmet-tests.tsx @@ -0,0 +1,44 @@ +import * as React from 'react'; +import * as Helmet from 'react-helmet'; + + + +const head = Helmet.rewind(); +const html = ` + + + + ${ head.title.toString() } + ${ head.meta.toString() } + ${ head.link.toString() } + + +
+ // React stuff here +
+ + +`; + +function HTML() { + return ( + + + { head.title.toComponent() } + { head.meta.toComponent() } + { head.link.toComponent() } + + +
+ // React stuff here +
+ + + ); +} + +function log(datum: Helmet.HelmetDatum) { + return console.log('logging a helmet datum:', datum.toString()); +} + +log(head.title); diff --git a/types/react-helmet/v4/tsconfig.json b/types/react-helmet/v4/tsconfig.json new file mode 100644 index 0000000000..5813078cfb --- /dev/null +++ b/types/react-helmet/v4/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../../", + "jsx": "react", + "typeRoots": [ + "../../" + ], + "paths": { + "react-helmet": [ + "react-helmet/v4" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-helmet-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/react-router-config/index.d.ts b/types/react-router-config/index.d.ts new file mode 100644 index 0000000000..7c7c218557 --- /dev/null +++ b/types/react-router-config/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for react-router-config 1.0 +// Project: https://github.com/ReactTraining/react-router/tree/master/packages/react-router-config +// Definitions by: François Nguyen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import * as React from "react"; +import { RouteComponentProps, match } from "react-router"; +import { Location } from "history"; + +export interface RouteConfigComponentProps extends RouteComponentProps { + route?: RouteConfig; +} + +export interface RouteConfig { + location?: Location; + component?: React.SFC | void> | React.ComponentClass | void>; + path?: string; + exact?: boolean; + strict?: boolean; + routes?: RouteConfig[]; +} + +export interface MatchedRoute { + route: RouteConfig; + match: match +} + +export function matchRoutes(routes: RouteConfig[], pathname: string): MatchedRoute[]; + +export function renderRoutes(routes: RouteConfig[] | undefined): JSX.Element; diff --git a/types/react-router-config/react-router-config-tests.tsx b/types/react-router-config/react-router-config-tests.tsx new file mode 100644 index 0000000000..47b54927b8 --- /dev/null +++ b/types/react-router-config/react-router-config-tests.tsx @@ -0,0 +1,64 @@ +import * as React from "react"; +import { RouteConfig, matchRoutes, MatchedRoute, renderRoutes, RouteConfigComponentProps } from "react-router-config"; +import { BrowserRouter } from "react-router-dom"; + +const Root = ({ route }: RouteConfigComponentProps) => ( +
+

Root

+ {/* child routes won't render without this */} + {renderRoutes(route && route.routes)} +
+) + +const Home = ({ route }: RouteConfigComponentProps) => ( +
+

Home

+
+) + +const Child = ({ route }: RouteConfigComponentProps) => ( +
+

Child

+ {/* child routes won't render without this */} + {renderRoutes(route && route.routes)} +
+) + +const GrandChild = () => ( +
+

Grand Child

+
+) + +// route config +const routes: RouteConfig[] = [ + { + component: Root, + routes: [ + { + path: "/", + exact: true, + component: Home + }, + { + path: "/child/:id", + component: Child, + routes: [{ + + path: "/child/:id/grand-child", + component: GrandChild + }] + } + ] + } +]; + +const branch: MatchedRoute<{}>[] = matchRoutes<{}>(routes, "/child/23"); +// using the routes shown earlier, this returns +// [ +// routes[0], +// routes[0].routes[1] +// ] + +// pass this into ReactDOM.render +{renderRoutes(routes)}; diff --git a/types/react-router-config/tsconfig.json b/types/react-router-config/tsconfig.json new file mode 100644 index 0000000000..34cb44c46f --- /dev/null +++ b/types/react-router-config/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "preserve" + }, + "files": [ + "index.d.ts", + "react-router-config-tests.tsx" + ] +} \ No newline at end of file diff --git a/types/react-router-config/tslint.json b/types/react-router-config/tslint.json new file mode 100644 index 0000000000..cf4f5924c3 --- /dev/null +++ b/types/react-router-config/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../tslint.json", + "rules": { + "void-return": false + } +} \ No newline at end of file diff --git a/types/serialize-javascript/index.d.ts b/types/serialize-javascript/index.d.ts new file mode 100644 index 0000000000..9cfa69b977 --- /dev/null +++ b/types/serialize-javascript/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for serialize-javascript 1.3 +// Project: https://github.com/yahoo/serialize-javascript +// Definitions by: François Nguyen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace serializeJavascript { + interface SerializeJSOptions { + /** + * This option is the same as the space argument that can be passed to JSON.stringify. + * It can be used to add whitespace and indentation to the serialized output to make it more readable. + */ + space?: string | number | undefined; + /** + * This option is a signal to serialize() that the object being serialized does not contain any function or regexps values. + * This enables a hot-path that allows serialization to be over 3x faster. + * If you're serializing a lot of data, and know its pure JSON, then you can enable this option for a speed-up. + */ + isJSON?: boolean; + } +} + +/** + * Serialize JavaScript to a superset of JSON that includes regular expressions and functions. + * @param {any} input data to serialize + * @param {serializeJavascript.SerializeJSOptions} options optional object + * @returns {string} serialized data + */ +declare function serializeJavascript(input: any, options?: serializeJavascript.SerializeJSOptions): string; +export = serializeJavascript; diff --git a/types/serialize-javascript/serialize-javascript-tests.ts b/types/serialize-javascript/serialize-javascript-tests.ts new file mode 100644 index 0000000000..b4c79f6a7c --- /dev/null +++ b/types/serialize-javascript/serialize-javascript-tests.ts @@ -0,0 +1,19 @@ +import * as serialize from "serialize-javascript"; + +const obj: any = { + str: "string", + num: 0, + obj: { foo: "foo" }, + arr: [1, 2, 3], + bool: true, + nil: null, + undef: undefined, + + fn: function echo(arg: any) { return arg; }, + re: /([^\s]+)/g +}; + +serialize(obj); +serialize(obj, { space: 2 }); +serialize(obj, { space: "\t" }); +serialize(obj, { isJSON: true }); diff --git a/types/serialize-javascript/tsconfig.json b/types/serialize-javascript/tsconfig.json new file mode 100644 index 0000000000..a0b35c9913 --- /dev/null +++ b/types/serialize-javascript/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "serialize-javascript-tests.ts" + ] +} \ No newline at end of file diff --git a/types/serialize-javascript/tslint.json b/types/serialize-javascript/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/types/serialize-javascript/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file