GUI -- Moved cap() utility function into FnService.
Change-Id: I0afdb38e5b37e085ffebaedc74d3cb2857472b12
Showing
3 changed files
with
21 additions
and
10 deletions
... | @@ -63,16 +63,9 @@ | ... | @@ -63,16 +63,9 @@ |
63 | // =========================================== | 63 | // =========================================== |
64 | // === Function Definitions === | 64 | // === Function Definitions === |
65 | 65 | ||
66 | - | ||
67 | - // TODO: move this to FnService. | ||
68 | - function cap(s) { | ||
69 | - return s.replace(/^[a-z]/, function (m) { return m.toUpperCase(); }); | ||
70 | - } | ||
71 | - | ||
72 | - | ||
73 | function mkKeyDisp(id) { | 66 | function mkKeyDisp(id) { |
74 | var v = keyDisp[id] || id; | 67 | var v = keyDisp[id] || id; |
75 | - return cap(v); | 68 | + return fs.cap(v); |
76 | } | 69 | } |
77 | 70 | ||
78 | function addSeparator(el, i) { | 71 | function addSeparator(el, i) { | ... | ... |
... | @@ -143,6 +143,13 @@ | ... | @@ -143,6 +143,13 @@ |
143 | return found; | 143 | return found; |
144 | } | 144 | } |
145 | 145 | ||
146 | + // return the given string with the first character capitalized. | ||
147 | + function cap(s) { | ||
148 | + return s.replace(/^[a-z]/, function (m) { | ||
149 | + return m.toUpperCase(); | ||
150 | + }); | ||
151 | + } | ||
152 | + | ||
146 | angular.module('onosUtil') | 153 | angular.module('onosUtil') |
147 | .factory('FnService', ['$window', function (_$window_) { | 154 | .factory('FnService', ['$window', function (_$window_) { |
148 | $window = _$window_; | 155 | $window = _$window_; |
... | @@ -158,7 +165,8 @@ | ... | @@ -158,7 +165,8 @@ |
158 | windowSize: windowSize, | 165 | windowSize: windowSize, |
159 | find: find, | 166 | find: find, |
160 | inArray: inArray, | 167 | inArray: inArray, |
161 | - removeFromArray: removeFromArray | 168 | + removeFromArray: removeFromArray, |
169 | + cap: cap | ||
162 | }; | 170 | }; |
163 | }]); | 171 | }]); |
164 | 172 | ... | ... |
... | @@ -202,7 +202,7 @@ describe('factory: fw/util/fn.js', function() { | ... | @@ -202,7 +202,7 @@ describe('factory: fw/util/fn.js', function() { |
202 | expect(fs.areFunctions(fs, [ | 202 | expect(fs.areFunctions(fs, [ |
203 | 'isF', 'isA', 'isS', 'isO', 'contains', | 203 | 'isF', 'isA', 'isS', 'isO', 'contains', |
204 | 'areFunctions', 'areFunctionsNonStrict', 'windowSize', 'find', | 204 | 'areFunctions', 'areFunctionsNonStrict', 'windowSize', 'find', |
205 | - 'inArray', 'removeFromArray' | 205 | + 'inArray', 'removeFromArray', 'cap' |
206 | ])).toBeTruthy(); | 206 | ])).toBeTruthy(); |
207 | }); | 207 | }); |
208 | 208 | ||
... | @@ -325,4 +325,14 @@ describe('factory: fw/util/fn.js', function() { | ... | @@ -325,4 +325,14 @@ describe('factory: fw/util/fn.js', function() { |
325 | expect(array).toEqual(['z', 'z', 'y']); | 325 | expect(array).toEqual(['z', 'z', 'y']); |
326 | }); | 326 | }); |
327 | 327 | ||
328 | + // === Tests for cap() | ||
329 | + it('should ignore non-alpha', function () { | ||
330 | + expect(fs.cap('123')).toEqual('123'); | ||
331 | + }); | ||
332 | + it('should capitalize first char', function () { | ||
333 | + expect(fs.cap('Foo')).toEqual('Foo'); | ||
334 | + expect(fs.cap('foo')).toEqual('Foo'); | ||
335 | + expect(fs.cap('foo bar')).toEqual('Foo bar'); | ||
336 | + }); | ||
337 | + | ||
328 | }); | 338 | }); | ... | ... |
-
Please register or login to post a comment