import * as _ from "lodash"; export const generateBullets = (arr: string[]) => { return "- " + _.join(arr, "\n- "); }; export const generateTable = (arr: object[]) => { if (!_.has(arr, "length")) return "N/A"; if (!arr.length) return "N/A"; const sample: any = _.head(arr); // remove non-strings const keys = _.filter(_.keys(sample), (key) => _.isString(sample[key])); const clean = (str: string) => _.startCase(_.toLower(str)); const header = `| ${_.join( _.map(keys, (key: any) => `${clean(key)} | `), "" )} |${_.join( _.map(_.range(keys.length), () => "-|"), "" )}`; return ( header + "\n" + "| " + _.join( _.map(arr, (itm: any) => { return _.join( _.map(keys, (key: string) => itm[key]), " | " ); }), " |\n| " ) + " |" ); }; export const generateTOC = () => ` `; export const generateSchema = (arr: any, tests: boolean = false) => { let schemaContent: any = []; // let testContent: any = []; _.forEach(arr, (component: any) => { schemaContent.push(`#### ${component["name"]} ##### Schema ${generateTable(component["schema"])} ${ tests ? ` ##### Tests ${generateTable(component["tests"])}` : "" } `); }); return _.join(schemaContent, "\n\n"); };