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

i18next / i18next / #51629

17 Mar 2016 09:13AM UTC coverage: 66.667% (+1.9%) from 64.722%
#51629

push

jamuhl
rebuild

514 of 771 relevant lines covered (66.67%)

20.23 hits per line

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

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

6
export function copy(a, s, t) {
1✔
7
  a.forEach(m => {
10✔
8
    if (s[m]) t[m] = s[m];
50✔
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;
330✔
15
  }
16

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

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

26
  if (!object) return {};
112✔
27
  return {
110✔
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) {
135✔
48
  let { obj, k } = getLastOfPath(object, path);
49

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

54
export function deepExtend(target, source, overwrite) {
1✔
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
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 {
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) {
1✔
70
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
34✔
71
}
72

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

84
export function escape(data) {
1✔
85
  if (typeof data === 'string') {
15✔
86
    return data.replace(/[&<>"'\/]/g, function (s) {
15✔
87
      return _entityMap[s];
20✔
88
    });
89
  } else {
90
    return data;
×
91
  }
92
}
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