3.0.0 • Published 3 years ago

ngx-truncate-text v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

ngx-truncate-text

This module is for shortening the text and also includes some useful features for text manipulation.

see demo on stackblitz. in developing ...

install:

npm i ngx-truncate-text

then import it to app.module.ts.

import {NgxTruncateTextModule } from '@exir/ngx-truncate-text';

@NgModule({
declarations: [...],
imports: [
...
NgxTruncateTextModule
],
providers: [...],
bootstrap: [...]
})
export class AppModule { }

and then use it in html (simplest use) :

<p ngxTruncateText number="50" more="show" less="hide">
	John Griffith London (1876 – 1916) was an American novelist, journalist, and social activist. A pioneer of commercial fiction and American magazines.
</p>
propertydescriptiontypeversion
lessA word is displayed before the text is shortenedstring1.0.0
moreA word is displayed after the text is shortenedstring1.0.0
numberNumber of characters to displaynumber1.0.0
completeWordIt prevents word break when shortening text on a part of the word.boolean1.1.0+
hashtagfinds hashtag in text (any language, zero-width non-joiner is considered.)boolean2.0.0+
hasLiteralIf you want to see the text as it is (including "\ r", "\ n", "\ t"), use this featureboolean2.1.0+
highlightListhighlight some word in favorite colorstring3.0.0
highlightConditionThis feature determines whether any similar word in your list found in the text will be highlighted or will find and highlight exactly the same words in the list.string3.0.0
  • default color for toggle button is #ff00ff and cursor style is pointer , if you want to use custom style, use the builtin .toggleText class.
.toggleText{
    color: aqua !important;
	font-size:14px;
	font-style: italic;
}
  • default color for hashtags is #1b95e0 (from twitter), if you want to use custom style, use the builtin .hashtag class.
  • befor sending highlightList to directive, you must stringify it. in ts:
 q = [
    { name: 'juven', color: 'lightgreen' },
    { name: 'istia', color: 'pink' },
    { name: 'Cristiano', color: 'orange' },
    { name: 'neymar', color: 'lightblue' },
    { name: 'Brazil', color: 'yellow' }
  ];

  queryHighlight =  JSON.stringify(this.q);

in html:

 <p ngxTruncateText  number="70" more="more" less="less"
        ...
        [highlightList]="queryHighlight">
        {{news}}
 </p>
  • for find and highlight exactly the word use the [highlightCondition]="exactly". Without this condition, similar words will be highlighted.
 <p ngxTruncateText  number="70" more="more" less="less"
        ...
        [highlightCondition]="exactly" [highlightList]="queryHighlight">
        {{news}}
 </p>
  • you can send the highlight list as array of string, the list is colored with yellow (default color).

     q3 = ["aiming","france","ran"];
     queryHighlight =  JSON.stringify(this.q3);