GUI -- Moved cap() utility function into FnService.

Change-Id: I0afdb38e5b37e085ffebaedc74d3cb2857472b12
This commit is contained in:
Simon Hunt 2015-02-19 14:49:55 -08:00
parent 337bb44579
commit 27a5cc8b45
3 changed files with 21 additions and 10 deletions

View File

@ -63,16 +63,9 @@
// ===========================================
// === Function Definitions ===
// TODO: move this to FnService.
function cap(s) {
return s.replace(/^[a-z]/, function (m) { return m.toUpperCase(); });
}
function mkKeyDisp(id) {
var v = keyDisp[id] || id;
return cap(v);
return fs.cap(v);
}
function addSeparator(el, i) {

View File

@ -143,6 +143,13 @@
return found;
}
// return the given string with the first character capitalized.
function cap(s) {
return s.replace(/^[a-z]/, function (m) {
return m.toUpperCase();
});
}
angular.module('onosUtil')
.factory('FnService', ['$window', function (_$window_) {
$window = _$window_;
@ -158,7 +165,8 @@
windowSize: windowSize,
find: find,
inArray: inArray,
removeFromArray: removeFromArray
removeFromArray: removeFromArray,
cap: cap
};
}]);

View File

@ -202,7 +202,7 @@ describe('factory: fw/util/fn.js', function() {
expect(fs.areFunctions(fs, [
'isF', 'isA', 'isS', 'isO', 'contains',
'areFunctions', 'areFunctionsNonStrict', 'windowSize', 'find',
'inArray', 'removeFromArray'
'inArray', 'removeFromArray', 'cap'
])).toBeTruthy();
});
@ -325,4 +325,14 @@ describe('factory: fw/util/fn.js', function() {
expect(array).toEqual(['z', 'z', 'y']);
});
// === Tests for cap()
it('should ignore non-alpha', function () {
expect(fs.cap('123')).toEqual('123');
});
it('should capitalize first char', function () {
expect(fs.cap('Foo')).toEqual('Foo');
expect(fs.cap('foo')).toEqual('Foo');
expect(fs.cap('foo bar')).toEqual('Foo bar');
});
});