Socket
Socket
Sign inDemoInstall

devalue

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devalue - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

src/base64.js

3

package.json
{
"name": "devalue",
"description": "Gets the job done when JSON.stringify can't",
"version": "5.0.0",
"version": "5.1.0",
"repository": "Rich-Harris/devalue",
"sideEffects": false,
"exports": {

@@ -7,0 +8,0 @@ ".": {

@@ -12,2 +12,3 @@ # devalue

- `BigInt`
- `ArrayBuffer` and Typed Arrays
- custom types via replacers, reducers and revivers

@@ -14,0 +15,0 @@

@@ -0,1 +1,2 @@

import { decode64 } from './base64.js';
import {

@@ -104,2 +105,28 @@ HOLE,

case "Int8Array":
case "Uint8Array":
case "Uint8ClampedArray":
case "Int16Array":
case "Uint16Array":
case "Int32Array":
case "Uint32Array":
case "Float32Array":
case "Float64Array":
case "BigInt64Array":
case "BigUint64Array": {
const TypedArrayConstructor = globalThis[type];
const base64 = value[1];
const arraybuffer = decode64(base64);
const typedArray = new TypedArrayConstructor(arraybuffer);
hydrated[index] = typedArray;
break;
}
case "ArrayBuffer": {
const base64 = value[1];
const arraybuffer = decode64(base64);
hydrated[index] = arraybuffer;
break;
}
default:

@@ -106,0 +133,0 @@ throw new Error(`Unknown type ${type}`);

@@ -7,2 +7,3 @@ import {

is_primitive,
stringify_key,
stringify_string

@@ -18,2 +19,3 @@ } from './utils.js';

} from './constants.js';
import { encode64 } from './base64.js';

@@ -141,2 +143,29 @@ /**

case "Int8Array":
case "Uint8Array":
case "Uint8ClampedArray":
case "Int16Array":
case "Uint16Array":
case "Int32Array":
case "Uint32Array":
case "Float32Array":
case "Float64Array":
case "BigInt64Array":
case "BigUint64Array": {
/** @type {import("./types.js").TypedArray} */
const typedArray = thing;
const base64 = encode64(typedArray.buffer);
str = '["' + type + '","' + base64 + '"]';
break;
}
case "ArrayBuffer": {
/** @type {ArrayBuffer} */
const arraybuffer = thing;
const base64 = encode64(arraybuffer);
str = `["ArrayBuffer","${base64}"]`;
break;
}
default:

@@ -160,3 +189,3 @@ if (!is_plain_object(thing)) {

for (const key in thing) {
keys.push(`.${key}`);
keys.push(stringify_key(key));
str += `,${stringify_string(key)},${flatten(thing[key])}`;

@@ -172,3 +201,3 @@ keys.pop();

started = true;
keys.push(`.${key}`);
keys.push(stringify_key(key));
str += `${stringify_string(key)}:${flatten(thing[key])}`;

@@ -175,0 +204,0 @@ keys.pop();

@@ -8,2 +8,3 @@ import {

is_primitive,
stringify_key,
stringify_string

@@ -85,2 +86,18 @@ } from './utils.js';

break;
case "Int8Array":
case "Uint8Array":
case "Uint8ClampedArray":
case "Int16Array":
case "Uint16Array":
case "Int32Array":
case "Uint32Array":
case "Float32Array":
case "Float64Array":
case "BigInt64Array":
case "BigUint64Array":
return;
case "ArrayBuffer":
return;

@@ -103,3 +120,3 @@ default:

for (const key in thing) {
keys.push(`.${key}`);
keys.push(stringify_key(key));
walk(thing[key]);

@@ -166,2 +183,23 @@ keys.pop();

return `new ${type}([${Array.from(thing).map(stringify).join(',')}])`;
case "Int8Array":
case "Uint8Array":
case "Uint8ClampedArray":
case "Int16Array":
case "Uint16Array":
case "Int32Array":
case "Uint32Array":
case "Float32Array":
case "Float64Array":
case "BigInt64Array":
case "BigUint64Array": {
/** @type {import("./types.js").TypedArray} */
const typedArray = thing;
return `new ${type}([${typedArray.toString()}])`;
}
case "ArrayBuffer": {
const ui8 = new Uint8Array(thing);
return `new Uint8Array([${ui8.toString()}]).buffer`;
}

@@ -168,0 +206,0 @@ default:

@@ -107,1 +107,8 @@ /** @type {Record<string, string>} */

}
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
/** @param {string} key */
export function stringify_key(key) {
return is_identifier.test(key) ? '.' + key : '[' + JSON.stringify(key) + ']';
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc