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

i18next / i18next / #12521

19 Apr 2018 07:07AM UTC coverage: 87.441% (+2.0%) from 85.448%
#12521

push

jamuhl
rebuild

933 of 1067 relevant lines covered (87.44%)

38.24 hits per line

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

94.64
/src/utils.js
1
export function makeString(object) {
2
  if (object == null) return '';
3
  /* eslint prefer-template: 0 */
1✔
4
  return '' + object;
5
}
6

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

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

×
18
  function canNotTraverseDeeper() {
19
    return !object || typeof object === 'string';
20
  }
1✔
21

20✔
22
  const stack = (typeof path !== 'string') ? [].concat(path) : path.split('.');
120✔
23
  while (stack.length > 1) {
24
    if (canNotTraverseDeeper()) return {};
25

26
    const key = cleanKey(stack.shift());
1✔
27
    if (!object[key] && Empty) object[key] = new Empty();
1✔
28
    object = object[key];
658✔
29
  }
30

31
  if (canNotTraverseDeeper()) return {};
1✔
32
  return {
716✔
33
    obj: object,
34
    k: cleanKey(stack.shift())
35
  };
265✔
36
}
265✔
37

493✔
38
export function setPath(object, path, newValue) {
39
  const { obj, k } = getLastOfPath(object, path, Object);
451✔
40

451✔
41
  obj[k] = newValue;
451✔
42
}
43

44
export function pushPath(object, path, newValue, concat) {
223✔
45
  const { obj, k } = getLastOfPath(object, path, Object);
207✔
46

47
  obj[k] = obj[k] || [];
48
  if (concat) obj[k] = obj[k].concat(newValue);
49
  if (!concat) obj[k].push(newValue);
50
}
51

1✔
52
export function getPath(object, path) {
16✔
53
  const { obj, k } = getLastOfPath(object, path);
54

55
  if (!obj) return undefined;
56
  return obj[k];
16✔
57
}
58

59
export function deepExtend(target, source, overwrite) {
1✔
60
  /* eslint no-restricted-syntax: 0 */
1✔
61
  for (const prop in source) {
62
    if (prop in target) {
63
      // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch
64
      if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
1✔
65
        if (overwrite) target[prop] = source[prop];
1✔
66
      } else {
1✔
67
        deepExtend(target[prop], source[prop], overwrite);
68
      }
69
    } else {
1✔
70
      target[prop] = source[prop];
248✔
71
    }
72
  }
73
  return target;
74
}
248✔
75

190✔
76
export function regexEscape(str) {
77
  /* eslint no-useless-escape: 0 */
78
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
1✔
79
}
80

4✔
81
/* eslint-disable */
6✔
82
var _entityMap = {
83
  "&": "&",
2✔
84
  "<": "&lt;",
2✔
85
  ">": "&gt;",
86
  '"': '&quot;',
×
87
  "'": '&#39;',
88
  "/": '&#x2F;'
89
};
4✔
90
/* eslint-enable */
91

92
export function escape(data) {
4✔
93
  if (typeof data === 'string') {
94
    return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
95
  }
1✔
96

97
  return data;
90✔
98
}
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