From 19f1f4b082c4e84cb756c32fe0dbc206ed8e5ef0 Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Wed, 10 Oct 2018 18:19:02 +0200 Subject: [PATCH] season: new typings (#29606) --- types/season/index.d.ts | 33 +++++++++++++++++++++++++++++++++ types/season/season-tests.ts | 25 +++++++++++++++++++++++++ types/season/tsconfig.json | 23 +++++++++++++++++++++++ types/season/tslint.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 types/season/index.d.ts create mode 100644 types/season/season-tests.ts create mode 100644 types/season/tsconfig.json create mode 100644 types/season/tslint.json diff --git a/types/season/index.d.ts b/types/season/index.d.ts new file mode 100644 index 0000000000..447edc148d --- /dev/null +++ b/types/season/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for season 6.0 +// Project: http://atom.github.io/season +// Definitions by: Piotr Roszatycki +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface ParseOptions { + allowDuplicateKeys?: boolean; +} + +/** Set the cache directory to use for storing compiled CSON files. */ +export function setCacheDir(cacheDirectory: string): void; + +/** Convert the object to a CSON string. */ +export function stringify(object: any): string; + +/** Read the CSON or JSON object at the given path and return it to the callback once it is read and parsed. */ +export function readFile(objectPath: string, callback: (err: Error | null, object: any) => void): void; +export function readFile(objectPath: string, options: ParseOptions, callback: (err: Error | null, object: any) => void): void; + +/** Synchronous version of `CSON.readFile(objectPath, callback)`. */ +export function readFileSync(objectPath: string, options?: ParseOptions): any; + +/** Write the object to the given path as either JSON or CSON depending on the path's extension. */ +export function writeFile(objectPath: string, object: any, callback: (err: Error | null) => void): void; + +/** Synchronous version of `CSON.writeFile(objectPath, object, callback)` */ +export function writeFileSync(objectPath: string, object: any): void; + +/** Is the given path a valid object path? Returns true if the path has a .json or .cson file extension, false otherwise. */ +export function isObjectPath(objectPath: string): boolean; + +/** Resolve the path to an existent file that has a .json or .cson extension. Returns the path to an existent CSON or JSON file or null if none found. */ +export function resolve(objectPath: string): string | null; diff --git a/types/season/season-tests.ts b/types/season/season-tests.ts new file mode 100644 index 0000000000..b3cb12432d --- /dev/null +++ b/types/season/season-tests.ts @@ -0,0 +1,25 @@ +import * as CSON from "season"; + +CSON.setCacheDir("/tmp"); + +CSON.stringify({}); +CSON.stringify("string"); +CSON.stringify(42); +CSON.stringify(true); + +CSON.readFile("input.cson", (err, obj) => { + if (err) throw err; + const input: any = obj; +}); + +const input: any = CSON.readFileSync("input.cson"); + +CSON.writeFile("output.cson", input, (err) => { + if (err) throw err; +}); + +CSON.writeFileSync("output.cson", input); + +const isObjectPath: boolean = CSON.isObjectPath("output.cson"); + +const path: string | null = CSON.resolve("output.cson"); diff --git a/types/season/tsconfig.json b/types/season/tsconfig.json new file mode 100644 index 0000000000..816c12e247 --- /dev/null +++ b/types/season/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "season-tests.ts" + ] +} diff --git a/types/season/tslint.json b/types/season/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/season/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }