Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
serializerr
Advanced tools
Readme
Convert Errors & Objects into an easily-serialized vanilla Object.
serializerr
creates a vanilla Object
with a flattened prototype
chain & any non-enumerable properties mapped to enumerable properties.
This allows Error
objects to be serialised to JSON without losing
important data.
npm install serializerr
var wellSerializedError = JSON.parse(JSON.stringify(
serializerr(error)
))
console.log(wellSerializedError.name) // Error
console.log(wellSerializedError.message) // an error occurred
console.log(wellSerializedError.stack) // Error: an error occurred\n at Test.<anonymous> ...
var serializerr = require('serializerr')
var error = new Error('an error')
// simulate transferring an Error object over the wire as JSON
// without first passing through serializerr
var poorlySerializedError = JSON.parse(JSON.stringify(error))
// oh dear:
console.log(poorlySerializedError.name) // undefined
console.log(poorlySerializedError.message) // undefined
console.log(poorlySerializedError.stack) // undefined
// bring forth the serializerr
var errorObject = serializerr(error)
var wellSerializedError = JSON.parse(JSON.stringify(errorObject))
// properties are conserved!
console.log(wellSerializedError.name) // Error
console.log(wellSerializedError.message) // an error occurred
console.log(wellSerializedError.stack) // Error: an error occurred\n at Test.<anonymous> ...
// note errorObject is a vanilla Object, not an Error
errorObject instanceof Error // false
If you've ever tried to send an Error over a JSON-encoded connection
you've probably been surprised to find all the useful information is
sapped out of it; all the juicy properties like name
, message
&
stack
are non-enumerable thus they are not included in the
stringified JSON. This may be non-standard behaviour, as I could not
locate any mention in either the ES5.1 or the ES6 spec about it, but
Error properties are non-enumerable both in V8 (Chrome/io.js/Node.js) &
SpiderMonkey (Firefox).
I believe Error property non-enumerability was added as a security measure to prevent stack traces and other sensitive information accidentally leaking, but it's not uncommon to actually want to send the data in Error objects over the wire.
serializerr
makes an Object suitable for serializing to & from
JSON. Not restricted to use with Errors, will work with any Object.
Name was selected as programming world is mostly Americanised, and npm search does not seem to do effective stemming.
This decision came with strong feelings of guilt and shame about what I thought was blasphemous Americanised spelling, but it turns out this is a misconception thus I am pardoned:
The -ize spelling is often incorrectly seen as an Americanism in Britain. However, the Oxford English Dictionary (OED) recommends -ize and notes that the -ise spelling is from French.
From Wikipedia: American and British English spelling differences
ISC
FAQs
Convert Errors & Objects into an easily-serialized vanilla Object.
The npm package serializerr receives a total of 45,359 weekly downloads. As such, serializerr popularity was classified as popular.
We found that serializerr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.