How to use the kind2string 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
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] ? <OverrideComponent {...commonProps} /> : <Prop {...commonProps} />;
};
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 <components.StringType>{convert(type)}</components.StringType>;
    }
    return <components.Type>{convert(type)}</components.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 <components.StringType>{convert(type)}</components.StringType>;
    }
    return <components.Type>{convert(type)}</components.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 <components.StringType>{convert(type)}</components.StringType>;
    }
    return <components.Type>{convert(type)}</components.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
property: (type: K.Property, components: Components, depth: number) => (
    <div key={convert(type.key)}>
      {type.key && (
        <TypeMinWidth>
          <components.Type>{convert(type.key)}</components.Type>
        </TypeMinWidth>
      )}
      {type.value.kind !== "generic" ? ` ${type.value.kind}` : " "}
      {type.optional ? null : (
        <components.Required> required</components.Required>
      )}{" "}
      {printComplexType(type.value, components, depth)}
    </div>
  ),
  union: (type: K.Union, components: Components, depth: number) => (
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
const prettyConvert = (type: K.AnyKind, components: Components, depth: number = 1) => {
  if (!type) {
    return '';
  }

  const converter = converters[type.kind];
  if (!converter) {
    const stringType = convert(type);
    return <components.Type key={stringType}>{stringType}</components.Type>;
  }
  return converter(type, components, depth);
};
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
property: (type: K.Property, components: Components, depth: number) => (
    <div key={convert(type.key)}>
      {type.key && (
        <TypeMinWidth>
          <components.Type>{convert(type.key)}</components.Type>
        </TypeMinWidth>
      )}
      {type.value.kind !== 'generic' ? ` ${type.value.kind}` : ' '}
      {type.optional ? null : <components.Required> required</components.Required>}{' '}
      {printComplexType(type.value, components, depth)}
    </div>
  ),
  union: (type: K.Union, components: Components, depth: number) => (
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
{type.parameters.map((param, index, array) => (
                <div key={convert(param.value)}>
                  {prettyConvert(param, components, depth + 1)}
                  {array.length - 1 === index ? "" : ", "}
                </div>
              ))}
            </components.Indent>
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
function: (type: K.Func, components: Components, depth: number) => {
    let simpleReturn = type.returnType && SIMPLE_TYPES.includes(type.returnType.kind);

    let simpleParameters =
      type.parameters.filter(param => SIMPLE_TYPES.includes(param.value.kind)).length ===
      type.parameters.length;

    if (simpleParameters && simpleReturn) {
      return (
        <span>
          {`(${type.parameters.map(convert).join(', ')})`}
          <Arrow />
          {`${convert(type.returnType)}`}
        </span>
      );
    } else if (simpleParameters || type.parameters.length < 2) {
      return (
        <span>
          <AddBrackets BracketStyler={components.FunctionType}>
            {type.parameters.map((param, index, array) => [
              prettyConvert(param, components, depth),
              array.length - 1 === index ? '' : ', '
            ])}
          </AddBrackets>
          <Arrow />
          {type.returnType ? prettyConvert(type.returnType, components, depth) : 'undefined'}
        </span>
      );
    } else {
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
const prettyConvert = (
  type: K.AnyKind,
  components: Components,
  depth: number = 1
) => {
  if (!type) {
    return "";
  }

  const converter = converters[type.kind];
  if (!converter) {
    const stringType = convert(type);
    return <components.Type key={stringType}>{stringType}</components.Type>;
  }
  return converter(type, components, depth);
};

kind2string

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

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages