1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | "use strict";
|
11 |
|
12 | var argx = require('argx');
|
13 |
|
14 | var ELLIPSIS = '...';
|
15 |
|
16 |
|
17 | function chop(text, len, options) {
|
18 | var args = argx(arguments);
|
19 | text = args.shift('string');
|
20 | len = args.shift('number');
|
21 | options = args.pop('object') || {};
|
22 | if(text.length < len){
|
23 | return text;
|
24 | }
|
25 | if (options.ellipsis) {
|
26 | return text.substr(0, len - ELLIPSIS.length) + ELLIPSIS;
|
27 | } else {
|
28 | return text.substr(0, len);
|
29 | }
|
30 |
|
31 | }
|
32 | chop.ELLIPSIS = ELLIPSIS;
|
33 |
|
34 | module.exports = chop;
|