Commit e6041089 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Better type checking

parent 8a8a399e
Loading
Loading
Loading
Loading
+36 −11
Changes for www/local-notification.js: 36 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -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.id         = options.id.toString();
    options.title      = options.title.toString();
    }

    if (options.message) {
    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') {
@@ -610,6 +614,27 @@ exports.convertIds = function (ids) {
    return convertedIds;
};

/**
 * @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
 *