From cabbc399ffaedd4f94b3c7d93030a545d8f99f04 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sat, 4 Aug 2018 00:32:30 +0200 Subject: [PATCH] add @iarna/toml (#27861) * add @iarna/toml * fix path mapping --- types/iarna__toml/iarna__toml-tests.ts | 35 ++++++++++++++++++++++++++ types/iarna__toml/index.d.ts | 19 ++++++++++++++ types/iarna__toml/parse-async.d.ts | 10 ++++++++ types/iarna__toml/parse-stream.d.ts | 9 +++++++ types/iarna__toml/parse-string.d.ts | 3 +++ types/iarna__toml/stringify.d.ts | 15 +++++++++++ types/iarna__toml/tsconfig.json | 35 ++++++++++++++++++++++++++ types/iarna__toml/tslint.json | 1 + 8 files changed, 127 insertions(+) create mode 100644 types/iarna__toml/iarna__toml-tests.ts create mode 100644 types/iarna__toml/index.d.ts create mode 100644 types/iarna__toml/parse-async.d.ts create mode 100644 types/iarna__toml/parse-stream.d.ts create mode 100644 types/iarna__toml/parse-string.d.ts create mode 100644 types/iarna__toml/stringify.d.ts create mode 100644 types/iarna__toml/tsconfig.json create mode 100644 types/iarna__toml/tslint.json diff --git a/types/iarna__toml/iarna__toml-tests.ts b/types/iarna__toml/iarna__toml-tests.ts new file mode 100644 index 0000000000..65dcddbe3a --- /dev/null +++ b/types/iarna__toml/iarna__toml-tests.ts @@ -0,0 +1,35 @@ +import * as TOML from '@iarna/toml'; +import { Readable } from 'stream'; + +TOML.parse('{}'); // $ExpectType Record +TOML.parse.async('{}'); // $ExpectType Promise> +TOML.parse.async('{}', {}); // $ExpectType Promise> +TOML.parse.async('{}', {blocksize: 1}); // $ExpectType Promise> + +TOML.parse.stream(); // $ExpectType Transform +TOML.parse.stream(new Readable()); // $ExpectType Promise> + +TOML.stringify({}); // $ExpectType string +TOML.stringify(1); // $ExpectError + +TOML.stringify.value({}); // $ExpectType string +TOML.stringify.value(1); // $ExpectType string + +import parse = require('@iarna/toml/parse-string'); +parse('{}'); // $ExpectType Record + +import parseAsync = require('@iarna/toml/parse-async'); +parseAsync('{}'); // $ExpectType Promise> +parseAsync('{}', {}); // $ExpectType Promise> +parseAsync('{}', {blocksize: 1}); // $ExpectType Promise> + +import parseStream = require('@iarna/toml/parse-stream'); +parseStream(); // $ExpectType Transform +parseStream(new Readable()); // $ExpectType Promise> + +import stringify = require('@iarna/toml/stringify'); +stringify({}); // $ExpectType string +stringify(1); // $ExpectError + +stringify.value({}); // $ExpectType string +stringify.value(1); // $ExpectType string diff --git a/types/iarna__toml/index.d.ts b/types/iarna__toml/index.d.ts new file mode 100644 index 0000000000..1d7f8b1239 --- /dev/null +++ b/types/iarna__toml/index.d.ts @@ -0,0 +1,19 @@ +// Type definitions for @iarna/toml 2.0 +// Project: https://github.com/iarna/iarna-toml#readme +// Definitions by: Klaus Meinhardt +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import parseAsync = require('./parse-async'); +import parseStream = require('./parse-stream'); + +export import stringify = require('./stringify'); + +/** Synchronously parse a TOML string and return an object. */ +export function parse(str: string): Record; +export namespace parse { + export { + parseAsync as async, + parseStream as stream, + }; +} diff --git a/types/iarna__toml/parse-async.d.ts b/types/iarna__toml/parse-async.d.ts new file mode 100644 index 0000000000..40ba9b64ba --- /dev/null +++ b/types/iarna__toml/parse-async.d.ts @@ -0,0 +1,10 @@ +/** Asynchronously parse a TOML string and return a promise of the resulting object. */ +declare function parseAsync(str: string, opts?: parseAsync.Options): Promise>; + +declare namespace parseAsync { + interface Options { + /** The amount text to parser per pass through the event loop. Defaults to 40kb. */ + blocksize?: number; + } +} +export = parseAsync; diff --git a/types/iarna__toml/parse-stream.d.ts b/types/iarna__toml/parse-stream.d.ts new file mode 100644 index 0000000000..f844be1f07 --- /dev/null +++ b/types/iarna__toml/parse-stream.d.ts @@ -0,0 +1,9 @@ +/// + +import { Readable, Transform } from "stream"; + +/** Given a readable stream, parse it as it feeds us data. Return a promise of the resulting object. */ +declare function parseStream(readable: Readable): Promise>; +/** Returns a transform stream in object mode. When it completes, emit the resulting object. Only one object will ever be emitted. */ +declare function parseStream(): Transform; +export = parseStream; diff --git a/types/iarna__toml/parse-string.d.ts b/types/iarna__toml/parse-string.d.ts new file mode 100644 index 0000000000..0ef7630951 --- /dev/null +++ b/types/iarna__toml/parse-string.d.ts @@ -0,0 +1,3 @@ +/** Synchronously parse a TOML string and return an object. */ +declare function parseString(str: string): Record; +export = parseString; diff --git a/types/iarna__toml/stringify.d.ts b/types/iarna__toml/stringify.d.ts new file mode 100644 index 0000000000..6596d587f3 --- /dev/null +++ b/types/iarna__toml/stringify.d.ts @@ -0,0 +1,15 @@ +/** + * Serialize an object as TOML. + * + * If an object `TOML.stringify` is serializing has a toJSON method then it will call it to transform the object before serializing it. + * This matches the behavior of JSON.stringify. + * The one exception to this is that toJSON is not called for Date objects because JSON represents dates as strings and TOML can represent them natively. + */ +declare function stringify(obj: Record): string; + +declare namespace stringify { + /** Serialize a value as TOML would. This is a fragment and not a complete valid TOML document. */ + function value(v: any): string; +} + +export = stringify; diff --git a/types/iarna__toml/tsconfig.json b/types/iarna__toml/tsconfig.json new file mode 100644 index 0000000000..fe5c1cbf66 --- /dev/null +++ b/types/iarna__toml/tsconfig.json @@ -0,0 +1,35 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true, + "paths": { + "@iarna/toml": [ + "iarna__toml" + ], + "@iarna/toml/*": [ + "iarna__toml/*" + ] + } + }, + "files": [ + "index.d.ts", + "parse-async.d.ts", + "parse-stream.d.ts", + "parse-string.d.ts", + "stringify.d.ts", + "iarna__toml-tests.ts" + ] +} diff --git a/types/iarna__toml/tslint.json b/types/iarna__toml/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iarna__toml/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }