You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-18 05:42:00 +03:00
Style checks and more jsdoc.
This commit is contained in:
48
dist/browser-matrix-dev.js
vendored
48
dist/browser-matrix-dev.js
vendored
@@ -308,7 +308,7 @@ MatrixClient.prototype = {
|
|||||||
'bind': bind
|
'bind': bind
|
||||||
};
|
};
|
||||||
return this._http.authedRequestWithPrefix(
|
return this._http.authedRequestWithPrefix(
|
||||||
callback, "POST", path, qps, data, httpApi.PREFIX_V2_ALPHA
|
callback, "POST", path, null, data, httpApi.PREFIX_V2_ALPHA
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ MatrixClient.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isLoggedIn: function() {
|
isLoggedIn: function() {
|
||||||
return this._http.opts.accessToken !== undefined
|
return this._http.opts.accessToken !== undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@@ -741,6 +741,7 @@ var HEADERS = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a MatrixHttpApi.
|
* Construct a MatrixHttpApi.
|
||||||
|
* @constructor
|
||||||
* @param {Object} opts The options to use for this HTTP API.
|
* @param {Object} opts The options to use for this HTTP API.
|
||||||
* @param {string} opts.baseUrl Required. The base client-server URL e.g.
|
* @param {string} opts.baseUrl Required. The base client-server URL e.g.
|
||||||
* 'http://localhost:8008'.
|
* 'http://localhost:8008'.
|
||||||
@@ -937,7 +938,7 @@ module.exports.request = function(r) {
|
|||||||
request = r;
|
request = r;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Construct a Matrix Client. Identical to {@link client/MatrixClient} except
|
* Construct a Matrix Client. Identical to {@link client/MatrixClient} except
|
||||||
* the 'request' option is already specified.
|
* the 'request' option is already specified.
|
||||||
* @param {(Object|string)} opts The configuration options for this client. If
|
* @param {(Object|string)} opts The configuration options for this client. If
|
||||||
@@ -946,6 +947,7 @@ module.exports.request = function(r) {
|
|||||||
* @param {boolean} opts.usePromises True to use promises rather than callbacks.
|
* @param {boolean} opts.usePromises True to use promises rather than callbacks.
|
||||||
* @param {string} opts.accessToken The access_token for this user.
|
* @param {string} opts.accessToken The access_token for this user.
|
||||||
* @param {string} opts.userId The user ID for this user.
|
* @param {string} opts.userId The user ID for this user.
|
||||||
|
* @return {MatrixClient} A new matrix client.
|
||||||
*/
|
*/
|
||||||
module.exports.createClient = function(opts) {
|
module.exports.createClient = function(opts) {
|
||||||
if (typeof opts === "string") {
|
if (typeof opts === "string") {
|
||||||
@@ -1166,7 +1168,12 @@ module.exports = MatrixInMemoryStore;
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
// avoiding deps on jquery and co
|
/**
|
||||||
|
* Encode a dictionary of query parameters.
|
||||||
|
* @param {Object} params A dict of key/values to encode e.g.
|
||||||
|
* {"foo": "bar", "baz": "taz"}
|
||||||
|
* @return {string} The encoded string e.g. foo=bar&baz=taz
|
||||||
|
*/
|
||||||
module.exports.encodeParams = function(params) {
|
module.exports.encodeParams = function(params) {
|
||||||
var qs = "";
|
var qs = "";
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
@@ -1177,6 +1184,14 @@ module.exports.encodeParams = function(params) {
|
|||||||
return qs.substring(1);
|
return qs.substring(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a URI according to a set of template variables. Variables will be
|
||||||
|
* passed through encodeURIComponent.
|
||||||
|
* @param {string} pathTemplate The path with template variables e.g. '/foo/$bar'.
|
||||||
|
* @param {Object} variables The key/value pairs to replace the template
|
||||||
|
* variables with. E.g. { "$bar": "baz" }.
|
||||||
|
* @return {string} The result of replacing all template variables e.g. '/foo/baz'.
|
||||||
|
*/
|
||||||
module.exports.encodeUri = function(pathTemplate, variables) {
|
module.exports.encodeUri = function(pathTemplate, variables) {
|
||||||
for (var key in variables) {
|
for (var key in variables) {
|
||||||
if (!variables.hasOwnProperty(key)) { continue; }
|
if (!variables.hasOwnProperty(key)) { continue; }
|
||||||
@@ -1187,6 +1202,13 @@ module.exports.encodeUri = function(pathTemplate, variables) {
|
|||||||
return pathTemplate;
|
return pathTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a map function to the given array.
|
||||||
|
* @param {Array} array The array to apply the function to.
|
||||||
|
* @param {Function} fn The function that will be invoked for each element in
|
||||||
|
* the array.
|
||||||
|
* @return {Array} A new array with the results of the function.
|
||||||
|
*/
|
||||||
module.exports.map = function(array, fn) {
|
module.exports.map = function(array, fn) {
|
||||||
var results = new Array(array.length);
|
var results = new Array(array.length);
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
@@ -1195,10 +1217,21 @@ module.exports.map = function(array, fn) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given thing is a function.
|
||||||
|
* @param {*} value The thing to check.
|
||||||
|
* @return {boolean} True if it is a function.
|
||||||
|
*/
|
||||||
module.exports.isFunction = function(value) {
|
module.exports.isFunction = function(value) {
|
||||||
return Object.prototype.toString.call(value) == "[object Function]";
|
return Object.prototype.toString.call(value) == "[object Function]";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the given object has the specified keys.
|
||||||
|
* @param {Object} obj The object to check.
|
||||||
|
* @param {string[]} keys The list of keys that 'obj' must have.
|
||||||
|
* @throws If the object is missing keys.
|
||||||
|
*/
|
||||||
module.exports.checkObjectHasKeys = function(obj, keys) {
|
module.exports.checkObjectHasKeys = function(obj, keys) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
if (!obj.hasOwnProperty(keys[i])) {
|
if (!obj.hasOwnProperty(keys[i])) {
|
||||||
@@ -1207,6 +1240,12 @@ module.exports.checkObjectHasKeys = function(obj, keys) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the given object has no extra keys other than the specified ones.
|
||||||
|
* @param {Object} obj The object to check.
|
||||||
|
* @param {string[]} allowedKeys The list of allowed key names.
|
||||||
|
* @throws If there are extra keys.
|
||||||
|
*/
|
||||||
module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
|
module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (!obj.hasOwnProperty(key)) { continue; }
|
if (!obj.hasOwnProperty(key)) { continue; }
|
||||||
@@ -1215,6 +1254,7 @@ module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
},{}],7:[function(require,module,exports){
|
},{}],7:[function(require,module,exports){
|
||||||
// Browser Request
|
// Browser Request
|
||||||
//
|
//
|
||||||
|
@@ -307,7 +307,7 @@ MatrixClient.prototype = {
|
|||||||
'bind': bind
|
'bind': bind
|
||||||
};
|
};
|
||||||
return this._http.authedRequestWithPrefix(
|
return this._http.authedRequestWithPrefix(
|
||||||
callback, "POST", path, qps, data, httpApi.PREFIX_V2_ALPHA
|
callback, "POST", path, null, data, httpApi.PREFIX_V2_ALPHA
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -463,7 +463,7 @@ MatrixClient.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isLoggedIn: function() {
|
isLoggedIn: function() {
|
||||||
return this._http.opts.accessToken !== undefined
|
return this._http.opts.accessToken !== undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ var HEADERS = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a MatrixHttpApi.
|
* Construct a MatrixHttpApi.
|
||||||
|
* @constructor
|
||||||
* @param {Object} opts The options to use for this HTTP API.
|
* @param {Object} opts The options to use for this HTTP API.
|
||||||
* @param {string} opts.baseUrl Required. The base client-server URL e.g.
|
* @param {string} opts.baseUrl Required. The base client-server URL e.g.
|
||||||
* 'http://localhost:8008'.
|
* 'http://localhost:8008'.
|
||||||
|
@@ -20,7 +20,7 @@ module.exports.request = function(r) {
|
|||||||
request = r;
|
request = r;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Construct a Matrix Client. Identical to {@link client/MatrixClient} except
|
* Construct a Matrix Client. Identical to {@link client/MatrixClient} except
|
||||||
* the 'request' option is already specified.
|
* the 'request' option is already specified.
|
||||||
* @param {(Object|string)} opts The configuration options for this client. If
|
* @param {(Object|string)} opts The configuration options for this client. If
|
||||||
@@ -29,6 +29,7 @@ module.exports.request = function(r) {
|
|||||||
* @param {boolean} opts.usePromises True to use promises rather than callbacks.
|
* @param {boolean} opts.usePromises True to use promises rather than callbacks.
|
||||||
* @param {string} opts.accessToken The access_token for this user.
|
* @param {string} opts.accessToken The access_token for this user.
|
||||||
* @param {string} opts.userId The user ID for this user.
|
* @param {string} opts.userId The user ID for this user.
|
||||||
|
* @return {MatrixClient} A new matrix client.
|
||||||
*/
|
*/
|
||||||
module.exports.createClient = function(opts) {
|
module.exports.createClient = function(opts) {
|
||||||
if (typeof opts === "string") {
|
if (typeof opts === "string") {
|
||||||
|
39
lib/utils.js
39
lib/utils.js
@@ -1,7 +1,12 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
// avoiding deps on jquery and co
|
/**
|
||||||
|
* Encode a dictionary of query parameters.
|
||||||
|
* @param {Object} params A dict of key/values to encode e.g.
|
||||||
|
* {"foo": "bar", "baz": "taz"}
|
||||||
|
* @return {string} The encoded string e.g. foo=bar&baz=taz
|
||||||
|
*/
|
||||||
module.exports.encodeParams = function(params) {
|
module.exports.encodeParams = function(params) {
|
||||||
var qs = "";
|
var qs = "";
|
||||||
for (var key in params) {
|
for (var key in params) {
|
||||||
@@ -12,6 +17,14 @@ module.exports.encodeParams = function(params) {
|
|||||||
return qs.substring(1);
|
return qs.substring(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a URI according to a set of template variables. Variables will be
|
||||||
|
* passed through encodeURIComponent.
|
||||||
|
* @param {string} pathTemplate The path with template variables e.g. '/foo/$bar'.
|
||||||
|
* @param {Object} variables The key/value pairs to replace the template
|
||||||
|
* variables with. E.g. { "$bar": "baz" }.
|
||||||
|
* @return {string} The result of replacing all template variables e.g. '/foo/baz'.
|
||||||
|
*/
|
||||||
module.exports.encodeUri = function(pathTemplate, variables) {
|
module.exports.encodeUri = function(pathTemplate, variables) {
|
||||||
for (var key in variables) {
|
for (var key in variables) {
|
||||||
if (!variables.hasOwnProperty(key)) { continue; }
|
if (!variables.hasOwnProperty(key)) { continue; }
|
||||||
@@ -22,6 +35,13 @@ module.exports.encodeUri = function(pathTemplate, variables) {
|
|||||||
return pathTemplate;
|
return pathTemplate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a map function to the given array.
|
||||||
|
* @param {Array} array The array to apply the function to.
|
||||||
|
* @param {Function} fn The function that will be invoked for each element in
|
||||||
|
* the array.
|
||||||
|
* @return {Array} A new array with the results of the function.
|
||||||
|
*/
|
||||||
module.exports.map = function(array, fn) {
|
module.exports.map = function(array, fn) {
|
||||||
var results = new Array(array.length);
|
var results = new Array(array.length);
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
@@ -30,10 +50,21 @@ module.exports.map = function(array, fn) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given thing is a function.
|
||||||
|
* @param {*} value The thing to check.
|
||||||
|
* @return {boolean} True if it is a function.
|
||||||
|
*/
|
||||||
module.exports.isFunction = function(value) {
|
module.exports.isFunction = function(value) {
|
||||||
return Object.prototype.toString.call(value) == "[object Function]";
|
return Object.prototype.toString.call(value) == "[object Function]";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the given object has the specified keys.
|
||||||
|
* @param {Object} obj The object to check.
|
||||||
|
* @param {string[]} keys The list of keys that 'obj' must have.
|
||||||
|
* @throws If the object is missing keys.
|
||||||
|
*/
|
||||||
module.exports.checkObjectHasKeys = function(obj, keys) {
|
module.exports.checkObjectHasKeys = function(obj, keys) {
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
if (!obj.hasOwnProperty(keys[i])) {
|
if (!obj.hasOwnProperty(keys[i])) {
|
||||||
@@ -42,6 +73,12 @@ module.exports.checkObjectHasKeys = function(obj, keys) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the given object has no extra keys other than the specified ones.
|
||||||
|
* @param {Object} obj The object to check.
|
||||||
|
* @param {string[]} allowedKeys The list of allowed key names.
|
||||||
|
* @throws If there are extra keys.
|
||||||
|
*/
|
||||||
module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
|
module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
if (!obj.hasOwnProperty(key)) { continue; }
|
if (!obj.hasOwnProperty(key)) { continue; }
|
||||||
|
Reference in New Issue
Block a user