Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor JSONCookies function for improved readability and modern syntax #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
Ayoub-Mabrouk committed Nov 1, 2024
commit d9f2aa67be8b36e5a7f12bcd7f04d8cdd3094bb6
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Loading