Skip to content

Commit

Permalink
Bump to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
samiahmedsiddiqui committed Oct 26, 2019
1 parent efb35b3 commit a6bb922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 72 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ yarn add trim-words

## Usage

Import Package in `Node.js`
Import Package in `Node.js`.

```
var trimWords = require('trim-words');
```

Import Package in `React`
Import Package in `React`.

```
import trimWords from 'trim-words';
Expand Down
75 changes: 6 additions & 69 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,6 @@
'use strict';

function stripTags(string, remove_breaks) {
string = string.replace(/<(script|style)[^>]*?>.*?<\/\\1>/si, '');

// Replace all Tags
string = string.replace(/<[^>]*>/g, '');
if (remove_breaks) {
string = string.replace(/[\r\n\t ]+/, ' ');
}

return trim(string);
}

function trim(str, charlist) {
var whitespace = [
' ',
'\n',
'\r',
'\t',
'\f',
'\x0b',
'\xa0',
'\u2000',
'\u2001',
'\u2002',
'\u2003',
'\u2004',
'\u2005',
'\u2006',
'\u2007',
'\u2008',
'\u2009',
'\u200a',
'\u200b',
'\u2028',
'\u2029',
'\u3000'
].join('');
var finalString = '';
var l = 0;
var i = 0;
str += '';

if (charlist) {
whitespace = (charlist + '').replace(/([[\]().?/*{}+$^:])/g, '$1');
}

l = str.length;
for (i = 0; i < l; i += 1) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(i);
break;
}
}

l = str.length;
for (i = l - 1; i >= 0; i -= 1) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(0, i + 1);
break;
}
}

if (whitespace.indexOf(str.charAt(0)) === -1) {
finalString = str;
}

return finalString;
}
var phpTrim = require('trim-php');

function trimWords(text, numWords, more) {
if (!numWords) {
Expand All @@ -77,7 +10,11 @@ function trimWords(text, numWords, more) {
more = '&hellip;';
}

text = stripTags(text);
// StripTags
text = text.replace(/<(script|style)[^>]*?>.*?<\/\\1>/si, '');
text = text.replace(/<[^>]*>/g, '');
text = phpTrim.trimPhp(text);

var wordsArray = text.split(/[\n\r\t ]+/, numWords + 1);
var sep = ' ';

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trim-words",
"version": "1.0.0",
"version": "1.1.0",
"description": "Trims text to a certain number of words.",
"main": "index.js",
"scripts": {
Expand All @@ -23,5 +23,8 @@
"url": "https://github.com/samiahmedsiddiqui/trim-words/issues"
},
"homepage": "https://github.com/samiahmedsiddiqui/trim-words#readme",
"dependencies": {
"trim-php": "^1.0.0"
},
"runkitExampleFilename": "test/runkit.js"
}

0 comments on commit a6bb922

Please sign in to comment.