Skip to content

Commit

Permalink
feat: Add helper getRawTypeName function
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 6, 2020
1 parent a549464 commit 1d33f8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useComponentDoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { SPECIAL_NUMBERS } from '../utils/propConstants';
import { getNormalizedTypeName } from '../utils/propTypeInfo';
import { getNormalizedTypeName, getRawTypeName } from '../utils/propTypeInfo';

const IGNORED_METHODS = [
'prototype',
Expand Down Expand Up @@ -30,7 +30,7 @@ const extractPropTypes = (component) => {
description: propDocs.text,
isRequired: propMeta.some((item) => item.name === 'isRequired'),
type: {
meta: type,
raw: getRawTypeName(propType),
name: getNormalizedTypeName(propType),
},
defaultValue,
Expand Down
5 changes: 3 additions & 2 deletions src/utils/propTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const getArgs = (propType) =>

const isUnion = (typeName) => typeName.includes(UNION_DELIMITER);

export const getRawTypeName = (propType) => propType.__reflect__[1].name;

export const getNormalizedTypeName = (propType) => {
const [_, { name }] = propType.__reflect__;
const name = getRawTypeName(propType);

switch (name) {
case 'bool':
Expand All @@ -32,4 +34,3 @@ export const getNormalizedTypeName = (propType) => {
return name;
}
};

0 comments on commit 1d33f8f

Please sign in to comment.