How to use the kind2string.reduceToObj function in kind2string

To help you get started, we’ve selected a few kind2string 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 atlassian / extract-react-types / packages / pretty-proptypes / src / PropType / index.js View on Github external
const renderPropType = (
  propType: any,
  { overrides = {}, shouldCollapseProps, components }: any
) => {
  if (!components) {
    components = allComponents;
  } else {
    components = { ...allComponents, ...components };
  }
  if (propType.kind === 'spread') {
    const furtherProps = reduceToObj(propType.value);
    if (Array.isArray(furtherProps) && furtherProps.length > 0) {
      /* Only render the spread contents if they are a non-empty value, otherwise render the
       * spread itself so we can see the spread of generics and other types that have not been
       * converted into an object */
      return furtherProps.map(p =>
        renderPropType(p, { overrides, shouldCollapseProps, components })
      );
    }
  }

  let description;
  if (propType.leadingComments) {
    description = propType.leadingComments.reduce((acc, { value }) => acc.concat(`\n${value}`), '');
  }

  if (!propType.value) {
github Noviny / pretty-proptypes / src / PropType / index.js View on Github external
const renderPropType = (
  propType: any,
  { overrides = {}, shouldCollapseProps, components }: any
) => {
  if (!components) {
    components = allComponents;
  } else {
    components = { ...allComponents, ...components };
  }
  if (propType.kind === "spread") {
    const furtherProps = reduceToObj(propType.value);
    if (Array.isArray(furtherProps) && furtherProps.length > 0) {
      /* Only render the spread contents if they are a non-empty value, otherwise render the
       * spread itself so we can see the spread of generics and other types that have not been
       * converted into an object */
      return furtherProps.map(p =>
        renderPropType(p, { overrides, shouldCollapseProps, components })
      );
    }
  }

  let description;
  if (propType.leadingComments) {
    description = propType.leadingComments.reduce(
      (acc, { value }) => acc.concat(`\n${value}`),
      ""
    );
github atlassian / extract-react-types / packages / pretty-proptypes / src / getPropTypes.js View on Github external
    propTypes = resolvedTypes.types.reduce((acc, type) => [...acc, ...reduceToObj(type)], []);
  }
github Noviny / pretty-proptypes / src / getPropTypes.js View on Github external
      (acc, type) => [...acc, ...reduceToObj(type)],
      [],

kind2string

Utility to ensure extract-react-types output can be rendered without errors

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Similar packages