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

i18next / i18next / #12570

18 Aug 2017 09:06AM UTC coverage: 77.778% (-6.2%) from 83.97%
#12570

push

jamuhl
adds the defaultValue option for getFixedT

0 of 1 new or added line in 1 file covered. (0.0%)

54 existing lines in 3 files now uncovered.

637 of 819 relevant lines covered (77.78%)

29.51 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

59
export function deepExtend(target, source, overwrite) {
1✔
60
  /* eslint no-restricted-syntax: 0 */
61
  for (const prop in source) {
2✔
62
    if (prop in target) {
2✔
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) {
2✔
65
        if (overwrite) target[prop] = source[prop];
2✔
66
      } else {
67
        deepExtend(target[prop], source[prop], overwrite);
×
68
      }
69
    } else {
70
      target[prop] = source[prop];
×
71
    }
72
  }
73
  return target;
2✔
74
}
75

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

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

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

97
  return data;
×
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