How to use kind2string - 10 common examples

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
let description;
  if (propType.leadingComments) {
    description = propType.leadingComments.reduce((acc, { value }) => acc.concat(`\n${value}`), '');
  }

  if (!propType.value) {
    // eslint-disable-next-line no-console
    console.error(
      `Prop ${
        propType.key
      } has no type; this usually indicates invalid propType or defaultProps config`
    );
    return null;
  }

  const name = propType.kind === 'spread' ? '...' : convert(propType.key);
  const OverrideComponent = overrides[name];
  const commonProps = {
    components,
    name,
    key: name,
    required: !propType.optional,
    type: getKind(propType.value),
    defaultValue: propType.default && convert(propType.default),
    description,
    shouldCollapse: shouldCollapseProps,
    typeValue: propType.value
  };

  return overrides[name] ?  : ;
};
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
string: (type: K.String, components: Components) => {
    if (type.value != null) {
      return {convert(type)};
    }
    return {convert(type)};
  },
  // nullable types are currently stripping infromation, as we show 'required'
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
string: (type: K.String, components: Components) => {
    if (type.value != null) {
      return {convert(type)};
    }
    return {convert(type)};
  },
  // nullable types are currently stripping infromation, as we show 'required'
github Noviny / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
string: (type: K.String, components: Components) => {
    if (type.value != null) {
      return {convert(type)};
    }
    return {convert(type)};
  },
  // nullable types are currently stripping infromation, as we show 'required'
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / index.js View on Github external
render() {
    let { shouldCollapse, typeValue: type, components } = this.props;
    // any instance of returning null means we are confident the information will
    // be displayed elsewhere so we do not need to also include it here.
    if (type.kind === 'generic') {
      type = resolveFromGeneric(type);
    }
    if (SIMPLE_TYPES.includes(type.kind)) return null;
    if (type.kind === 'nullable' && SIMPLE_TYPES.includes(type.arguments.kind)) {
      return null;
    }

    return shouldCollapse ? (
       (
          <div>
            
              {isCollapsed ? 'Expand Prop Shape' : 'Hide Prop Shape'}
            
          </div>
        )}
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
{type.members.map(prop =&gt; {
              if (prop.kind === "spread") {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =&gt;
                    prettyConvert(newProp, components, depth)
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
github Noviny / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
{type.members.map(prop =&gt; {
              if (prop.kind === 'spread') {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =&gt;
                    prettyConvert(newProp, components, depth),
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
{type.members.filter(p =&gt; p).map(prop =&gt; {
              if (prop.kind === 'spread') {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =&gt;
                    prettyConvert(newProp, components, depth)
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / index.js View on Github external
render() {
    let { shouldCollapse, typeValue: type, components } = this.props;
    // any instance of returning null means we are confident the information will
    // be displayed elsewhere so we do not need to also include it here.
    if (type.kind === "generic") {
      type = resolveFromGeneric(type);
    }
    if (SIMPLE_TYPES.includes(type.kind)) return null;
    if (
      type.kind === "nullable" &amp;&amp;
      SIMPLE_TYPES.includes(type.arguments.kind)
    ) {
      return null;
    }

    return shouldCollapse ? (
       (
          <div>
            </div>
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) {

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