How to use the property-expr.forEach function in property-expr

To help you get started, we’ve selected a few property-expr 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 jquense / yup / src / util / reach.js View on Github external
export function getIn(schema, path, value, context) {
  let parent, lastPart, lastPartDebug;

  // if only one "value" arg then use it for both
  context = context || value;

  if (!path)
    return {
      parent,
      parentPath: path,
      schema,
    };

  forEach(path, (_part, isBracket, isArray) => {
    let part = isBracket ? trim(_part) : _part;

    if (isArray || has(schema, '_subType')) {
      // we skipped an array: foo[].bar
      let idx = isArray ? parseInt(part, 10) : 0;

      schema = schema.resolve({ context, parent, value })._subType;

      if (value) {
        if (isArray && idx >= value.length) {
          throw new Error(
            `Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` +
              `because there is no value at that index. `,
          );
        }
github tjinauyeung / svelte-forms-lib / lib / util.js View on Github external
function getIn(schema, path, value, context) {
  let parent, lastPart, lastPartDebug;

  context = context || value;

  if (!path)
    return {
      parent,
      parentPath: path,
      schema
    };

  forEach(path, (_part, isBracket, isArray) => {
    let part = isBracket ? trim(_part) : _part;

    if (isArray || has(schema, "_subType")) {
      let index = isArray ? parseInt(part, 10) : 0;
      schema = schema.resolve({ context, parent, value })._subType;
      if (value) {
        value = value[index];
      }
    }

    if (!isArray) {
      schema = schema.resolve({ context, parent, value });
      schema = schema.fields[part];
      parent = value;
      value = value && value[part];
      lastPart = part;

property-expr

tiny util for getting and setting deep object props safely

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis