diff --git a/types/html-truncate/html-truncate-tests.ts b/types/html-truncate/html-truncate-tests.ts new file mode 100644 index 0000000000..30f6a19e7c --- /dev/null +++ b/types/html-truncate/html-truncate-tests.ts @@ -0,0 +1,13 @@ +import Truncate = require("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..4784caa925 --- /dev/null +++ b/types/html-truncate/index.d.ts @@ -0,0 +1,23 @@ +// 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 +// TypeScript Version: 3.0 + +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. + */ +declare function truncate(input: string, maxLength: number, options?: TruncateOptions): string; + +export = truncate; 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