Comparing version 0.0.0 to 0.1.0
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5850
132
7