From b826388e52ab7cb43944b9b9047c8170d9f2fd98 Mon Sep 17 00:00:00 2001 From: "Adam A. Zerella" Date: Fri, 1 Mar 2019 14:21:51 +1100 Subject: [PATCH 1/2] Added type defs for html-truncate --- types/html-truncate/html-truncate-tests.ts | 13 +++++++++++ types/html-truncate/index.d.ts | 20 +++++++++++++++++ types/html-truncate/tsconfig.json | 25 ++++++++++++++++++++++ types/html-truncate/tslint.json | 3 +++ 4 files changed, 61 insertions(+) create mode 100644 types/html-truncate/html-truncate-tests.ts create mode 100644 types/html-truncate/index.d.ts create mode 100644 types/html-truncate/tsconfig.json create mode 100644 types/html-truncate/tslint.json diff --git a/types/html-truncate/html-truncate-tests.ts b/types/html-truncate/html-truncate-tests.ts new file mode 100644 index 0000000000..0c46bf560b --- /dev/null +++ b/types/html-truncate/html-truncate-tests.ts @@ -0,0 +1,13 @@ +import Truncate from "html-truncate"; + +Truncate('hello world', 4); + +Truncate('

hello world

', 4, { + keepImageTag: true, + ellipsis: true +}); + +Truncate('

hello world

', 6, { + keepImageTag: false, + ellipsis: '---' +}); diff --git a/types/html-truncate/index.d.ts b/types/html-truncate/index.d.ts new file mode 100644 index 0000000000..8be4a950a3 --- /dev/null +++ b/types/html-truncate/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for html-truncate 1.2 +// Project: https://github.com/huang47/nodejs-html-truncate +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface TruncateOptions { + /** + * Flag to specify if keep image tag, false by default. + */ + keepImageTag: boolean; + /** + * Omission symbol for truncated string, '...' by default. + */ + ellipsis: boolean|string; +} + +/** + * Truncate HTML text and also keep tag safe. + */ +export default function truncate(input: string, maxLength: number, options?: TruncateOptions): string; diff --git a/types/html-truncate/tsconfig.json b/types/html-truncate/tsconfig.json new file mode 100644 index 0000000000..693d5d17ba --- /dev/null +++ b/types/html-truncate/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "html-truncate-tests.ts" + ] +} diff --git a/types/html-truncate/tslint.json b/types/html-truncate/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/html-truncate/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From 0219d7546ed10178d5659696ee431a6613abe088 Mon Sep 17 00:00:00 2001 From: Adam Zerella Date: Wed, 6 Mar 2019 21:51:56 +1100 Subject: [PATCH 2/2] Updated export type --- types/html-truncate/html-truncate-tests.ts | 2 +- types/html-truncate/index.d.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/types/html-truncate/html-truncate-tests.ts b/types/html-truncate/html-truncate-tests.ts index 0c46bf560b..30f6a19e7c 100644 --- a/types/html-truncate/html-truncate-tests.ts +++ b/types/html-truncate/html-truncate-tests.ts @@ -1,4 +1,4 @@ -import Truncate from "html-truncate"; +import Truncate = require("html-truncate"); Truncate('hello world', 4); diff --git a/types/html-truncate/index.d.ts b/types/html-truncate/index.d.ts index 8be4a950a3..4784caa925 100644 --- a/types/html-truncate/index.d.ts +++ b/types/html-truncate/index.d.ts @@ -2,8 +2,9 @@ // Project: https://github.com/huang47/nodejs-html-truncate // Definitions by: Adam Zerella // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 -export interface TruncateOptions { +interface TruncateOptions { /** * Flag to specify if keep image tag, false by default. */ @@ -17,4 +18,6 @@ export interface TruncateOptions { /** * Truncate HTML text and also keep tag safe. */ -export default function truncate(input: string, maxLength: number, options?: TruncateOptions): string; +declare function truncate(input: string, maxLength: number, options?: TruncateOptions): string; + +export = truncate;