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

babel-plugin-object-to-json-parse

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-object-to-json-parse - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

46

dist/utils.js

@@ -24,3 +24,26 @@ "use strict";

};
const createSafeStringForJsonParse = (value) => {
if (/\\/.test(value)) {
value = value.replace(/\\/g, '\\\\');
}
if (/"/.test(value)) {
value = value.replace(/"/g, '\\"');
}
if (/[\t\f\r\n\b]/g.test(value)) {
const codes = ['\f', '\r', '\n', '\t', '\b'];
const replaceCodes = ['\\f', '\\r', '\\n', '\\t', '\\b'];
for (let i = 0; i < codes.length; i++) {
value = value.replace(new RegExp(codes[i]), replaceCodes[i]);
}
}
return value;
};
function converter(node) {
// for negative number, ex) -10
if (types_1.isUnaryExpression(node)) {
const { operator, argument } = node;
if (operator === '-' && types_1.isNumericLiteral(argument)) {
return -argument.value;
}
}
if (!isValidJsonValue(node)) {

@@ -30,17 +53,5 @@ throw new Error('Invalid value is included.');

if (types_1.isStringLiteral(node)) {
let { value } = node;
if (/\\/.test(value)) {
value = value.replace(/\\/g, '\\\\');
}
if (/"/.test(value)) {
value = value.replace(/"/g, '\\"');
}
if (/[\t\f\r\n\b]/g.test(value)) {
const codes = ['\f', '\r', '\n', '\t', '\b'];
const replaceCodes = ['\\f', '\\r', '\\n', '\\t', '\\b'];
for (let i = 0; i < codes.length; i++) {
value = value.replace(new RegExp(codes[i]), replaceCodes[i]);
}
}
return value;
const { value } = node;
const safeValue = createSafeStringForJsonParse(value);
return safeValue;
}

@@ -63,3 +74,6 @@ if (types_1.isNullLiteral(node)) {

return properties.reduce((acc, cur) => {
const key = cur.key.name || cur.key.value;
let key = cur.key.name || cur.key.value;
if (typeof key === 'string') {
key = createSafeStringForJsonParse(key);
}
// see issues#10

@@ -66,0 +80,0 @@ if (typeof key === 'number' && !Number.isSafeInteger(key)) {

{
"name": "babel-plugin-object-to-json-parse",
"version": "0.1.2",
"version": "0.2.0",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "scripts": {

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