How to use dot-object - 10 common examples

To help you get started, we’ve selected a few dot-object examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cult-of-coders / grapher / lib / query / hypernova / assembler.js View on Github external
parent.results.forEach(parentResult => {
            // support dotted fields
            const [root, ...nested] = fieldStorage.split('.');
            const value = dot.pick(root, parentResult);
            if (!value) {
                return;
            }


            const data = [];
            value.forEach(v => {
                const _id = nested.length > 0 ? dot.pick(nested.join('.'), v) : v;
                data.push(_.first(resultsByKeyId[_id]));
            });

            parentResult[childCollectionNode.linkName] = filterAssembledData(
                data,
                { limit, skip }
            );
        });
github giper45 / DockerSecurityPlayground / app / data / docker-converter.js View on Github external
function JDCgetCapabilities(selectedImage) {
  const log = appUtils.getLogger();
  const returnCaps = [];
  if (!selectedImage.labels) {
    return [];
  }
  else {
    const convertedLabels = dot.object(selectedImage.labels);
    if (convertedLabels && convertedLabels.caps_add) {
      const convertedCaps = convertedLabels.caps_add.split(',');
      convertedCaps.forEach((cap) => {
        const cleanedCap = cap.trim();
        // If is a valid cap add
        if (dockerCapabilities.check(cleanedCap)) {
          returnCaps.push(cleanedCap);
        }
        else log.warn(`${cap} is not a valid cap! No converted`);
      });
      // TBD CHECK OF CAPS
      return returnCaps;
    }
    else return [];
  }
}
github origami-cms / cms / packages / core-lib / src / configFile.ts View on Github external
let _obj: Partial | boolean = obj;
        // If the variable is a plugin setting that is contained in aliases
        // Then update the config via the filename not the alias
        const res = /plugins\.([\w-]+)/.exec(key);
        if (res && aliases.plugins[res[1]]) {
          _key = key
            .split('.')
            .slice(2)
            .join('.');
          _obj = obj.plugins![aliases.plugins[res[1]]];
        }

        // Try set the key, however current value may be a boolean or undefined
        // meaning that deeper keys may throw error. If that's the case,
        // then set the value to an empty object, and try again
        dot.str(_key, value, _obj);
      });
