JSFiddle - React, Tailwind, and code Playground

by jwerre

JavaScript

const input = `
    export type IconSize =
    export let color: string = COLORS.black;
    export let size: IconSize = DEFAULT_SIZE;
    export let strokeWidth = 2;
    export let name: IconName;
    export let debug = false;
`;

const lines = input.split('\n');

const regex = /export\s+(?:type\s+)?(?:let|const)?\s*(\w+)(?:\s*:\s*(\w+))?\s*=\s*([^;]+);/;



for (let i = 0; i < lines.length; i++) {
    const line = lines[i].trim();
	console.log(line)
    const match = regex.exec(line);
    if (match) {
		console.log(match)
        const [fullMatch, name, type, value] = match;
        console.log(`Name: ${name}`);
		console.log(`Type: ${type}`);
        console.log(`Value: ${value}`);

    }
	console.log('\n\n---');
}