| Total Complexity | 6 |
| Complexity/F | 3 |
| Lines of Code | 40 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 80% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 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 | 10 | 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 | 10 | if (safeString(value).length > 0) { |
|
| 27 | 8 | const { setTitleMethod } = options |
|
| 28 | 8 | const title = buildPageTitle(value, options) |
|
| 29 | |||
| 30 | // use custom setTitle method |
||
| 31 | 8 | if (setTitleMethod && isFunction(setTitleMethod)) { |
|
| 32 | setTitleMethod(title) |
||
| 33 | return |
||
| 34 | } |
||
| 35 | |||
| 36 | 8 | document.title = title |
|
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | export { setPageTitle } |
||
| 41 |