How to use dot-prop - 10 common examples

To help you get started, we’ve selected a few dot-prop 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 vivocha / arrest / src / utils.ts View on Github external
function moveDefinition(spec: any, newSchemaKey: string, path: string): any {
  // copy the definition to components.schemas root
  const defSchema = dot.get(spec, path);
  dot.set(spec, `components.schemas.${newSchemaKey}`, defSchema);
  // delete the definition at current path
  dot.delete(spec, path);
  const newRef = `#/components/schemas/${newSchemaKey}`;
  return updateRefs(spec, `#/${path.split('.').join('/')}`, newRef);
}
github liferay / liferay-js-toolkit / packages / liferay-npm-build-tools-common / src / project / misc.ts View on Github external
get maxParallelFiles(): number {
		const {npmbundlerrc} = this._project;

		// Default values for "ulimit -n" vary across different OSes. Some
		//
		// values I have found are:
		//   - Apparently Mac OS X limit is 256 but usually people increase it
		//   - Fedora: 1024
		//   - Windows: there's no ulimit, but MSVCRT.DLL has a 2048 limit
		//
		// Given this mess and the impossibility of retrieving the limit from
		// Node, I'm giving this a default value of 128 because it looks like it
		// doesn't impact performance and should be low enough to make it work
		// in all OSes.
		return prop.get(npmbundlerrc, 'max-parallel-files', 128);
	}
