Repository: plexis-js/plexis
Pull request #111 (2019-11-05 02:29:27)

feat: `toEllipsis / truncate / fit`
Please merge new toEllipsis feature.

codecov[bot]: # [Codecov](https://codecov.io/gh/plexis-js/plexis/pull/111?src=pr&el=h1) Report
> Merging [#111](https://codecov.io/gh/plexis-js/plexis/pull/111?src=pr&el=desc) into [master](https://codecov.io/gh/plexis-js/plexis/commit/26ca84e0b4dd70472922efb4a17b13b6cf03fc97?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.


[![Impacted file tree graph](https://codecov.io/gh/plexis-js/plexis/pull/111/graphs/tree.svg?width=650&token=DdDVC9ByG1&height=150&src=pr)](https://codecov.io/gh/plexis-js/plexis/pull/111?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #111   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          38     39    +1     
  Lines         182    186    +4     
=====================================
+ Hits          182    186    +4
```


| [Impacted Files](https://codecov.io/gh/plexis-js/plexis/pull/111?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/toEllipsis/src/index.js](https://codecov.io/gh/plexis-js/plexis/pull/111/diff?src=pr&el=tree#diff-cGFja2FnZXMvdG9FbGxpcHNpcy9zcmMvaW5kZXguanM=) | `100% <100%> (ø)` | |

stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

protob: It's just a comment to remove wontfix label
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > 
> 
> This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes: 
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes: 
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > 
> 
> This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

protob: @vorillaz, Could you merge this feature please?
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > 
> 
> This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
AngelGzS: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

👀
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
AngelGzS: 👀
stale[bot]: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

papb: > 
> 
> This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. May the force be with you!

:eyes:
vorillaz: Oops, sorry for that merging this one!

Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index 79ac1fb..1efe3fe 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -36,4 +36,5 @@
 - [withoutHTML](/packages/withoutHTML)
 - [withoutIndent](/packages/withoutIndent)
 - [tail](/packages/tail)
+- [toEllipsis](/packages/toEllipsis)
 - [toSwap](/packages/toSwap)
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index 63baea8..4ac49db 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -48,7 +48,8 @@
     "@plexis/without-diacritics": "^0.0.22",
     "@plexis/without-html": "^0.0.22",
     "@plexis/without-indent": "^0.0.22",
-    "@plexis/is-empty": "^0.0.22"
+    "@plexis/is-empty": "^0.0.22",
+    "@plexis/to-ellipsis": "^0.0.22"
   },
   "keywords": [
     "utility",
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index 2b9b287..80929ea 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -71,3 +71,4 @@ export {default as withoutHTML, default as removeHTML} from '@plexis/without-htm
 export {default as isEmpty} from '@plexis/is-empty';
 export {default as tail, default as rest, default as last, default as pop} from '@plexis/tail';
 export {default as toSwap, default as swap} from '@plexis/to-swap';
+export {default as toEllipsis, default as truncate, default as fit} from '@plexis/to-ellipsis';
diff --git a/packages/toEllipsis/README.md b/packages/toEllipsis/README.md
new file mode 100644
index 0000000..9bcf134
--- /dev/null
+++ b/packages/toEllipsis/README.md
@@ -0,0 +1,24 @@
+# `@plexis/to-ellipsis`
+
+Truncates the input text to the desired length.
+
+**Installation**
+`npm i @plexis/to-ellipsis`
+
+**Usage**
+
+```javascript
+import toEllipsis from '@plexis/to-ellipsis';
+
+toEllipsis('foo'); // retruns 'foo'
+toEllipsis('foo', 1); // retruns  'f..'
+toEllipsis('foo', 3); // retruns 'foo'
+toEllipsis('Last night I dreamt I went to Manderley again.', 5); // retruns 'Last ...'
+```
+
+## Aliases
+
+```javascript
+import toEllipsis from '@plexis/to-ellipsis';
+import {toEllipsis, truncate, fit} from 'plexis';
+```
diff --git a/packages/toEllipsis/package.json b/packages/toEllipsis/package.json
new file mode 100644
index 0000000..e8e39ae
--- /dev/null
+++ b/packages/toEllipsis/package.json
@@ -0,0 +1,30 @@
+{
+  "name": "@plexis/to-ellipsis",
+  "version": "0.0.22",
+  "description": "Truncates the input text to the desired length.",
+  "keywords": [
+    "utility",
+    "string",
+    "truncate"
+  ],
+  "author": "protob <protobx@gmail.com>",
+  "homepage": "https://github.com/plexis-js/plexis.git",
+  "license": "MIT",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "publishConfig": {
+    "access": "public"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "bugs": {
+    "url": "https://github.com/plexis-js/plexis/issues"
+  }
+}
diff --git a/packages/toEllipsis/src/index.js b/packages/toEllipsis/src/index.js
new file mode 100644
index 0000000..6e0e620
--- /dev/null
+++ b/packages/toEllipsis/src/index.js
@@ -0,0 +1,18 @@
+/**
+ * @description Truncates the input text to the desired length.
+ * @param {String} string
+ * @param {Number} limit
+ * @example
+ * toEllipsis('foo'); //=> 'foo'
+ * toEllipsis('foo', 1); // => 'f..'
+ * toEllipsis('foo', 3); // => 'foo'
+ * toEllipsis('Last night I dreamt I went to Manderley again.', 5);  // => 'Last ...'
+ */
+
+const toEllipsis = (string, limit) => {
+  if (isNaN(limit)) return string;
+  const suffix = string.length <= limit ? '' : '...';
+  return string.substring(0, limit) + suffix;
+};
+
+export default toEllipsis;


Test patch:
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index 35bec8d..17b1fd7 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -78,5 +78,8 @@ Array [
   "pop",
   "toSwap",
   "swap",
+  "toEllipsis",
+  "truncate",
+  "fit",
 ]
 `;
diff --git a/packages/toEllipsis/test/index.js b/packages/toEllipsis/test/index.js
new file mode 100644
index 0000000..6061d51
--- /dev/null
+++ b/packages/toEllipsis/test/index.js
@@ -0,0 +1,21 @@
+'use strict';
+
+import toEllipsis from '../src';
+
+describe('@plexis/toEllipsis', () => {
+  it('should retrun ...', () => {
+    expect(toEllipsis('foo', 0)).toBe('...');
+  });
+  it('should retrun foo', () => {
+    expect(toEllipsis('foo')).toBe('foo');
+  });
+  it('should retrun foo', () => {
+    expect(toEllipsis('foo', Infinity)).toBe('foo');
+  });
+  it('should retrun foo', () => {
+    expect(toEllipsis('foo', 3)).toBe('foo');
+  });
+  it('should retrun Last ...', () => {
+    expect(toEllipsis('Last night I dreamt I went to Manderley again.', 5)).toBe('Last ...');
+  });
+});