github zackiles / elasticsearch-odm / lib / query.js View on Github external
function addExistenceFilters(req, missingFilters, existsFilters){
  // see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-missing-filter.html
  // and https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filters.html

  // is this a filtered query, or a regulat?
  var boolFilter = dot.pick('body.query.filtered', req);

  var getPreviousFilters = function(){
    var andFilters;
    if(boolFilter){
      andFilters = dot.pick('body.query.filtered.query.constant_score.filter.and', req);
    }else{
      andFilters = dot.pick('body.query.constant_score.filter.and', req);
    }
    return andFilters || [];
  };

  var query = {
    constant_score: {
      filter: {
        and: getPreviousFilters()
      }
github zackiles / elasticsearch-odm / lib / query.js View on Github external
return f;
  };

  filter.bool.must = _.map(mustFilters, makeTermFilter);
  filter.bool.must_not = _.map(notFilters, makeTermFilter);

  // Remove any empty filters, Elasticsearch will throw an error.
  _.each(filter.bool, function(v, k) {
    if(!v || !v.length) delete filter.bool[k];
  });

  // No filters found? return now.
  if(_.isEmpty(filter.bool)) return void 0;

  // Is this a new filtered query, or an existing to merge with?
  var boolFilter = dot.pick('body.query.filtered.filter.bool', req);

  var mergeFilter = function(filterName, data){
    if( _.isArray(boolFilter[filterName]) ){
      req.body.query.filtered.filter.bool[filterName] = req.body.query.filtered.filter.bool[filterName].concat(data);
    }else if( _.isPlainObject(boolFilter[filterName]) ){
      req.body.query.filtered.filter.bool[filterName] = [boolFilter[filterName]];
      req.body.query.filtered.filter.bool[filterName] = req.body.query.filtered.filter.bool[filterName].concat(data);
    }else{
      req.body.query.filtered.filter.bool[filterName] = data;
    }
  };

  if(boolFilter){
    if(filter.bool.must) mergeFilter('must', filter.bool.must);
    if(filter.bool.must_not) mergeFilter('must_not', filter.bool.must_not);
  }else{
github psvet / obey / src / lib / validators.js View on Github external
requiredIfNot: function(def, value, key, errors, data) {
    const type = 'requiredIfNot'
    const sub = def.requiredIfNot
    if (typeof sub === 'object') {
      const field = Object.keys(sub)[0]
      const fieldArr = Array.isArray(sub[field]) ? sub[field] : [ sub[field] ]
      fieldArr.some(val => {
        /* istanbul ignore else */
        if (dot.pick(field, data) !== val && value === undefined) {
          errors.push({ type, sub, key, value, message: `Value required because '${field}' value is not one specified` })
          return true
        }
      })
    } else if (dot.pick(sub, data) === undefined && value === undefined) {
      errors.push({ type, sub, key, value, message: `Value required because '${sub}' is undefined`})
    }
  },
  /**
github Aluminati / meteor-react-autoform / src / autoform.js View on Github external
Object.keys(this.props.schema).map(fieldName =>
    {
      if(typeof state[`${fieldName}_fieldValue`] !== 'undefined' &&
        !(this.props.type === 'insert' && state[`${fieldName}_fieldValue`] === '') &&
        this.getDocumentValue(fieldName) !== this.getStateOrDefaultSchemaValue(fieldName, null, null, state))
      {
        formFields[fieldName] = this.getStateOrDefaultSchemaValue(fieldName, null, null, state); // Gets the state value

        if(fieldName.indexOf('.') > 0) // If this fieldName belongs to object
        {
          let fieldNameObj = Dot.object(Object.assign({}, {[fieldName]: formFields[fieldName]})), // Get the entire object
            // schemaKey = fieldName.substr(0, fieldName.lastIndexOf('.')); // Get the parent object key
            schemaKey = fieldName.substr(0, fieldName.indexOf('.')); // Get the parent object key

          Dot.copy(schemaKey, schemaKey, this.props.doc, fieldNameObj); // Copy the original object
          formFields = {...Dot.dot(fieldNameObj), ...formFields}; // Turn the original object into dotted object and then merge it with the new fieldName value
        }
      }
    });
github namics / generator-nitro / packages / nitro-app / app / core / router.js View on Github external
config.get('nitro.basePath'),
		config.get('nitro.viewDataDirectory'),
		`/${req.query._data}.json`
	) : false;

	if (customDataPath && fs.existsSync(customDataPath)) {
		extend(true, data, JSON.parse(fs.readFileSync(customDataPath, 'utf8')));
	} else if (fs.existsSync(dataPath)) {
		extend(true, data, JSON.parse(fs.readFileSync(dataPath, 'utf8')));
	}

	// handle query string parameters
	if (Object.keys(req.query).length !== 0) {
		// simple clone
		const reqQuery = JSON.parse(JSON.stringify(req.query));
		dot.object(reqQuery);
		extend(true, data, reqQuery);
		// save query for use in patterns
		data._query = reqQuery;
	}

	// layout handling
	if (data._layout) {
		if (utils.layoutExists(data._layout)) {
			data.layout = utils.getLayoutPath(data._layout);
		}
	}
	if (!data.layout || !utils.layoutExists(utils.getLayoutName(data.layout))) {
		// use default layout if present
		if (utils.layoutExists(config.get('nitro.defaultLayout'))) {
			data.layout = utils.getLayoutPath(config.get('nitro.defaultLayout'));
		}
github cult-of-coders / grapher / lib / query / reducers / lib / createReducers.js View on Github external
export function handleAddField(fieldName, body, root) {
    if (_.contains(specialFields, fieldName)) {
        root.addProp(fieldName, body);

        return;
    }

    if (_.isObject(body)) {
        // if reducer specifies a nested field
        // if it's a prop
        const dots = dot.dot({
            [fieldName]: body
        });

        _.each(dots, (value, key) => {
            addFieldIfRequired(root, key, value);
        });
    } else {
        // if reducer does not specify a nested field, and the field does not exist.
        addFieldIfRequired(root, fieldName, body);
    }
}
github Aluminati / meteor-react-autoform / src / autoform.js View on Github external
getDocumentValue(fieldName)
  {
    if(this.doesDocumentValueExist(fieldName))
    {
      let doc = {};
      Dot.copy(fieldName, fieldName, this.props.doc, doc);
      doc = Dot.dot(doc);

      // If it's a number
      if(!isNaN(parseFloat(doc[fieldName])) && isFinite(doc[fieldName]))
      {
        // Return it as a String
        return doc[fieldName].toString();
      }

      return doc[fieldName];
    }

    return false;
  }

dot-object

dot-object makes it possible to transform and read (JSON) objects using dot notation.

MIT
Latest version published 3 years ago

Package Health Score

47 / 100
Full package analysis