Example #1
0
          _.each(attributes, function(val, key) {
            if (metadata.attributes[key] ||
                key === 'platform' ||
                key === 'platform_version') return;

            let type = 'unknown';

            if (_.isNumber(val)) type = 'number';
            else if (_.isBoolean(val)) type = 'boolean';
            else if (_.isString(val)) type = 'string';
            else if (_.isArray(val)) type = 'json_array';

            metadata.attributes[key] = { default: val, type: type };
          });
 this.autosave = function () {
     var data = [];
     for (var _i = 0; _i < arguments.length; _i++) {
         data[_i - 0] = arguments[_i];
     }
     var result = _this.validateAndSave.apply(_this, data);
     if (_.isBoolean(result)) {
         return result;
     }
     else {
         _this.autosaveService.trigger(result);
         return true;
     }
 };
Example #3
0
                .end(function (err, res) {
                    if (err) {
                        return done(err);
                    }

                    should.not.exist(res.headers['x-cache-invalidate']);
                    var jsonResponse = res.body;
                    should.exist(jsonResponse);
                    should.exist(jsonResponse.posts);
                    testUtils.API.checkResponse(jsonResponse.posts[0], 'post');
                    jsonResponse.posts[0].page.should.be.ok();
                    _.isBoolean(jsonResponse.posts[0].page).should.eql(true);
                    done();
                });
Example #4
0
function getDescriptor(proxy, field, key ) {

    return {
        enumerable:   _.isBoolean(field.enumerable) ? field.enumerable : true,
        configurable: _.isBoolean(field.configurable) ? field.configurable : true,
        get: function(){ 
            return proxy[key] 
        },
        set: function(val){
            var last = proxy[key]

            if ( val instanceof field.ctor )
                proxy[key] = val
            else if( field.parse)
                proxy[key] = field.parse(val)
            else
                throw TypeError('field: ' + key + 'incorrect type and no parser')

            if( !_.has(proxy.__changes__, key) )
                proxy.__changes__[key] = last
        },
    }
}
var convertValue = function convertValue (value, schema, type) {
  if (_.isUndefined(type)) {
    type = mHelpers.getParameterType(schema);
  }

  // If there is no value, do not convert it
  if (_.isUndefined(value)) {
    return value;
  }

  switch (type) {
  case 'array':
    value = _.map(value, function (item) {
      return convertValue(item, _.isArray(schema.items) ? schema.items[0] : schema.items);
    });

    break;

  case 'boolean':
    if (!_.isBoolean(value)) {
      value = value === 'true' || value === true ? true : false;
    }

    break;

  case 'integer':
    if (!_.isNumber(value)) {
      value = parseInt(value, 10);
    }

    break;

  case 'number':
    if (!_.isNumber(value)) {
      value = parseFloat(value);
    }

    break;

  case 'string':
    if (['date', 'date-time'].indexOf(schema.format) > -1 && !_.isDate(value)) {
      value = new Date(value);
    }

    break;

  }

  return value;
};
Example #6
0
  function timestamp(str) {
    if (_.isBoolean(config.timestamp)) {

      str = config.timestamp ? moment().format() + ":" + config.newline + str : str;

      return str;
    } else if (_.isPlainObject(config.timestamp)) {

      var time = config.timestamp.format ? moment().format(config.timestamp.format) : time = moment().format();
      str = config.timestamp.space ? time + config.timestamp.space + str : time + "\t" + str;

      return str;
    }
  }
	setPropertyValue(propName, propValue) {
		switch(propName) {
			case 'eatTabKey' :
				if(_.isBoolean(propValue)) {
					this.eatTabKey = propValue;
				}
				break;

			case 'caseInsensitive' :
				if(_.isBoolean(propValue)) {
					this.caseInsensitive = propValue;
				}
				break;

			case 'keys' :
				if(Array.isArray(propValue)) {
					this.keys = propValue;
				}
				break;
		}
		
		super.setPropertyValue(propName, propValue);
	}
Example #8
0
  getSelector: function(name, withBase) {
    withBase = _.isBoolean(withBase) ? withBase : true;
    var selector = '';

    if(name && this.selectors[name]) {
      selector = this.selectors[name];
    }

    if(withBase && this.baseSelector) {
      selector = this.baseSelector + ' ' + selector;
    }

    return selector;
  },
Example #9
0
    gitdown.setConfig = (config) => {
        if (!_.isPlainObject(config)) {
            throw new Error('config must be a plain object.');
        }

        if (config.variable && !_.isObject(config.variable.scope)) {
            throw new Error('config.variable.scope must be set and must be an object.');
        }

        if (config.deadlink && !_.isBoolean(config.deadlink.findDeadURLs)) {
            throw new Error('config.deadlink.findDeadURLs must be set and must be a boolean value');
        }

        if (config.deadlink && !_.isBoolean(config.deadlink.findDeadFragmentIdentifiers)) {
            throw new Error('config.deadlink.findDeadFragmentIdentifiers must be set and must be a boolean value');
        }

        if (config.gitinfo && !fs.realpathSync(config.gitinfo.gitPath)) {
            throw new Error('config.gitinfo.gitPath must be set and must resolve an existing file path.');
        }

        instanceConfig = _.defaultsDeep(config, instanceConfig);
    };
Example #10
0
function asBoolean (value) {
  if (_.isBoolean(value)) {
    return value;
  }
  var iValue = parseInt(value);
  if (!isNaN(iValue)) {
    return value !== 0;
  }
  try {
    return !!JSON.parse(value);
  } catch (e) {
    return false;
  }
}
 compareElementPropertyEquality: function(property, value){
     //When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since
     //the value in the selector always comes through as a string
     if(_.isNumber(property)){
         return property === parseInt(value);
     }
     else if(_.isBoolean(property)){
         return property === (value === 'true' ? true : false);
     }
     else if(value === "null"){
         return property === null;
     }
     return property === value;
 }
Example #12
0
var ObjectTerm = exports.ObjectTerm = function(obj, escape) {
    escape = (typeof escape !== 'undefined') ? escape : true;
    var res = '';
    if (_.isPlainObject(obj)) {
        for (var i in obj) {
            if (_.isString(obj[i]) || _.isNumber(obj[i]) || _.isBoolean(obj[i])) {
                res += Term(obj[i], i, escape);
            } else if (_.isPlainObject(obj[i])) {
                res += Term(ObjectTerm(obj[i], escape), i, false);
            }
        }
    }
    return res;
}
Example #13
0
  cout.config = function(opt) {
    config = _.assign(_.extend(defaults, opt));
    //configure moment's locale
    if (_.isBoolean(config.timestamp)) {
      moment.locale('en');
    } else if (_.isPlainObject(config.timestamp)) {
      if (config.timestamp.locale) {
        moment.locale(config.timestamp.locale);
      } else {
        moment.locale('en');
      }

    }
  };
Example #14
0
  function setTagValue(tagName, tagValue, done)
  {
    if (!_.isString(tagName))
    {
      done({
        message: 'Tag name must be a string.',
        code: 'TAG_WRITE_INVALID_NAME'
      });

      return;
    }

    if (!_.isString(tagValue) && !_.isNumber(tagValue) && !_.isBoolean(tagValue))
    {
      done({
        message: 'Tag value must be a string, a number or a boolean.',
        code: 'TAG_WRITE_INVALID_VALUE'
      });

      return;
    }

    const tag = module.tags[tagName];

    if (!tag)
    {
      done({
        message: 'Unknown tag.',
        code: 'TAG_WRITE_UNKNOWN'
      });

      return;
    }

    if (!tag.writable)
    {
      done({
        message: 'Tag is not writable.',
        code: 'TAG_WRITE_NOT_WRITABLE'
      });

      return;
    }

    messengerClient.request('modbus.setTagValue', {name: tagName, value: tagValue}, function(err)
    {
      done(err, tag);
    });
  }
Example #15
0
  /*!
   * Apply document key = require(descriptor
   * @param descriptor
   */
  _applyDocumentKey (descriptor) {
    // find the document key key
    let docKeyFound = false
    for (const prop in descriptor) {
      if (descriptor.hasOwnProperty(prop)) {
        if (utils.isPlainObject(descriptor[prop]) && descriptor[prop].key === true) {
          if (descriptor[prop].index === true) {
            throw new TypeError('Schema key cannot be index field')
          }

          if (descriptor[prop].ref) {
            throw new TypeError('Schema key cannot be reference property')
          }

          if (descriptor[prop].type &&
            descriptor[prop].type !== String &&
            descriptor[prop].type !== Number &&
            descriptor[prop].type !== 'number' &&
            descriptor[prop].type !== 'string') {
            throw new TypeError('Schema expects key to be a String or a Number')
          }

          docKeyFound = true
          this.key.generate = false

          this.key.docKeyKey = prop
          if (_.isString(descriptor[prop].prefix)) {
            this.key.prefix = descriptor[prop].prefix
          }

          if (_.isString(descriptor[prop].suffix)) {
            this.key.suffix = descriptor[prop].suffix
          }

          if (_.isBoolean(descriptor[prop].generate)) {
            this.key.generate = descriptor[prop].generate
          }

          this.descriptor[this.key.docKeyKey] = normalizeProperties.call(this, descriptor[prop], this.key.docKeyKey)
        }
      }
    }

    if (!docKeyFound && !this.key.docKeyKey) {
      // manually add one, should be one-op
      this.key.docKeyKey = 'id'
      this.descriptor[this.key.docKeyKey] = normalizeProperties.call(this, String, this.key.docKeyKey)
    }
  }
Example #16
0
var Producer = function(options) {
  options = options || {};
  this.channel = options.channel;
  this.exchange = options.exchange;
  this.routingKey = options.routingKey;
  this.autoDeclare = _.isBoolean(options.autoDeclare) ? options.autoDeclare : true;
  if (!this.exchange) {
    this.exchange = new Exchange();
  }
  // debug('.constructor.autoDeclare', this.autoDeclare);
  if (this.autoDeclare) {
    this.exchange = this.exchange.use(this.channel);
  }
// debug('.constructor.exchange', this.exchange);
};
Example #17
0
            .end(function (err, res) {
                if (err) {
                    return done(err);
                }

                should.not.exist(res.headers['x-cache-invalidate']);
                var jsonResponse = res.body;
                should.exist(jsonResponse);
                should.exist(jsonResponse.posts);
                localUtils.API.checkResponse(jsonResponse.posts[0], 'post');
                jsonResponse.posts[0].slug.should.equal('welcome');

                _.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
                done();
            });
Example #18
0
    to: function(v) {
      if(_.isBoolean(v)) return v;
      if (_.isNumber(v)){
        if(v === 1) return true;
        if(v === 0) return false;
      }
      if (_.isString(v)) {
        if(v === 'true') return true;
        if(v === 'false') return false;
        if(v === '1') return true;
        if(v === '0') return false;
      }

      throw new Error('E_runtimeInputTypeCoercionError');
    },
Example #19
0
Options.validateBustRequireCacheOption = function (options, functionName, logger) {

  var err;

  if (_.isUndefined(options.bustRequireCache)) {
    return;
  }

  if (_.isBoolean(options.bustRequireCache) === false) {
    err = new errors.ConfigError('Please pass a boolean for the options.bustRequireCache parameter to %s.', functionName);
    logger.error(err);
    throw err;
  }

};
Example #20
0
 return function (array, filterExpr, comparator) {
     var predicateFn;
     if (_.isFunction(filterExpr)) {
         predicateFn = filterExpr;
     } else if (_.isString(filterExpr) || 
         _.isNumber(filterExpr) ||
         _.isBoolean(filterExpr) ||
         _.isNull(filterExpr) ||
         _.isObject(filterExpr)) {
         predicateFn = createPredicateFn(filterExpr, comparator);
     } else {
         return array;
     }
     return _.filter(array, predicateFn);
 };
Example #21
0
        return (input) => {
            if (isBoolean(input)) {
                return input;
            }
            if (input === 'true' || input === 'false') {
                return input === 'true';
            }

            console.log(feedbackMessage(
                warningLabel('Warning', 'Conversion Failed'),
                `Invalid value given for ${chalk.bold(name)}. Will use the default ${chalk.bold(value)}.`
            ));

            return value;
        };
Example #22
0
var HttpBackend = function(browser, options) {
    this.browser = browser;
    this.browserGet = this.browser.get;
    this.options = options;
    this.flow = this.browser.driver.controlFlow;
    if (!this.options || this.options == 'undefined') {
        this.options = {};
    }

    if (!_.isBoolean(this.options.autoSync)) {
        this.options.autoSync = true;
    }

    this.reset();
};
    this.isBoolean = function(value, errors) {
        if (!errors) {
            errors = [];
        }

        if (value !== null && value !== undefined) {
            if (!dash.isBoolean( value )) {
                errors.push( [ 'FIELD value: ', value, ' is not a valid boolean' ].join('') );
            }
        } else {
            errors.push( [ 'FIELD is empty and not a valid boolean' ].join('') );
        }

        return errors;
    };
Example #24
0
MqttNode.prototype._setAttrs = function (oid, iid, rid, attrs) {
    var okey = mutils.oidKey(oid),
        rkey,
        key,
        trg;

    if (arguments.length === 4) {
        rkey = mutils.ridKey(oid, rid);
        key = okey + ':' + iid + ':' + rkey;
    } else if (arguments.length === 3) {
        attrs = rid;
        rid = undefined;
        key = okey + ':' + iid;
    } else if (arguments.length === 2) {
        attrs = iid;
        iid = undefined;
    }

    if (!_.isPlainObject(attrs))
        throw new TypeError('attrs should be given as an object.');

    trg = this._target(oid, iid, rid);

    if (!trg.exist)
        return false;

    // attrs with default settings
    attrs.pmin = _.isNumber(attrs.pmin) ? attrs.pmin : this.so.lwm2mServer[0].defaultMinPeriod;
    attrs.pmax = _.isNumber(attrs.pmax) ? attrs.pmax : this.so.lwm2mServer[0].defaultMaxPeriod;
    attrs.mute = _.isBoolean(attrs.mute) ? attrs.mute : true;
    attrs.cancel = _.isBoolean(attrs.cancel) ? attrs.cancel : true;

    this._repAttrs[key] = attrs;

    return true;
};
Example #25
0
 union: function union(callbacks, wrap) {
   if (arguments.length === 1 || arguments.length === 2 && _.isBoolean(wrap)) {
     if (!Array.isArray(callbacks)) {
       callbacks = [callbacks];
     }
     for (var i = 0, l = callbacks.length; i < l; i++) {
       this._statements.push({
         grouping: 'union',
         clause: 'union',
         value: callbacks[i],
         wrap: wrap || false
       });
     }
   } else {
     callbacks = _.toArray(arguments).slice(0, arguments.length - 1);
     wrap = arguments[arguments.length - 1];
     if (!_.isBoolean(wrap)) {
       callbacks.push(wrap);
       wrap = false;
     }
     this.union(callbacks, wrap);
   }
   return this;
 },
		return when.promise(function(resolve, reject) {
			if (!lodash.isString(id)) {
				reject(new Error('id is required and must be a String'));
				return;
			}

			if (!lodash.isUndefined(refresh) && !lodash.isBoolean(refresh)) {
				reject(new Error('refresh must be a Boolean'));
				return;
			}

			var doc = self.ejs.Document(self.index, self.type, id);
			doc.refresh(!!refresh);
			doc.doDelete(resolve, reject);
		});
Example #27
0
  schemeWhitelist.forEach((scheme) => {
    const isEnabled = isBoolean(settings.thumbnails[scheme.setting])
      ? settings.thumbnails[scheme.setting]
      : scheme.default;

    $('.settings-thumbnails-providers-list').append(`
      <li>
        <input type="checkbox" name="thumbnails.${scheme.setting}" id="${
  scheme.setting
}" ${isEnabled ? 'checked' : ''}>
        <img src="${getFaviconURL(scheme)}" class="favicon-icon" />
        <label for="${scheme.setting}">${scheme.name}</label>
      </li>
    `);
  });
Example #28
0
    (req, res, next) => {
        // TODO: return a better error if `body.selected` is not a boolean
        const layer_id = req.params.layer_id;
        const user = req.user;
        let updated = false;

        const [source_id, ] = split_merged_id(layer_id); // eslint-disable-line array-bracket-spacing
        const source = user.get_source(source_id);
        if (!_.isUndefined(source) && _.isBoolean(req.body.selected)) {
            updated = user.toggle_selected_layer(layer_id, req.body.selected);
        }
        logger.debug('%s patched layer `%s`: %j', req.id, layer_id, req.body);
        res.json(updated);
        next();
    }
Example #29
0
		delete: function(args, cb) {

			var folderId = env.toNumberOrThrow(args.id, 'folder:delete#id');
			var recursive =	_.isBoolean(args.recursive) 
								? args.recursive 
								: false;

			request.del(env.prepare({
				url: util.format(
					'https://api.box.com/2.0/folders/%d?recursive=%s',
					folderId,
					recursive
				)
			}), env.complete(cb));
		},
Example #30
0
 function booleanize (val) {
   var trueOutput = 'Yes';
   var falseOutput = 'No';
   if (_.isNumber(val) && val === 0) {
     val = false;
   }
   if (_.indexOf(['true', 'false', '0'], val) !== -1) {
     val = (val === 'true');
   }
   if (_.isBoolean(val)) {
     return val ? trueOutput : falseOutput;
   } else {
     return val ? val : 'Not known';
   }
 }