From 2b98b72dad31181b1dc87d6456490a93ec1f1714 Mon Sep 17 00:00:00 2001 From: Mike North Date: Mon, 31 Dec 2018 13:42:51 -0800 Subject: [PATCH 1/2] types for treeify --- types/treeify/index.d.ts | 28 ++++++++++++++++++++++++++++ types/treeify/treeify-tests.ts | 31 +++++++++++++++++++++++++++++++ types/treeify/tsconfig.json | 16 ++++++++++++++++ types/treeify/tslint.json | 4 ++++ 4 files changed, 79 insertions(+) create mode 100644 types/treeify/index.d.ts create mode 100644 types/treeify/treeify-tests.ts create mode 100644 types/treeify/tsconfig.json create mode 100644 types/treeify/tslint.json diff --git a/types/treeify/index.d.ts b/types/treeify/index.d.ts new file mode 100644 index 0000000000..29375cf7ba --- /dev/null +++ b/types/treeify/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for tress 1.0 +// Project: https://github.com/notatestuser/treeify +// Definitions by: Mike North +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export interface TreeObject { + [k: string]: TreeValue; +} +export type TreeValue = string | TreeObject; + +export function asTree( + treeObj: TreeObject, + showValues: boolean, + hideFunctions: boolean +): string; + +export function asLines( + treeObj: TreeObject, + showValues: boolean, + lineCallback: (line: string) => void +): string; +export function asLines( + treeObj: TreeObject, + showValues: boolean, + hideFunctions: boolean, + lineCallback: (line: string) => void +): string; diff --git a/types/treeify/treeify-tests.ts b/types/treeify/treeify-tests.ts new file mode 100644 index 0000000000..75d3de92a2 --- /dev/null +++ b/types/treeify/treeify-tests.ts @@ -0,0 +1,31 @@ +import * as treeify from 'treeify'; + +function log(s: string): void {} + +treeify.asTree( + { + apples: 'gala', // ├─ apples: gala + oranges: 'mandarin' // └─ oranges: mandarin + }, + true, + true +); + +treeify.asLines( + { + apples: 'gala', // ├─ apples: gala + oranges: 'mandarin' // └─ oranges: mandarin + }, + true, + log +); + +treeify.asLines( + { + apples: 'gala', // ├─ apples: gala + oranges: 'mandarin' // └─ oranges: mandarin + }, + true, + false, + log +); diff --git a/types/treeify/tsconfig.json b/types/treeify/tsconfig.json new file mode 100644 index 0000000000..965d33c826 --- /dev/null +++ b/types/treeify/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [] + }, + "files": ["index.d.ts", "treeify-tests.ts"] +} diff --git a/types/treeify/tslint.json b/types/treeify/tslint.json new file mode 100644 index 0000000000..10d875b8db --- /dev/null +++ b/types/treeify/tslint.json @@ -0,0 +1,4 @@ +{ + "extends": "dtslint/dt.json", + "rules": {} +} From f1b04d0c9aade73ec41d6957ac15e64ced8c93af Mon Sep 17 00:00:00 2001 From: Mike North Date: Mon, 31 Dec 2018 14:30:46 -0800 Subject: [PATCH 2/2] nested data test case --- types/treeify/treeify-tests.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/types/treeify/treeify-tests.ts b/types/treeify/treeify-tests.ts index 75d3de92a2..b8132ec0cf 100644 --- a/types/treeify/treeify-tests.ts +++ b/types/treeify/treeify-tests.ts @@ -4,7 +4,7 @@ function log(s: string): void {} treeify.asTree( { - apples: 'gala', // ├─ apples: gala + apples: 'gala', // ├─ apples: gala oranges: 'mandarin' // └─ oranges: mandarin }, true, @@ -13,8 +13,12 @@ treeify.asTree( treeify.asLines( { - apples: 'gala', // ├─ apples: gala - oranges: 'mandarin' // └─ oranges: mandarin + apples: 'gala', // ├─ apples: gala + oranges: 'mandarin', // ├─ oranges: mandarin + grapes: { // └─ grapes + seedless: 'Thompson, Selma Pete', // ├─ seedless: Thompson, Selma Pete + seeded: 'concord' // └─ seeded: Concord + } }, true, log @@ -22,7 +26,7 @@ treeify.asLines( treeify.asLines( { - apples: 'gala', // ├─ apples: gala + apples: 'gala', // ├─ apples: gala oranges: 'mandarin' // └─ oranges: mandarin }, true,