add @iarna/toml (#27861)

* add @iarna/toml

* fix path mapping
This commit is contained in:
Klaus Meinhardt
2018-08-04 00:32:30 +02:00
committed by Sheetal Nandi
parent f37107862d
commit cabbc399ff
8 changed files with 127 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import * as TOML from '@iarna/toml';
import { Readable } from 'stream';
TOML.parse('{}'); // $ExpectType Record<string, any>
TOML.parse.async('{}'); // $ExpectType Promise<Record<string, any>>
TOML.parse.async('{}', {}); // $ExpectType Promise<Record<string, any>>
TOML.parse.async('{}', {blocksize: 1}); // $ExpectType Promise<Record<string, any>>
TOML.parse.stream(); // $ExpectType Transform
TOML.parse.stream(new Readable()); // $ExpectType Promise<Record<string, any>>
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<string, any>
import parseAsync = require('@iarna/toml/parse-async');
parseAsync('{}'); // $ExpectType Promise<Record<string, any>>
parseAsync('{}', {}); // $ExpectType Promise<Record<string, any>>
parseAsync('{}', {blocksize: 1}); // $ExpectType Promise<Record<string, any>>
import parseStream = require('@iarna/toml/parse-stream');
parseStream(); // $ExpectType Transform
parseStream(new Readable()); // $ExpectType Promise<Record<string, any>>
import stringify = require('@iarna/toml/stringify');
stringify({}); // $ExpectType string
stringify(1); // $ExpectError
stringify.value({}); // $ExpectType string
stringify.value(1); // $ExpectType string

19
types/iarna__toml/index.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
// Type definitions for @iarna/toml 2.0
// Project: https://github.com/iarna/iarna-toml#readme
// Definitions by: Klaus Meinhardt <https://github.com/ajafff>
// 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<string, any>;
export namespace parse {
export {
parseAsync as async,
parseStream as stream,
};
}

10
types/iarna__toml/parse-async.d.ts vendored Normal file
View File

@@ -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<Record<string, any>>;
declare namespace parseAsync {
interface Options {
/** The amount text to parser per pass through the event loop. Defaults to 40kb. */
blocksize?: number;
}
}
export = parseAsync;

9
types/iarna__toml/parse-stream.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
/// <reference types="node" />
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<Record<string, any>>;
/** 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;

3
types/iarna__toml/parse-string.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
/** Synchronously parse a TOML string and return an object. */
declare function parseString(str: string): Record<string, any>;
export = parseString;

15
types/iarna__toml/stringify.d.ts vendored Normal file
View File

@@ -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, any>): 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;

View File

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

View File

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