New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

all-parse

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

all-parse

Parse all properties of an object into a JS object from a JSON string.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

all-parse

🇨🇳中文 | ENGLISH

深遍历对象和数组,将所有JSON字符串转换成JS对象。

const object = {
  a: 1,
  b: '{"c": 2}',
  d: {
    e: "{"f": 3}",
  },
};

parse(object);
// output:
const object = {
  a: 1,
  b: {
    c: 2,
  },
  d: {
    e: {
      f: 3,
    },
  },
};

安装

npm i all-parse -S

使用

// ESM
import parse from 'all-parse';
const obj = parse(object);
const obj = parse(array);

// CommonJS
const parse = require('all-parse').default;

const obj = parse(object);
const obj = parse(array);

自定义parser

import JSON3 from 'json3';
import parse from 'all-parse';

const obj = parse(object, JSON3.parse);

注意点

方法存在副作用,会修改源对象,如果希望不影响源对象,可以再传入之前进行一次深拷贝:

import parse from 'all-parse';

const input = cloneDeep(object);

const obj = parse(input);

Keywords

json

FAQs

Package last updated on 14 Jul 2023

Did you know?

Socket

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.

Install

Related posts