aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/js/common.js
blob: 07268f42cfb69098e234a93d151a8541d7dd0fe3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com>
// This file is licensed under the terms of the MIT License.
// See LICENSE.txt for details.

if (!String.prototype.format) {
  String.prototype.format = function() {
    var str = this.toString();
    if (!arguments.length)
      return str;
    switch (typeof arguments[0]) {
      case 'string':
      case 'number':
        var args = arguments;
        break;
      default:
        var args = arguments[0];
        break;
    }
    for (var arg in args)
      str = str.replace(new RegExp('\\{' + arg + '\\}', 'gi'), args[arg]);
    return str;
  }
}