Socket
Socket
Sign inDemoInstall

@nuxt/devalue

Package Overview
Dependencies
Maintainers
5
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nuxt/devalue

Gets the job done when JSON.stringify can't


Version published
Weekly downloads
118K
decreased by-80.26%
Maintainers
5
Weekly downloads
 
Created

What is @nuxt/devalue?

@nuxt/devalue is a JavaScript library used to serialize JavaScript values into a string that can be safely embedded in HTML. It is particularly useful for server-side rendering (SSR) in frameworks like Nuxt.js, where you need to serialize state or other data to be sent to the client.

What are @nuxt/devalue's main functionalities?

Serialize JavaScript values

This feature allows you to serialize JavaScript values into a string format that can be safely embedded in HTML. The example demonstrates serializing an object with nested arrays.

const devalue = require('@nuxt/devalue');
const obj = { foo: 'bar', baz: [1, 2, 3] };
const serialized = devalue(obj);
console.log(serialized); // Output: '{"foo":"bar","baz":[1,2,3]}'

Handle complex data structures

This feature allows you to serialize complex data structures like Date objects, regular expressions, Maps, and Sets. The example demonstrates serializing an object containing these complex types.

const devalue = require('@nuxt/devalue');
const complexObj = { date: new Date(), regex: /test/i, map: new Map([[1, 'one']]), set: new Set([1, 2, 3]) };
const serialized = devalue(complexObj);
console.log(serialized); // Output: '{"date":new Date("2023-10-04T00:00:00.000Z"),"regex":/test/i,"map":new Map([[1,"one"]]),"set":new Set([1,2,3])}'

Prevent XSS attacks

This feature ensures that serialized data is safe to embed in HTML, preventing XSS (Cross-Site Scripting) attacks. The example demonstrates serializing an object containing a potentially unsafe script tag.

const devalue = require('@nuxt/devalue');
const unsafeObj = { script: '<script>alert("XSS")</script>' };
const serialized = devalue(unsafeObj);
console.log(serialized); // Output: '{"script":"<script>alert(\"XSS\")</script>"}'

Other packages similar to @nuxt/devalue

FAQs

Package last updated on 02 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc