Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

destr

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

destr - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

7

CHANGELOG.md

@@ -5,4 +5,11 @@ # Changelog

### [0.1.3](https://github.com/nuxt-contrib/destr/compare/v0.1.2...v0.1.3) (2020-05-20)
### Bug Fixes
* remove unused code ([10ef37d](https://github.com/nuxt-contrib/destr/commit/10ef37d2854ce41534abbcff955c658fa727c459))
### [0.1.2](https://github.com/nuxt-contrib/destr/compare/v0.1.1...v0.1.2) (2020-05-20)
### 0.1.1 (2020-05-20)

35

dist/index.js

@@ -7,13 +7,5 @@ 'use strict';

var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
var STR_MAP = {
"true": true,
"false": false,
"null": null,
nan: NaN,
infinity: Infinity,
undefined: undefined
};
function jsonParseTransform(key, value) {
if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
if (key === '__proto__' || key === 'constructor') {
return;

@@ -32,7 +24,26 @@ }

if (_lval in STR_MAP) {
// @ts-ignore
return STR_MAP[_lval];
if (_lval === 'true') {
return true;
}
if (_lval === 'false') {
return false;
}
if (_lval === 'null') {
return null;
}
if (_lval === 'nan') {
return NaN;
}
if (_lval === 'infinity') {
return Infinity;
}
if (_lval === 'undefined') {
return undefined;
}
if (val[0] !== '"' && val[0] !== '{' && val[0] !== '[') {

@@ -39,0 +50,0 @@ return val;

{
"name": "destr",
"version": "0.1.2",
"version": "0.1.3",
"description": "A faster, secure and convenient alternative for JSON.parse",

@@ -25,2 +25,3 @@ "repository": "nuxt-contrib/destr",

"rollup-plugin-typescript2": "latest",
"secure-json-parse": "^2.1.0",
"standard-version": "latest",

@@ -27,0 +28,0 @@ "typescript": "latest"

@@ -41,6 +41,4 @@ # destr

⚠️ Before reading cool features, please note that `destr` is not always faster! When parsing a standard JSON string it is about **3 times slower** mainly because of transform to avoid [prototype pollution](https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061) which can lead to serious security issues if not being sanetized.
Please note that `destr` is little bit slower when parsing a standard JSON string mainly because of transform to avoid [prototype pollution](https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061) which can lead to serious security issues if not being sanetized. In the other words, `destr` is better when input is not always a json string or from untrsuted source like request body.
In the other words, `destr` is better when input is not always a json string or from untrsuted source like request body.
**Fast fallback to input if is not string:**

@@ -57,6 +55,6 @@

```js
// JSON.parse x 5,363,773 ops/sec ±0.31% (96 runs sampled)
// JSON.parse x 5,324,474 ops/sec ±0.65% (94 runs sampled)
JSON.parse(3.14159265359)
// destr x 660,537,795 ops/sec ±0.06% (86 runs sampled)
// destr x 657,187,095 ops/sec ±0.06% (98 runs sampled)
destr(3.14159265359)

@@ -76,6 +74,6 @@ ```

```js
// JSON.parse x 10,432,994 ops/sec ±0.23% (94 runs sampled)
// JSON.parse x 10,407,488 ops/sec ±0.30% (97 runs sampled)
JSON.parse('true')
// destr x 652,107,152 ops/sec ±0.11% (94 runs sampled
// destr x 88,634,032 ops/sec ±0.32% (95 runs sampled)
destr('true')

@@ -88,6 +86,6 @@ ```

// Uncaught SyntaxError: Unexpected token s in JSON at position 0
// JSON.parse (try-catch) x 248,749 ops/sec ±1.66% (93 runs sampled)
// JSON.parse (try-catch) x 248,212 ops/sec ±1.22% (84 runs sampled
JSON.parse('salam')
// destr x 32,415,523 ops/sec ±0.57% (94 runs sampled)
// destr x 30,867,179 ops/sec ±0.49% (94 runs sampled)
destr('salam')

@@ -94,0 +92,0 @@ ```

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