Merge pull request #33494 from adamzerella/types/html-truncate

[html-truncate] Add typing for html-truncate
This commit is contained in:
Nathan Shively-Sanders
2019-03-07 09:24:00 -08:00
committed by GitHub
4 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import Truncate = require("html-truncate");
Truncate('hello world', 4);
Truncate('<p><div>hello world</div></p>', 4, {
keepImageTag: true,
ellipsis: true
});
Truncate('<p><div>hello world</div></p>', 6, {
keepImageTag: false,
ellipsis: '---'
});

23
types/html-truncate/index.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
// Type definitions for html-truncate 1.2
// Project: https://github.com/huang47/nodejs-html-truncate
// Definitions by: Adam Zerella <https://github.com/adamzerella>
// 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;

View File

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

View File

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