diff --git a/clamp-js/clamp-js-tests.ts b/clamp-js/clamp-js-tests.ts new file mode 100755 index 0000000000..33accec319 --- /dev/null +++ b/clamp-js/clamp-js-tests.ts @@ -0,0 +1,28 @@ +import * as clamp from 'clamp-js'; + +const lineElement: HTMLElement = document.createElement('div'); +lineElement.style.setProperty('font-size', '3px'); +lineElement.style.setProperty('line-height', '5px'); +lineElement.style.setProperty('height', '11px'); +lineElement.style.setProperty('width', '15px'); + +const newtext: Text = document.createTextNode('Lorem ipsum, dolor sit amet.'); +lineElement.appendChild(newtext); + +const clampFromElement = clamp(lineElement); +const clampFromDefaults = clamp(lineElement, { + clamp: 'auto', + useNativeClamp: true, + splitOnChars: ['.', '-', '–', '—', ' '], + animate: false, + truncationChar: '…', + truncationHTML: null +}); +const clampWithOptions = clamp(lineElement, { + clamp: 1, + useNativeClamp: false, + splitOnChars: [','], + animate: true, + truncationChar: '--', + truncationHTML: '' +}); diff --git a/clamp-js/index.d.ts b/clamp-js/index.d.ts new file mode 100755 index 0000000000..2e86e544f7 --- /dev/null +++ b/clamp-js/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for clamp-js 0.7 +// Project: https://github.com/xavi160/Clamp.js +// Definitions by: Sebastiaan de Rooij +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace clamp { + export interface ClampOptions { + clamp?: number|string; + useNativeClamp?: boolean; + splitOnChars?: string[]; + animate?: boolean; + truncationChar?: string; + truncationHTML?: string | null; + } + + export interface ClampResponse { + 'original': string; + 'clamped': string; + } +} + +declare function clamp(element: HTMLElement, options?: clamp.ClampOptions): clamp.ClampResponse; + +export = clamp; +export as namespace clamp; diff --git a/clamp-js/tsconfig.json b/clamp-js/tsconfig.json new file mode 100755 index 0000000000..dc6338fcf2 --- /dev/null +++ b/clamp-js/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "clamp-js-tests.ts" + ] +} diff --git a/clamp-js/tslint.json b/clamp-js/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/clamp-js/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }