Commit e6041089 by Sebastián Katzer

Better type checking

parent 8a8a399e
......@@ -159,7 +159,7 @@ exports.update = function (opts, callback, scope) {
exports.clear = function (ids, callback, scope) {
ids = Array.isArray(ids) ? ids : [ids];
ids = this.convertIds(ids);
ids = this.convertIds(ids);
this.exec('clear', ids, callback, scope);
};
......@@ -488,12 +488,22 @@ exports.onclear = function (id, state, json, data) {};
exports.mergeWithDefaults = function (options) {
var defaults = this.getDefaults();
options.date = this.getValueFor(options, 'date', 'at', 'firstAt');
options.repeat = this.getValueFor(options, 'repeat', 'every');
options.message = this.getValueFor(options, 'message', 'text');
for (var key in defaults) {
if (options[key] === null || options[key] === undefined) {
options[key] = defaults[key];
}
}
for (key in options) {
if (!defaults.hasOwnProperty(key)) {
delete options[key];
}
}
return options;
};
......@@ -509,24 +519,18 @@ exports.mergeWithDefaults = function (options) {
* The converted property list
*/
exports.convertProperties = function (options) {
if (options.id) {
options.id = options.id.toString();
}
if (options.date === undefined) {
if (options.date === undefined || options.date === null) {
options.date = new Date();
}
if (options.title) {
options.title = options.title.toString();
}
if (options.message) {
options.message = options.message.toString();
}
options.id = options.id.toString();
options.title = options.title.toString();
options.message = options.message.toString();
options.autoCancel = options.autoCancel === true;
if (options.text) {
options.message = options.text.toString();
if (isNaN(options.badge)) {
options.badge = this.getDefaults().badge;
}
if (typeof options.date == 'object') {
......@@ -613,6 +617,27 @@ exports.convertIds = function (ids) {
/**
* @private
*
* Return the first found value for the given keys.
*
* @param {Object} options
* Object with key-value properties
*
* @param {String[]} keys*
* Key list
*/
exports.getValueFor = function (options) {
var keys = Array.apply(null, arguments).slice(1);
for (var key in keys) {
if (options.hasOwnProperty(key)) {
return options[key];
}
}
};
/**
* @private
*
* Executes the native counterpart.
*
* @param {String} action
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment