Adding tryGetValueInsensitive
This commit is contained in:
Родитель
03136272d1
Коммит
a71c9cf261
|
@ -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.
|
||||
|
|
|
@ -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;
|
|
@ -1,3 +1,4 @@
|
|||
services/core/servicesettings-tests.js
|
||||
services/core/storageservicesettings-tests.js
|
||||
util/validate-tests.js
|
||||
util/util-tests.js
|
|
@ -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();
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче