Passed
Push — master ( 61dd3f...482d1b )
by greg
01:51
created

src/cli/cms/templates/handlebars/truncate.js   A

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 16
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 4
c 1
b 0
f 0
nc 1
mnd 2
bc 3
fnc 1
dl 0
loc 16
rs 10
bpm 3
cpm 4
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A truncate.js ➔ truncate 0 14 4
1
import Handlebars from 'handlebars'
2
3
export default function truncate(str, len) {
4
  if (typeof str !== 'undefined' && str.length > len) {
5
    new_str = new Handlebars.SafeString (str)
0 ignored issues
show
Unused Code introduced by
The assignment to variable new_str seems to be never used. Consider removing it.
Loading history...
6
    var new_str = str + ' '
7
    new_str = str.substr (0, len)
8
    new_str = str.substr (0, new_str.lastIndexOf(' '))
9
    new_str = (new_str.length > 0) ? new_str : str.substr (0, len)
10
11
    return new_str +'...' 
12
  } else {
13
    
14
    return ''
15
  }
16
}
17