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.0.0 to 0.1.0

6

dist/index.d.ts
export declare type JSONObject = {
[key: string]: JSONValue;
};
export declare type JSONValue = true | false | null | string | JSONObject | JSONValue[];
export declare type DestrValue = JSONValue | JSONValue[] | undefined;
export default function destr(val: any): DestrValue;
export declare type JSONValue = true | false | null | string | Number | JSONObject | JSONValue[];
export declare type DestrValue = JSONValue | undefined;
export default function destr(val: string | any): DestrValue;
'use strict';
var STR_MAP = {
'true': true,
'false': false,
'null': null,
'nan': NaN,
'infinity': Infinity,
'undefined': undefined
"true": true,
"false": false,
"null": null,
nan: NaN,
infinity: Infinity,
undefined: undefined
};

@@ -11,0 +11,0 @@

{
"name": "destr",
"version": "0.0.0",
"description": "",
"repository": "nuxt-community/destr",
"version": "0.1.0",
"description": "A faster, secure and convenient alternative for JSON.parse",
"repository": "nuxt-contrib/destr",
"license": "MIT",

@@ -14,11 +14,16 @@ "main": "dist/index.js",

"bench": "yarn build && node ./bench.js",
"build": "bili src/index.ts"
"lint": "eslint --ext .ts .",
"test": "yarn lint",
"build": "bili src/index.ts",
"release": "release-it"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"benchmark": "^2.1.4",
"bili": "^4.10.0",
"rollup-plugin-typescript2": "^0.27.1",
"benchmark": "latest",
"bili": "latest",
"eslint": "latest",
"release-it": "latest",
"rollup-plugin-typescript2": "latest",
"typescript": "latest"
}
}
# destr
A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse):
> A faster, secure and convenient alternative for [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse):
[![npm version][npm-v-src]][npm-v-href]
[![npm downloads][npm-d-src]][npm-d-href]
[![bundle phobia][bundlephobia-src]][bundlephobia-href]
## Usage
### Node.js
Install using npm or yarn:
```bash
npm i destr
# or
yarn add destr
```
Import into your Node.js project:
```js
// CommonJS
const destr = require('destr')
// ESM
import destr from 'destr'
```
### Deno
```js
import destr from 'https://cdn.jsdelivr.net/gh/nuxt-contrib/destr/src/index.ts'
console.log(destr('{ "deno": "yay" }'))
```
## Why?
⚠️ 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.
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:**

@@ -16,3 +56,3 @@

```js
// JSON.parse x 5,363,773 ops/sec ±0.31% (96 runs sampled
// JSON.parse x 5,363,773 ops/sec ±0.31% (96 runs sampled)
JSON.parse(3.14159265359)

@@ -53,3 +93,3 @@

**Avoid Prototype Pollution:**
**Avoid prototype pollution:**

@@ -75,8 +115,3 @@ ```js

```ts
export declare type JSONObject = {
[key: string]: JSONValue;
};
export declare type JSONValue = true | false | null | string | JSONObject | JSONValue[];
export declare type DestrValue = JSONValue | JSONValue[] | undefined;
export default function destr(val: any): DestrValue;
function destr(val: string | any): DestrValue
```

@@ -86,2 +121,15 @@

MIT
MIT. Made with 💖
<!-- Refs -->
[npm-v-src]: https://img.shields.io/npm/v/destr?style=flat-square
[npm-v-href]: https://npmjs.com/package/destr
[npm-d-src]: https://img.shields.io/npm/dm/destr?style=flat-square
[npm-d-href]: https://npmjs.com/package/destr
[github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/destr/ci/master?style=flat-square
[github-actions-href]: https://github.com/nuxt-contrib/destr/actions?query=workflow%3Aci
[bundlephobia-src]: https://img.shields.io/bundlephobia/min/destr?style=flat-square
[bundlephobia-href]: https://bundlephobia.com/result?p=destr
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