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

i18next / i18next / #39978

20 Sep 2021 12:34PM UTC coverage: 94.049% (+2.9%) from 91.16%
#39978

push

web-flow
Updated i18next compat dependencies (#1655)

* updated i18next-localstorage-cache

* updated i18next-browser-languagedetector

1287 of 1737 branches covered (74.09%)

1201 of 1277 relevant lines covered (94.05%)

106.48 hits per line

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

97.47
/src/utils.js
1
// http://lea.verou.me/2016/12/resolve-promises-externally-with-this-one-weird-trick/
2
export function defer() {
3
  let res;
1✔
4
  let rej;
5

6
  const promise = new Promise((resolve, reject) => {
1✔
7
    res = resolve;
1✔
8
    rej = reject;
1✔
9
  });
1✔
10

1✔
11
  promise.resolve = res;
1✔
12
  promise.reject = rej;
1✔
13

1✔
14
  return promise;
1✔
15
}
1✔
16

1✔
17
export function makeString(object) {
1✔
18
  if (object == null) return '';
19
  /* eslint prefer-template: 0 */
20
  return '' + object;
21
}
22

23
export function copy(a, s, t) {
49✔
24
  a.forEach(m => {
49✔
25
    if (s[m]) t[m] = s[m];
49✔
26
  });
27
}
49✔
28

49✔
29
function getLastOfPath(object, path, Empty) {
49✔
30
  function cleanKey(key) {
31
    return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
32
  }
33

10✔
34
  function canNotTraverseDeeper() {
35
    return !object || typeof object === 'string';
36
  }
5✔
37

38
  const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
39
  while (stack.length > 1) {
40
    if (canNotTraverseDeeper()) return {};
50✔
41

350✔
42
    const key = cleanKey(stack.shift());
43
    if (!object[key] && Empty) object[key] = new Empty();
44
    // prevent prototype pollution
45
    if (Object.prototype.hasOwnProperty.call(object, key)) {
46
      object = object[key];
47
    } else {
1,968!
48
      object = {};
49
    }
50
  }
51

1,983✔
52
  if (canNotTraverseDeeper()) return {};
53
  return {
54
    obj: object,
763✔
55
    k: cleanKey(stack.shift()),
56
  };
763✔
57
}
1,221✔
58

1,220✔
59
export function setPath(object, path, newValue) {
1,220✔
60
  const { obj, k } = getLastOfPath(object, path, Object);
61

1,220✔
62
  obj[k] = newValue;
982✔
63
}
64

238✔
65
export function pushPath(object, path, newValue, concat) {
66
  const { obj, k } = getLastOfPath(object, path, Object);
67

68
  obj[k] = obj[k] || [];
762✔
69
  if (concat) obj[k] = obj[k].concat(newValue);
748✔
70
  if (!concat) obj[k].push(newValue);
71
}
72

73
export function getPath(object, path) {
74
  const { obj, k } = getLastOfPath(object, path);
75

76
  if (!obj) return undefined;
31✔
77
  return obj[k];
31✔
78
}
31✔
79

80
export function getPathWithDefaults(data, defaultData, key) {
31✔
81
  const value = getPath(data, key);
82
  if (value !== undefined) {
83
    return value;
84
  }
8✔
85
  // Fallback to default values
8✔
86
  return getPath(defaultData, key);
8✔
87
}
88

8✔
89
export function deepExtend(target, source, overwrite) {
8!
90
  /* eslint no-restricted-syntax: 0 */
8!
91
  for (const prop in source) {
92
    if (prop !== '__proto__' && prop !== 'constructor') {
93
      if (prop in target) {
94
        // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch
724✔
95
        if (
724✔
96
          typeof target[prop] === 'string' ||
724✔
97
          target[prop] instanceof String ||
98
          typeof source[prop] === 'string' ||
724✔
99
          source[prop] instanceof String
709✔
100
        ) {
101
          if (overwrite) target[prop] = source[prop];
102
        } else {
103
          deepExtend(target[prop], source[prop], overwrite);
134✔
104
        }
105
      } else {
134✔
106
        target[prop] = source[prop];
120✔
107
      }
108
    }
109
  }
110
  return target;
14✔
111
}
112

113
export function regexEscape(str) {
114
  /* eslint no-useless-escape: 0 */
115
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
6✔
116
}
8✔
117

6✔
118
/* eslint-disable */
119
var _entityMap = {
2!
120
  '&': '&',
2✔
121
  '<': '&lt;',
122
  '>': '&gt;',
×
123
  '"': '&quot;',
124
  "'": '&#39;',
125
  '/': '&#x2F;',
4✔
126
};
127
/* eslint-enable */
128

129
export function escape(data) {
130
  if (typeof data === 'string') {
6✔
131
    return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
132
  }
133

134
  return data;
135
}
174✔
136

137
export const isIE10 =
138
  typeof window !== 'undefined' &&
139
  window.navigator &&
140
  window.navigator.userAgent &&
1✔
141
  window.navigator.userAgent.indexOf('MSIE') > -1;
142

143
const chars = [' ', ',', '?', '!', ';'];
144
export function looksLikeObjectPath(key, nsSeparator, keySeparator) {
145
  nsSeparator = nsSeparator || '';
146
  keySeparator = keySeparator || '';
147
  const possibleChars = chars.filter(
148
    c => nsSeparator.indexOf(c) < 0 || keySeparator.indexOf(c) < 0,
149
  );
150
  if (possibleChars.length === 0) return true;
151
  const r = new RegExp(`(${possibleChars.map(c => (c === '?' ? '\\?' : c)).join('|')})`);
105!
152
  return !r.test(key);
105✔
153
}
21✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc