Passed
Push — master ( 4f9324...0fef39 )
by Vinicius
02:07
created

src/page-title.js   A

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 40
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 6
eloc 14
c 1
b 0
f 0
nc 1
mnd 2
bc 4
fnc 2
dl 0
loc 40
ccs 10
cts 10
cp 1
crap 0
rs 10
bpm 2
cpm 3
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A page-title.js ➔ ??? 0 1 1
1 2
import { buildPageTitle, safeString, isFunction } from './utils'
2
3
/**
4
 * if use ssr document is not available
5
 * @method isBrowser
6
 * @return {Boolean}
7
 */
8 11
const isBrowser = () => (typeof document !== 'undefined')
9
10
/**
11
 * update document.title
12
 * @method setPageTitle
13
 * @param  {String}     value new title
14
 * @param  {Object}     options buildPageTitle options
15
 * @return {void}
16
 */
17 2
const setPageTitle = (value, options) => {
18
  // test if not is a browser
19
  /* istanbul ignore next: SSR */
20
  if (!isBrowser()) {
21
    console.warn('no browser enviroment')
22
    return
23
  }
24
25
  // test if title is empty
26 11
  if (safeString(value).length > 0) {
27 9
    const { setTitleMethod } = options
28 9
    const title = buildPageTitle(value, options)
29
30
    // use custom setTitle method
31 9
    if (setTitleMethod && isFunction(setTitleMethod)) {
32 1
      setTitleMethod(title)
33 1
      return
34
    }
35
36 8
    document.title = title
37
  }
38
}
39
40
export { setPageTitle }
41