Permalink
Browse files

Adding tryGetValueInsensitive

  • Loading branch information...
1 parent 0313627 commit a71c9cf26191ed5b14802becefe8486b02ed82fc Andre Rodrigues committed Oct 11, 2012
Showing with 60 additions and 2 deletions.
  1. +24 −1 lib/services/core/storageservicesettings.js
  2. +24 −0 lib/util/util.js
  3. +2 −1 test/testlist.txt
  4. +10 −0 test/util/util-tests.js
@@ -124,7 +124,30 @@ StorageServiceSettings.developmentStorageAccount = function () {
}
return _devStoreAccount;
-}
+};
+
+/**
+* Gets the default service endpoint using the specified protocol and account
+* name.
+*
+* @param {array} settings The service settings.
+* @param {string} dns The service DNS.
+*
+* @return {string}
+*/
+StorageServiceSettings._getDefaultServiceEndpoint = function (settings, dns) {
+ var scheme = util.tryGetValueInsensitive(
+ ConnectionStringKeys.DEFAULT_ENDPOINTS_PROTOCOL_NAME,
+ settings
+ );
+
+ var accountName = util.tryGetValueInsensitive(
+ ConnectionStringKeys.ACCOUNT_NAME_NAME,
+ settings
+ );
+
+ return url.format({ protocol: scheme, host: accountName + '.' + dns });
+};
/**
* Creates StorageServiceSettings object given endpoints uri.
View
@@ -232,6 +232,30 @@ exports.inArrayInsensitive = function (needle, haystack) {
return _.contains(_.map(haystack, function (h) { return h.toLowerCase() }), needle.toLowerCase());
};
+/**
+* Returns the specified value of the key passed from object and in case that
+* this key doesn't exist, the default value is returned. The key matching is
+* done in a case insensitive manner.
+*
+* @param {string} key The array key.
+* @param {object} haystack The object to be used.
+* @param {mix} default The value to return if $key is not found in $array.
+*
+* @static
+*
+* @return mix
+*/
+exports.tryGetValueInsensitive = function (key, haystack, defaultValue)
+{
+ for (var i in haystack) {
+ if (i.toString().toLowerCase() === key.toString().toLowerCase()) {
+ return haystack[i];
+ }
+ }
+
+ return defaultValue;
+};
+
exports.pathExistsSync = fs.existsSync
? fs.existsSync
: path.existsSync;
View
@@ -1,3 +1,4 @@
services/core/servicesettings-tests.js
services/core/storageservicesettings-tests.js
-util/validate-tests.js
+util/validate-tests.js
+util/util-tests.js
View
@@ -175,4 +175,14 @@ suite('util-tests', function() {
done();
});
+
+ test('Get value case insensitive', function (done) {
+ // int positives
+ assert.equal(util.tryGetValueInsensitive('B', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1');
+ assert.equal(util.tryGetValueInsensitive('b', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), 'b1');
+ assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }), undefined);
+ assert.equal(util.tryGetValueInsensitive('D', { 'a': 'a1', 'b': 'b1', 'c': 'c1' }, 'something'), 'something');
+
+ done();
+ });
});

0 comments on commit a71c9cf

Please sign in to comment.