UNPKG

storybook-readme

Version:

Storybook addon to show components README (for React and Vue)

75 lines (62 loc) 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validatePropTables = void 0; // Validate user inputs(excludePropTables, includePropTables) by type guarding // whether it is an array and a function. For now, type checking if it // is a real React component(class, stateless, renderable) looks overkill // since components are compared directly. var validatePropTables = function validatePropTables(excludePropTables, includePropTables) { if (!excludePropTables && !includePropTables) { return { excludePropTables: [], includePropTables: [] }; } if (!isValidArray(excludePropTables, includePropTables)) { return { excludePropTables: [], includePropTables: [] }; } if (!isValidArrayItems(excludePropTables, includePropTables)) { return { excludePropTables: [], includePropTables: [] }; } return { excludePropTables: excludePropTables, includePropTables: includePropTables }; }; // Validate if the inputs are an array. exports.validatePropTables = validatePropTables; var isValidArray = function isValidArray(excludePropTables, includePropTables) { var isValidArray = true; if (!Array.isArray(excludePropTables)) { isValidArray = false; console.warn('storybook-readme: excludePropTables is not an array. It must be an ' + 'array of React components.'); } if (!Array.isArray(includePropTables)) { isValidArray = false; console.warn('storybook-readme: includePropTables is not an array. It must be an ' + 'array of React components.'); } return isValidArray; }; // Validate if the items inside of array is a React component. var isValidArrayItems = function isValidArrayItems(excludePropTables, includePropTables) { var isValidArrayItems = true; excludePropTables.map(function (value) { if (typeof value !== 'function') { isValidArrayItems = false; console.warn("storybook-readme: Value ".concat(value, "(").concat(typeof value, ") from ") + 'excludePropTables is not a React component. It must be an' + 'actual React component.'); } }); includePropTables.map(function (value) { if (typeof value !== 'function') { isValidArrayItems = false; console.warn("storybook-readme: Value ".concat(value, "(").concat(typeof value, ") from ") + 'excludePropTables is not a React component. It must be an' + 'actual React component.'); } }); return isValidArrayItems; };