/** * @name lcfc - lower-cased-first-character * * @param obj - This parameter is the object that will be converted to the first letter of the keys in the object to lowercase. * @returns - Returns the object with the first letter of the keys in the object to lowercase. * * @example * * const obj = { * Name: "Ali Veli", * Age: 25, * Address: { * City: "İstanbul", * Country: "Türkiye" * } * } * * const newObj = lcfc(obj); * * console.log(newObj); * * // Output: * { * name: "Ali Veli", * age: 25, * address: { * city: "İstanbul", * country: "Türkiye" * } * } */ export default function lcfc(obj: T): T { const newObj: any = {}; if (!obj) { return obj; } Object.keys(obj).forEach((key) => { if ( typeof obj[key as keyof T] === "object" && !Array.isArray(obj[key as keyof T]) ) { newObj[key.charAt(0).toLowerCase() + key.slice(1)] = lcfc( obj[key as keyof T], ); return; } if ( typeof obj[key as keyof T] === "object" && Array.isArray(obj[key as keyof T]) ) { newObj[key.charAt(0).toLowerCase() + key.slice(1)] = ( obj[key as keyof T] as any[] ).map((item) => { return lcfc(item); }); return; } newObj[key.charAt(0).toLowerCase() + key.slice(1)] = obj[key as keyof T]; }); return newObj as T; }