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

randing89 / ngrequire / #225

31 Jan 2015 12:59PM UTC coverage: 85.593% (-1.3%) from 86.864%
#225

push

travis-ci

randing89
Fix problem with bracket type of definition

113 of 167 branches covered (67.66%)

20 of 31 new or added lines in 1 file covered. (64.52%)

5 existing lines in 2 files now uncovered.

202 of 236 relevant lines covered (85.59%)

43.68 hits per line

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

55.88
/src/string.js
1
var _ = require('lodash');
1✔
2

3
var dollarRegexp = /\$/gi;
1✔
4

5
/**
6
 * Safe replace
7
 *
8
 * @param suffix
9
 * @returns {boolean}
10
 */
11
if (typeof String.prototype.safeReplace !== 'function') {
1!
12
    String.prototype.safeReplace = function(exp, replacement) {
1✔
13
        return this.replace(exp, replacement.replace(dollarRegexp, '$$$$'));
5✔
14
    };
15
}
16

17
/**
18
 * Format a string
19
 *
20
 * @returns {String}
21
 */
22
if (typeof String.prototype.format !== 'function') {
1!
23
    String.prototype.format = function () {
1✔
24
        var formatted = this;
3✔
25
        for (var i = 0; i < arguments.length; i++) {
3✔
26
            var regexp = new RegExp('\\{' + i + '\\}', 'gi');
5✔
27
            // All $ in string will be replaced with $$
28
            var value = (arguments[i] === undefined) ?
5!
29
                'undefined':
30
                arguments[i].toString();
31
            formatted = formatted.safeReplace(regexp, value);
5✔
32
        }
33

34
        return formatted;
3✔
35
    };
36
}
37

38
if (typeof String.prototype.f !== 'function') {
1!
39
    String.prototype.f = String.prototype.format;
1✔
40
}
41

42
/**
43
 * Test if string start with prefix
44
 *
45
 * @param prefix
46
 * @returns {boolean}
47
 */
48
if (typeof String.prototype.startsWith !== 'function') {
1!
UNCOV
49
    String.prototype.startsWith = function(suffix) {
×
UNCOV
50
        return this.indexOf(suffix) === 0;
×
51
    };
52
}
53

54
/**
55
 * Test if string end with suffix
56
 *
57
 * @param suffix
58
 * @returns {boolean}
59
 */
60
if (typeof String.prototype.endsWith !== 'function') {
1!
UNCOV
61
    String.prototype.endsWith = function(suffix) {
×
62
        return this.indexOf(suffix, this.length - suffix.length) !== -1;
×
63
    };
64
}
65

66
module.exports = {
1✔
67
    nullOrEmpty: function (s) {
68
        return (Object.prototype.toString.call(s) === '[object String]') ?
80✔
69
            (s.trim() === '') :
70
            (s === undefined || s === null);
1!
71
    },
72

73
    camelCase: function (s) {
74
        var self = this;
×
75

76
        if (!this.isUpperCase(s)) {
×
77
            s = (s || '')
×
78
                .replace(/([^\s]\s)([^\s])/g, function (m, g1, g2) {
79
                    return g1 + (self.isUpperCase(g2) ? g2 : self.ucfirst(g2));
×
80
                })
81
                .replace(/([a-z])([A-Z])/g, '$1-$2');
82

83
            // Because Javascript doesn't have look behind
84
            // We add one more dash to every consecutive dashes
85
            // eg -- to ---
86
            // Then split will comsume the extra dash
87
            s = s.replace(/(\w)(-{2})/g, '$1$2-');
×
88

89
            return _.map(s.split(/-(?=\w)/), function (s) {
×
90
                return self.isUpperCase(s) ? s : self.ucfirst(s);
×
91
            }).join('');
92
        }
93

94
        return s;
×
95
    },
96

97
    isUpperCase: function (s) {
98
        s = s || '';
×
99

100
        return s === s.toUpperCase();
×
101
    },
102

103
    ucfirst: function (s) {
104
        return s[0].toUpperCase() + s.slice(1);
×
105
    }
106
};
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