• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

i18next / i18next / #16043

11 Apr 2017 02:06PM UTC coverage: 66.069% (+0.3%) from 65.798%
#16043

push

jamuhl
update build

590 of 893 relevant lines covered (66.07%)

24.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.55
/src/utils.js
1
export function makeString(object) {
1✔
2
  if (object == null) return '';
5✔
3
  return '' + object;
×
4
}
5

6
export function copy(a, s, t) {
1✔
7
  a.forEach(m => {
13✔
8
    if (s[m]) t[m] = s[m];
65✔
9
  });
10
}
11

12
function getLastOfPath(object, path, Empty) {
1✔
13
  function cleanKey(key) {
1✔
14
    return (key && key.indexOf('###') > -1) ? key.replace(/###/g, '.') : key;
487✔
15
  }
16

17
  let stack = (typeof path !== 'string') ? [].concat(path) : path.split('.');
226✔
18
  while(stack.length > 1) {
226✔
19
    if (!object) return {};
399✔
20

21
    let key = cleanKey(stack.shift());
331✔
22
    if (!object[key] && Empty) object[key] = new Empty();
331✔
23
    object = object[key];
331✔
24
  }
25

26
  if (!object) return {};
158✔
27
  return {
156✔
28
    obj: object,
29
    k: cleanKey(stack.shift())
30
  };
31
}
32

33
export function setPath(object, path, newValue) {
7✔
34
  let { obj, k } = getLastOfPath(object, path, Object);
35

36
  obj[k] = newValue;
7✔
37
}
38

39
export function pushPath(object, path, newValue, concat) {
1✔
40
  let { obj, k } = getLastOfPath(object, path, Object);
41

42
  obj[k] = obj[k] || [];
1✔
43
  if (concat) obj[k] = obj[k].concat(newValue);
1✔
44
  if (!concat) obj[k].push(newValue);
1✔
45
}
46

47
export function getPath(object, path) {
218✔
48
  let { obj, k } = getLastOfPath(object, path);
49

50
  if (!obj) return undefined;
218✔
51
  return obj[k];
52
}
53

148✔
54
export function deepExtend(target, source, overwrite) {
146✔
55
  for (let prop in source)
56
    if (prop in target) {
57
      // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch
2✔
58
      if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
59
        if (overwrite) target[prop] = source[prop];
60
      } else {
1✔
61
        deepExtend(target[prop], source[prop], overwrite);
×
62
      }
×
63
    } else {
64
      target[prop] = source[prop];
×
65
    }
×
66
  return target;
67
}
×
68

69
export function regexEscape(str) {
70
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
×
71
}
72

×
73
/* eslint-disable */
74
var _entityMap = {
75
  "&": "&",
1✔
76
  "<": "&lt;",
60✔
77
  ">": "&gt;",
78
  '"': '&quot;',
79
  "'": '&#39;',
80
  "/": '&#x2F;'
1✔
81
};
82
/* eslint-enable */
83

84
export function escape(data) {
85
  if (typeof data === 'string') {
86
    return data.replace(/[&<>"'\/]/g, function (s) {
87
      return _entityMap[s];
88
    });
89
  } else {
90
    return data;
1✔
91
  }
17✔
92
}
17✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc