New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-json-pretty

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-json-pretty - npm Package Compare versions

Comparing version 1.6.2 to 1.6.3

.eslintrc.json

20

JSONPretty.jsx

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

/* eslint-disable no-unused-vars */
var React = require('react');
/* eslint-enable no-unused-vars */
var createReactClass = require('create-react-class');

@@ -18,4 +20,4 @@

if (val) {
if (val === "true" || val === "false") {
sps = sps + (val[0] == '"' ? strSpan : booSpan) + val + spanEnd;
if (val === 'true' || val === 'false') {
sps = sps + booSpan + val + spanEnd;
}

@@ -33,6 +35,6 @@ else {

var regLine = /^( *)("[^"]+": )?("[^"]*"|[\w.+-]*)?([,[{]|\[\s*\],?|\{\s*\},?)?$/mg;
return JSON.stringify(obj, null, 2)
.replace(/&/g, '&').replace(/\\"([^,])/g, '"$1')
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(regLine, this._replace);
return JSON.stringify(obj, null, 2)
.replace(/&/g, '&amp;').replace(/\\"([^,])/g, '&quot;$1')
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(regLine, this._replace);
},

@@ -49,3 +51,7 @@ render: function () {

catch (e) {
console.error("The string is not a valid json data!", e);
console.error('The string is not a valid json data!', e);
return(
<pre {...rest} className='json-pretty' dangerouslySetInnerHTML={{__html: json}}>
</pre>
);
}

@@ -52,0 +58,0 @@ }

{
"name": "react-json-pretty",
"version": "1.6.2",
"version": "1.6.3",
"description": "A code formatting tool for raw json data",
"main": "src/JSONPretty.js",
"scripts": {
"test": "jest",
"test": "jest --coverage --silent",
"build": "npm run build-styl && npm run build-jsx",
"eslint": "eslint JSONPretty.jsx",
"precommit": "npm run build && npm run eslint",
"prepush": "npm test",
"build-styl-monikai": "stylus --compress < JSONPretty.monikai.styl > src/JSONPretty.monikai.css",

@@ -37,2 +40,5 @@ "build-styl-1337": "stylus --compress < JSONPretty.1337.styl > src/JSONPretty.1337.css",

"babel-preset-react": "^6.24.1",
"eslint": "^3.19.0",
"eslint-plugin-react": "^6.10.3",
"husky": "^0.13.3",
"jest": "^19.0.2",

@@ -51,3 +57,13 @@ "react": "^15.5.4",

"create-react-class": "^15.5.2"
},
"jest": {
"collectCoverageFrom": [
"**.jsx",
"src/**.js"
],
"coverageDirectory": "tests",
"coverageReporters": [
"lcov"
]
}
}

@@ -56,2 +56,13 @@ # React JSON Pretty

### 1.6.3
1. Add jest coverage
2. Add eslint
3. Add husky for git hook
### 1.6.2
1. Add testcases(using jest)
2. Add .travis.yml for travis ci
### 1.6.1

@@ -58,0 +69,0 @@

@@ -0,1 +1,3 @@

'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -5,3 +7,5 @@

/* eslint-disable no-unused-vars */
var React = require('react');
/* eslint-enable no-unused-vars */
var createReactClass = require('create-react-class');

@@ -11,3 +15,3 @@

// 格式化函数
_replace: function (match, ind, key, val, tra) {
_replace: function _replace(match, ind, key, val, tra) {
var spanEnd = '</span>';

@@ -24,4 +28,4 @@ var keySpan = '<span class=json-key>';

if (val) {
if (val === "true" || val === "false") {
sps = sps + (val[0] == '"' ? strSpan : booSpan) + val + spanEnd;
if (val === 'true' || val === 'false') {
sps = sps + booSpan + val + spanEnd;
} else {

@@ -35,3 +39,3 @@ sps = sps + (val[0] == '"' ? strSpan : valSpan) + val + spanEnd;

// JSON =》 HTML转换器
_pretty: function (obj) {
_pretty: function _pretty(obj) {
// 逐行匹配,列举:“key”: "value" | "key": value | "key": [ | "key": { | "key": [],| "Key": {},

@@ -41,7 +45,7 @@ var regLine = /^( *)("[^"]+": )?("[^"]*"|[\w.+-]*)?([,[{]|\[\s*\],?|\{\s*\},?)?$/mg;

},
render: function () {
render: function render() {
// See https://facebook.github.io/react/warnings/unknown-prop.html
var _props = this.props,
{ json } = _props,
json = _props.json,
rest = _objectWithoutProperties(_props, ['json']);

@@ -53,3 +57,4 @@

} catch (e) {
console.error("The string is not a valid json data!", e);
console.error('The string is not a valid json data!', e);
return React.createElement('pre', _extends({}, rest, { className: 'json-pretty', dangerouslySetInnerHTML: { __html: json } }));
}

@@ -56,0 +61,0 @@ }

@@ -28,2 +28,20 @@ import React from 'react';

expect(tree).toMatchSnapshot();
});
test('src/JSONPretty.js -- string', () => {
const json = renderer.create(
<JSONPretty json={JSON.stringify(obj2)}></JSONPretty>
);
let tree = json.toJSON();
expect(tree).toMatchSnapshot();
});
test('JSONPretty.js -- StringInvalid', () => {
const json = renderer.create(
<JSONPretty json={"{1211221}"}></JSONPretty>
);
let tree = json.toJSON();
expect(tree).toMatchSnapshot();
});

@@ -8,2 +8,5 @@ import React from 'react';

bbbb: true,
efef: "true",
efed: "false",
efee: false,
cccc: "ab\"cd\\",

@@ -29,2 +32,20 @@ dddd: {

expect(tree).toMatchSnapshot();
});
test('JSONPretty.jsx -- String', () => {
const json = renderer.create(
<JSONPretty json={JSON.stringify(obj2)}></JSONPretty>
);
let tree = json.toJSON();
expect(tree).toMatchSnapshot();
});
test('JSONPretty.jsx -- StringInvalid', () => {
const json = renderer.create(
<JSONPretty json={"{1211221}"}></JSONPretty>
);
let tree = json.toJSON();
expect(tree).toMatchSnapshot();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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