app/js/common/stringformat.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 9
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
mnd 1
bc 1
fnc 1
dl 0
loc 9
rs 10
bpm 1
cpm 2
noi 2
c 0
b 0
f 0
1
// jshint esversion: 8
2
3
/*
4
  .format String Prototype
5
    formats a given string with input parameters
6
  parameters
7
    string + x (string) - String to include in string
8
 */
9
String.prototype.format = function() {
0 ignored issues
show
Compatibility Best Practice introduced by
You are extending the built-in type String. This may have unintended consequences on other objects using this built-in type. Consider subclassing instead.
Loading history...
10
  var a = this;
11
  for (var k in arguments) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
12
    a = a.replace(new RegExp("\\{" + k + "\\}", 'g'), arguments[k]);
13
  }
14
  return a;
15
};
16
17
exports = String.prototype.format;
18