github vivocha / arrest / src / utils.ts View on Github external
// or, if ref path is like:  #/components/schemas/A/properties/a
            type = refPath[refPath.length - 4];
          }

          if (['schemas', 'parameters', 'responses'].includes(refPath[refPath.length - 2])) {
            // in case of a ref like #/components/schemas/A or #/components/parameters/A or #/components/responses/A
            // schema name is the last element of the path
            schemaName = refPath[refPath.length - 1];
          } else if (refPath[refPath.length - 2] === 'properties') {
            // in case of a ref like #/components/schemas/A/properties/B
            // schema name is A, then:
            schemaName = refPath[refPath.length - 3];
          }
          if (['schemas', 'parameters', 'responses'].includes(type)) {
            // check if the reference points to an existing path in spec
            if (!dot.get(spec as any, refPath.slice(1).join('.'))) {
              throw new Error(`Referenced path "${obj[key]}" doesn't exist in spec.`);
            } else {
              occurrences[type][schemaName]['count'] += 1;
              occurrences[type][schemaName]['referencedBy'].push(currentPath.slice(0, 3).join('.'));
            }
          }
        }
        const prop = obj[key];
        // recursively find and count...
        if (prop && typeof prop === 'object') {
          if (!Array.isArray(prop)) {
            if (!parsedProps.find(p => p === prop)) {
              parsedProps.push(prop);
              findAndCount(prop, currentPath);
            }
          } else {
github vivocha / arrest / src / utils.ts View on Github external
function rebaseOASDefinition(fullSpec: any, schemaKey: string, schema: any, path: string, definitionsPath: string[]): any {
  if (schema.definitions) {
    for (const defKey in schema.definitions) {
      // current recursive definition path chain
      const chain = [...definitionsPath, defKey];
      const newPath = `${path}.definitions.${defKey}`;
      const definition = dot.get(fullSpec, newPath);
      fullSpec = rebaseOASDefinition(fullSpec, defKey, definition, newPath, chain);
      const newSchemaName = `${chain.join('_')}`;
      // move to components/schemas and get a new ref related to the new path
      fullSpec = moveDefinition(fullSpec, newSchemaName, newPath);
    }
    dot.delete(fullSpec, `${path}.definitions`);
  }
  return fullSpec;
}
github zaaack / ELaunch / app / config / index.js View on Github external
write(key, value) {
    dotDrop.set(rawConfig, key, value)
    writeConfig()
  },
  set(key, value) { // write with emit event
github wordup-dev / wordup-cli / src / lib / project.js View on Github external
if (fs.existsSync(this.getProjectPath('.wordup','config.yml'))) {

      try {
        this.dotWordupYml = YAML.parseDocument(fs.readFileSync(this.getProjectPath('.wordup','config.yml'), 'utf8'))
        this.dotWordupJson = this.dotWordupYml.toJSON()
      } catch (err) {
        this.error('Could not parse wordup config: '+err, {exit:1})
      }

      // Create the slug as a name. Because it could be also a path
      const slug = this.wPkg('slug')
      if(slug){
        if (slug.lastIndexOf('/') !== -1) {
          dotProp.set(this.dotWordupJson, 'slugName', slug.substring(0, slug.lastIndexOf('/')))
        } else {
          dotProp.set(this.dotWordupJson, 'slugName', slug)
        }
      }

      // Get config based on the current path
      this.config = this._wordupConfigstore.get('projects.' + this.projectId)

      //Set docker-compose files
      if (fs.existsSync(this.getProjectPath('docker-compose.yml'))) {
        // If there is a local docker-compose.yml file, extend it
        composerFiles += seperator + this.getProjectPath('docker-compose.yml') 
      }
    }

    //Set env which are the same for each project
    shell.env.COMPOSE_FILE = composerFiles
github fliphub / fliphub / modules / json-chain / index.js View on Github external
has(key) {
    this.parse()
    if (key.includes('.')) return dotProp.has(this.data, key)
    return Object.prototype.hasOwnProperty.call(this.data, key)
  }
  // delete. remove
github vivocha / arrest / src / utils.ts View on Github external
// current schema was the last reference in the other schema referencing it, then remove also that schema
        dot.delete(spec as any, referencedByPath);
      } else {
        // or, update the referencing schema removing the current schema:
        // remove the entry from the referencedBy array in occurrences table
        _.remove(referencedBy[referencedByKey].referencedBy, v => v === referencedByPath);
        // update occurrence to save in occurrences table
        const updatedOccurrence = {
          count: referencedBy[referencedByKey].count - 1,
          referencedBy: referencedBy[referencedByKey].referencedBy
        };
        dot.set(occurrences['schemas'] as any, referencedByKey, updatedOccurrence);
      }
    }
    // finally, delete the current schema with count === 0
    dot.delete(spec as any, pathToDelete);
  }
  return spec;
}
github vivocha / arrest / src / utils.ts View on Github external
function rebaseOASDefinition(fullSpec: any, schemaKey: string, schema: any, path: string, definitionsPath: string[]): any {
  if (schema.definitions) {
    for (const defKey in schema.definitions) {
      // current recursive definition path chain
      const chain = [...definitionsPath, defKey];
      const newPath = `${path}.definitions.${defKey}`;
      const definition = dot.get(fullSpec, newPath);
      fullSpec = rebaseOASDefinition(fullSpec, defKey, definition, newPath, chain);
      const newSchemaName = `${chain.join('_')}`;
      // move to components/schemas and get a new ref related to the new path
      fullSpec = moveDefinition(fullSpec, newSchemaName, newPath);
    }
    dot.delete(fullSpec, `${path}.definitions`);
  }
  return fullSpec;
}
github scalarwaves / leximaven / src / commands / configuration / set.js View on Github external
exports.handler = (argv) => {
  const key = argv.key
  let value = argv.value
  value = tools.checkBoolean(value)
  tools.checkConfig(CFILE)
  const config = noon.load(CFILE)
  const theme = themes.loadTheme(config.theme)
  if (config.verbose) themes.label(theme, 'down', 'Configuration')
  if (dot.has(config, key)) {
    if (/\./i.test(key)) {
      if (/^\w*\.date/i.test(key)) {
        throw new Error("API limits hardcoded, can't set this key.")
      } else {
        dot.set(config, key, value)
      }
    } else {
      config[key] = value
    }
  } else {
    throw new Error(`Option ${key} not found.`)
  }
  noon.save(CFILE, config)
  console.log(`Set option ${chalk.white.bold(key)} to ${chalk.white.bold(value)}.`)
}

dot-prop

Get, set, or delete a property from a nested object using a dot path

MIT
Latest version published 7 months ago

Package Health Score

76 / 100
Full package analysis