How to use object-inspect - 7 common examples

To help you get started, we’ve selected a few object-inspect 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 airbnb / enzyme / packages / enzyme / src / Debug.js View on Github external
function propString(prop, options) {
  if (isString(prop)) {
    return inspect(String(prop), { quoteStyle: 'double' });
  }
  if (isNumber(prop)) {
    return `{${inspect(Number(prop))}}`;
  }
  if (isBoolean(prop)) {
    return `{${inspect(booleanValue(prop))}}`;
  }
  if (isCallable(prop)) {
    return `{${inspect(prop)}}`;
  }
  if (typeof prop === 'object') {
    if (options.verbose) {
      return `{${inspect(prop)}}`;
    }

    return '{{...}}';
  }
  return `{[${typeof prop}]}`;
}
github porsager / flems / src / actions.js View on Github external
}).catch(err => {
      consoleOutput({
        content: ['Error compiling ' + file.compiler + ':', inspect(err)],
        type: 'error',
        stack: []
      })
      return {
        name: file.name,
        type: file.type,
        content: file.content
      }
    })
  }
github sanity-io / sanity / src / state / FormBuilderState.js View on Github external
export function createFieldValue(value, context) {

  const {schema, field, resolveInputComponent} = context

  if (!field) {
    throw new Error(`Missing field for value ${inspect(value)}`)
  }

  const fieldType = getFieldType(schema, field)

  let ResolvedInput
  try {
    ResolvedInput = resolveInputComponent(field, fieldType)
  } catch (error) {
    error.message = `Got error while resolving input component for field "${field.name}" of type ${fieldType.name}: ${error.message}.`
    throw error
  }

  const ResolvedContainer = (ResolvedInput && ResolvedInput.valueContainer) || PrimitiveValueContainer

  return ResolvedContainer.deserialize(value, context)
}
github airbnb / enzyme / packages / enzyme / src / Debug.js View on Github external
export function debugNode(node, indentLength = 2, options = {}) {
  if (typeof node === 'string' || typeof node === 'number') return escape(node);
  if (typeof node === 'function') {
    const name = functionName(node);
    return `[function${name ? ` ${name}` : ''}]`;
  }
  if (!node) return '';

  const adapter = getAdapter();
  if (!adapter.isValidElement(node) && !isRSTNodeLike(node)) {
    return `{${inspect(node)}}`;
  }

  const childrenStrs = childrenOfNode(node)
    .map((n) => debugNode(n, indentLength, options))
    .filter(Boolean);
  const type = typeName(node);

  const props = options.ignoreProps ? '' : propsString(node, options);
  const beforeProps = props ? ' ' : '';
  const afterProps = childrenStrs.length
    ? '>'
    : ' ';
  const childrenIndented = indentChildren(childrenStrs, indentLength);
  const nodeClose = childrenStrs.length ? `` : '/>';
  return `<${type}${beforeProps}${props}${afterProps}${childrenIndented}${nodeClose}`;
}
github airbnb / enzyme / packages / enzyme / src / Debug.js View on Github external
function propString(prop, options) {
  if (isString(prop)) {
    return inspect(String(prop), { quoteStyle: 'double' });
  }
  if (isNumber(prop)) {
    return `{${inspect(Number(prop))}}`;
  }
  if (isBoolean(prop)) {
    return `{${inspect(booleanValue(prop))}}`;
  }
  if (isCallable(prop)) {
    return `{${inspect(prop)}}`;
  }
  if (typeof prop === 'object') {
    if (options.verbose) {
      return `{${inspect(prop)}}`;
    }

    return '{{...}}';
  }
  return `{[${typeof prop}]}`;
}
github popcodeorg / popcode / src / previewSupport / prettyPrint.js View on Github external
export default function prettyPrint(value) {
  return inspect(value, {quoteStyle: 'double'});
}
github airbnb / enzyme / packages / enzyme / src / Debug.js View on Github external
function propString(prop, options) {
  if (isString(prop)) {
    return inspect(String(prop), { quoteStyle: 'double' });
  }
  if (isNumber(prop)) {
    return `{${inspect(Number(prop))}}`;
  }
  if (isBoolean(prop)) {
    return `{${inspect(booleanValue(prop))}}`;
  }
  if (isCallable(prop)) {
    return `{${inspect(prop)}}`;
  }
  if (typeof prop === 'object') {
    if (options.verbose) {
      return `{${inspect(prop)}}`;
    }

    return '{{...}}';
  }
  return `{[${typeof prop}]}`;
}

object-inspect

string representations of objects in node and the browser

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis

Popular object-inspect functions