From d9f2aa67be8b36e5a7f12bcd7f04d8cdd3094bb6 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Fri, 1 Nov 2024 03:10:29 +0100 Subject: [PATCH] Refactor JSONCookies function for improved readability and modern syntax - Replaced Object.keys() with Object.entries() for cleaner iteration over key-value pairs. - Utilized destructuring in the loop to enhance code clarity. - Improved variable naming for better understanding of the decoded value. - Maintained functionality of decoding JSON cookies while updating the original object. --- index.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index dd6d479..550b444 100644 --- a/index.js +++ b/index.js @@ -101,16 +101,11 @@ function JSONCookie (str) { */ function JSONCookies (obj) { - var cookies = Object.keys(obj) - var key - var val - - for (var i = 0; i < cookies.length; i++) { - key = cookies[i] - val = JSONCookie(obj[key]) + for (const [key, value] of Object.entries(obj)) { + const decodedValue = JSONCookie(value) - if (val) { - obj[key] = val + if (decodedValue) { + obj[key] = decodedValue } }