JSFiddle - React, Tailwind, and code Playground

by igalst

JavaScript

function convertToEnum(input) {
    const lines = input.trim().split('\n');
    let enumString = 'enum FarmingType {\n';
    
    lines.forEach((line, index) => {
        const [code, description] = line.split('\t');
        const enumName = description.trim();//.toUpperCase().replace(/\s+/g, '_');
        enumString += `    "${code}" = "${enumName}"`;
        if (index !== lines.length - 1) {
            enumString += ',';
        }
        enumString += `
        `;
    });

    enumString += '}';
    return enumString;
}

var x = convertToEnum(`111110	Soybean Farming
111120	Oilseed (except Soybean) Farming 
111130	Dry Pea and Bean Farming 
111140	Wheat Farming
111150	Corn Farming 
111160	Rice Farming
111191	Oilseed and Grain Combination Farming 
111199	All Other Grain Farming 
111211	Potato Farming 
111219	Other Vegetable (except Potato) and Melon Farming 
111310	Orange Groves
111320	Citrus (except Orange) Groves 
111331	Apple Orchards 
111332	Grape Vineyards 
111333	Strawberry Farming 
111334	Berry (except Strawberry) Farming 
111335	Tree Nut Farming 
111336	Fruit and Tree Nut Combination Farming 
111339	Other Noncitrus Fruit Farming 
111411	Mushroom Production 
111419	Other Food Crops Grown Under Cover 
111421	Nursery and Tree Production 
111422	Floriculture Production 
111910	Tobacco Farming
111920	Cotton Farming
111930	Sugarcane Farming
111940	Hay Farming 
111991	Sugar Beet Farming 
111992	Peanut Farming 
111998	All Other Miscellaneous Crop Farming 
112111	Beef Cattle Ranching and Farming 
112112	Cattle Feedlots 
112120	Dairy Cattle and Milk Production
112130	Dual-Purpose Cattle Ranching and Farming 
112210	Hog and Pig Farming 
112310	Chicken Egg Production 
112320	Broilers and Other Meat Type Chicken Production 
112330	Turkey Production
112340	Poultry Hatcheries
112390	Other Poultry Production 
112410	Sheep Farming
112420	Goat Farming
112511	Finfish Farming and Fish Hatcheries 
112512	Shellfish Farming 
112519	Other Aquaculture...