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

jsonrepair

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonrepair - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

lib/cjs/jsonrepair.js

11

CHANGELOG.md
# Changelog
## 2021-01-13, version 2.0.0
- Renamed the library from `simple-json-repair` to `jsonrepair`.
Thanks a lot @vmx for making this npm package name available!
- Change source code from TypeScript to JavaScript. Reasons: TypeScript
conflicts with using native ESM, requiring ugly workarounds.
Due to some (old) TypeScript issues we also have to use `@ts-ignore` a lot.
Using TypeScript makes running tests slower. And in this case, TypeScript
hardly adds value since we have a very simple API and function signatures.
## 2020-11-06, version 1.1.0

@@ -4,0 +15,0 @@

2

lib/cjs/index-commonjs.js

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

module.exports = require('./simpleJsonRepair.js').default
module.exports = require('./jsonrepair.js').default
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var JsonRepairError = /** @class */ (function (_super) {
__extends(JsonRepairError, _super);
/**
* @param {string} message Explanatory message
* @param {number} char Character index where the error happened
*/
function JsonRepairError(message, char) {
var _this = _super.call(this, message + ' (char ' + char + ')') || this;
_this.char = char;
return _this;
}
return JsonRepairError;
}(SyntaxError));
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = JsonRepairError;
function JsonRepairError(message, char) {
if (!(this instanceof JsonRepairError)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
this.message = message + ' (char ' + char + ')';
this.char = char;
this.stack = new Error().stack;
}
JsonRepairError.prototype = new Error();
JsonRepairError.prototype.constructor = Error;
//# sourceMappingURL=JsonRepairError.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.insertAtIndex = exports.insertBeforeLastWhitespace = exports.stripLastOccurrence = exports.normalizeQuote = exports.isQuote = exports.normalizeWhitespace = exports.isSpecialWhitespace = exports.isWhitespace = exports.isDigit = exports.isHex = exports.isAlpha = void 0;
var SINGLE_QUOTES = [
'\'',
'\u2018',
'\u2019',
'\u0060',
'\u00B4' // acute accent
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isAlpha = isAlpha;
exports.isHex = isHex;
exports.isDigit = isDigit;
exports.isWhitespace = isWhitespace;
exports.isSpecialWhitespace = isSpecialWhitespace;
exports.normalizeWhitespace = normalizeWhitespace;
exports.isQuote = isQuote;
exports.normalizeQuote = normalizeQuote;
exports.stripLastOccurrence = stripLastOccurrence;
exports.insertBeforeLastWhitespace = insertBeforeLastWhitespace;
exports.insertAtIndex = insertAtIndex;
var SINGLE_QUOTES = ['\'', // quote
"\u2018", // quote left
"\u2019", // quote right
"`", // grave accent
"\xB4" // acute accent
];
var DOUBLE_QUOTES = [
'"',
'\u201C',
'\u201D' // double quote right
var DOUBLE_QUOTES = ['"', "\u201C", // double quote left
"\u201D" // double quote right
];
/**
* Check if the given character contains an alpha character, a-z, A-Z, _
* @param {string} c
* @return {boolean}
*/
function isAlpha(c) {
return /^[a-zA-Z_]$/.test(c);
return /^[a-zA-Z_]$/.test(c);
}
exports.isAlpha = isAlpha;
/**
* Check if the given character contains a hexadecimal character 0-9, a-f, A-F
* @param {string} c
* @return {boolean}
*/
function isHex(c) {
return /^[0-9a-fA-F]$/.test(c);
return /^[0-9a-fA-F]$/.test(c);
}
exports.isHex = isHex;
/**
* checks if the given char c is a digit
* @param {string} c
* @return {boolean}
*/
function isDigit(c) {
return (c >= '0' && c <= '9');
return c >= '0' && c <= '9';
}
exports.isDigit = isDigit;
/**
* Check if the given character is a whitespace character like space, tab, or
* newline
* @param {string} c
* @return {boolean}
*/
function isWhitespace(c) {
return c === ' ' || c === '\t' || c === '\n' || c === '\r';
return c === ' ' || c === '\t' || c === '\n' || c === '\r';
}
exports.isWhitespace = isWhitespace;
/**
* Check if the given character is a special whitespace character, some
* unicode variant
* @param {string} c
* @return {boolean}
*/
function isSpecialWhitespace(c) {
return (c === '\u00A0' ||
(c >= '\u2000' && c <= '\u200A') ||
c === '\u202F' ||
c === '\u205F' ||
c === '\u3000');
return c === "\xA0" || c >= "\u2000" && c <= "\u200A" || c === "\u202F" || c === "\u205F" || c === "\u3000";
}
exports.isSpecialWhitespace = isSpecialWhitespace;
/**
* Replace speical whitespace characters with regular spaces
* @param {string} text
* @returns {string}
*/
function normalizeWhitespace(text) {
var normalized = '';
for (var i = 0; i < text.length; i++) {
var char = text[i];
normalized += isSpecialWhitespace(char)
? ' '
: char;
}
return normalized;
var normalized = '';
for (var i = 0; i < text.length; i++) {
var char = text[i];
normalized += isSpecialWhitespace(char) ? ' ' : char;
}
return normalized;
}
exports.normalizeWhitespace = normalizeWhitespace;
/**
* Test whether the given character is a quote or double quote character.
* Also tests for special variants of quotes.
* @param {string} c
* @returns {boolean}
*/
function isQuote(c) {
return SINGLE_QUOTES.includes(c) || DOUBLE_QUOTES.includes(c);
return SINGLE_QUOTES.includes(c) || DOUBLE_QUOTES.includes(c);
}
exports.isQuote = isQuote;
/**
* Normalize special double or single quote characters to their regular
* variant ' or "
* @param {string} c
* @returns {string}
*/
function normalizeQuote(c) {
if (SINGLE_QUOTES.includes(c)) {
return '\'';
}
if (DOUBLE_QUOTES.includes(c)) {
return '"';
}
return c;
if (SINGLE_QUOTES.includes(c)) {
return '\'';
}
if (DOUBLE_QUOTES.includes(c)) {
return '"';
}
return c;
}
exports.normalizeQuote = normalizeQuote;
/**
* Strip last occurrence of textToStrip from text
* @param {string} text
* @param {string} textToStrip
* @returns {string}
*/
function stripLastOccurrence(text, textToStrip) {
var index = text.lastIndexOf(textToStrip);
return (index !== -1)
? text.substring(0, index) + text.substring(index + 1)
: text;
var index = text.lastIndexOf(textToStrip);
return index !== -1 ? text.substring(0, index) + text.substring(index + 1) : text;
}
exports.stripLastOccurrence = stripLastOccurrence;
/**
* Insert textToInsert into text before the last whitespace in text
* @param {string} text
* @param {string} textToInsert
* @returns {string}
*/
function insertBeforeLastWhitespace(text, textToInsert) {
return text.replace(/\s*$/, function (match) { return textToInsert + match; });
return text.replace(/\s*$/, function (match) {
return textToInsert + match;
});
}
exports.insertBeforeLastWhitespace = insertBeforeLastWhitespace;
/**
* Insert textToInsert at index in text
* @param {string} text
* @param {string} textToInsert
* @param {number} index
* @returns {string}
*/
function insertAtIndex(text, textToInsert, index) {
return text.substring(0, index) + textToInsert + text.substring(index);
return text.substring(0, index) + textToInsert + text.substring(index);
}
exports.insertAtIndex = insertAtIndex;
//# sourceMappingURL=stringUtils.js.map

@@ -1,27 +0,12 @@

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var JsonRepairError = /** @class */ (function (_super) {
__extends(JsonRepairError, _super);
/**
* @param {string} message Explanatory message
* @param {number} char Character index where the error happened
*/
function JsonRepairError(message, char) {
var _this = _super.call(this, message + ' (char ' + char + ')') || this;
_this.char = char;
return _this;
}
return JsonRepairError;
}(SyntaxError));
export default JsonRepairError;
export default function JsonRepairError(message, char) {
if (!(this instanceof JsonRepairError)) {
throw new SyntaxError('Constructor must be called with the new operator');
}
this.message = message + ' (char ' + char + ')';
this.char = char;
this.stack = new Error().stack;
}
JsonRepairError.prototype = new Error();
JsonRepairError.prototype.constructor = Error;
//# sourceMappingURL=JsonRepairError.js.map

@@ -1,30 +0,36 @@

var SINGLE_QUOTES = [
'\'',
'\u2018',
'\u2019',
'\u0060',
'\u00B4' // acute accent
var SINGLE_QUOTES = ['\'', // quote
"\u2018", // quote left
"\u2019", // quote right
"`", // grave accent
"\xB4" // acute accent
];
var DOUBLE_QUOTES = [
'"',
'\u201C',
'\u201D' // double quote right
var DOUBLE_QUOTES = ['"', "\u201C", // double quote left
"\u201D" // double quote right
];
/**
* Check if the given character contains an alpha character, a-z, A-Z, _
* @param {string} c
* @return {boolean}
*/
export function isAlpha(c) {
return /^[a-zA-Z_]$/.test(c);
return /^[a-zA-Z_]$/.test(c);
}
/**
* Check if the given character contains a hexadecimal character 0-9, a-f, A-F
* @param {string} c
* @return {boolean}
*/
export function isHex(c) {
return /^[0-9a-fA-F]$/.test(c);
return /^[0-9a-fA-F]$/.test(c);
}
/**
* checks if the given char c is a digit
* @param {string} c
* @return {boolean}
*/
export function isDigit(c) {
return (c >= '0' && c <= '9');
return c >= '0' && c <= '9';
}

@@ -34,46 +40,97 @@ /**

* newline
* @param {string} c
* @return {boolean}
*/
export function isWhitespace(c) {
return c === ' ' || c === '\t' || c === '\n' || c === '\r';
return c === ' ' || c === '\t' || c === '\n' || c === '\r';
}
/**
* Check if the given character is a special whitespace character, some
* unicode variant
* @param {string} c
* @return {boolean}
*/
export function isSpecialWhitespace(c) {
return (c === '\u00A0' ||
(c >= '\u2000' && c <= '\u200A') ||
c === '\u202F' ||
c === '\u205F' ||
c === '\u3000');
return c === "\xA0" || c >= "\u2000" && c <= "\u200A" || c === "\u202F" || c === "\u205F" || c === "\u3000";
}
/**
* Replace speical whitespace characters with regular spaces
* @param {string} text
* @returns {string}
*/
export function normalizeWhitespace(text) {
var normalized = '';
for (var i = 0; i < text.length; i++) {
var char = text[i];
normalized += isSpecialWhitespace(char)
? ' '
: char;
}
return normalized;
var normalized = '';
for (var i = 0; i < text.length; i++) {
var char = text[i];
normalized += isSpecialWhitespace(char) ? ' ' : char;
}
return normalized;
}
/**
* Test whether the given character is a quote or double quote character.
* Also tests for special variants of quotes.
* @param {string} c
* @returns {boolean}
*/
export function isQuote(c) {
return SINGLE_QUOTES.includes(c) || DOUBLE_QUOTES.includes(c);
return SINGLE_QUOTES.includes(c) || DOUBLE_QUOTES.includes(c);
}
/**
* Normalize special double or single quote characters to their regular
* variant ' or "
* @param {string} c
* @returns {string}
*/
export function normalizeQuote(c) {
if (SINGLE_QUOTES.includes(c)) {
return '\'';
}
if (DOUBLE_QUOTES.includes(c)) {
return '"';
}
return c;
if (SINGLE_QUOTES.includes(c)) {
return '\'';
}
if (DOUBLE_QUOTES.includes(c)) {
return '"';
}
return c;
}
/**
* Strip last occurrence of textToStrip from text
* @param {string} text
* @param {string} textToStrip
* @returns {string}
*/
export function stripLastOccurrence(text, textToStrip) {
var index = text.lastIndexOf(textToStrip);
return (index !== -1)
? text.substring(0, index) + text.substring(index + 1)
: text;
var index = text.lastIndexOf(textToStrip);
return index !== -1 ? text.substring(0, index) + text.substring(index + 1) : text;
}
/**
* Insert textToInsert into text before the last whitespace in text
* @param {string} text
* @param {string} textToInsert
* @returns {string}
*/
export function insertBeforeLastWhitespace(text, textToInsert) {
return text.replace(/\s*$/, function (match) { return textToInsert + match; });
return text.replace(/\s*$/, function (match) {
return textToInsert + match;
});
}
/**
* Insert textToInsert at index in text
* @param {string} text
* @param {string} textToInsert
* @param {number} index
* @returns {string}
*/
export function insertAtIndex(text, textToInsert, index) {
return text.substring(0, index) + textToInsert + text.substring(index);
return text.substring(0, index) + textToInsert + text.substring(index);
}
//# sourceMappingURL=stringUtils.js.map
The ISC License
Copyright (c) 2020 by Jos de Jong
Copyright (c) 2020-2021 by Jos de Jong

@@ -5,0 +5,0 @@ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

{
"name": "jsonrepair",
"version": "1.1.0",
"version": "2.0.0",
"description": "Repair broken JSON documents",
"repository": {
"type": "git",
"url": "https://github.com/josdejong/simple-json-repair.git"
"url": "https://github.com/josdejong/jsonrepair.git"
},
"type": "module",
"main": "lib/cjs/index-commonjs.js",
"module": "lib/esm/simpleJsonRepair.js",
"browser": "lib/umd/simpleJsonRepair.min.js",
"types": "lib/esm/simpleJsonRepair.d.ts",
"module": "lib/esm/jsonrepair.js",
"browser": "lib/umd/jsonrepair.min.js",
"types": "lib/index.d.ts",
"keywords": [

@@ -24,11 +24,11 @@ "simple",

"test:lib": "mocha test-lib/*.test.*",
"build": "npm run clean && npm run build:esm && npm run build:esm:fix:imports && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"build": "npm run clean && npm run build:ts && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",
"clean": "del-cli lib",
"build:esm": "tsc --module es2015 --target es5 --outDir lib/esm",
"build:esm:fix:imports": "node tools/esm/fixImportExtensions.cjs",
"build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs && cp-cli tools/cjs lib/cjs",
"build:umd": "rollup lib/esm/simpleJsonRepair.js --format umd --name 'simpleJsonRepair' --sourcemap --output.file lib/umd/simpleJsonRepair.js && cp-cli tools/cjs/package.json lib/umd/package.json",
"build:umd:min": "uglifyjs --compress --mangle --source-map --comments --output lib/umd/simpleJsonRepair.min.js -- lib/umd/simpleJsonRepair.js",
"build:ts": "cpy src/index.d.ts lib",
"build:esm": "babel src --out-dir lib/esm --source-maps --config-file ./babel.config.json",
"build:cjs": "babel src --out-dir lib/cjs --source-maps --config-file ./babel-cjs.config.json && cpy tools/cjs lib/cjs",
"build:umd": "rollup lib/esm/jsonrepair.js --format umd --name 'jsonrepair' --sourcemap --output.file lib/umd/jsonrepair.js && cpy tools/cjs/package.json lib/umd",
"build:umd:min": "uglifyjs --compress --mangle --source-map --comments --output lib/umd/jsonrepair.min.js -- lib/umd/jsonrepair.js",
"link": "npm run build",
"lint": "eslint src/**/*.ts",
"lint": "eslint src/**/*.js",
"build-and-test": "npm run lint && npm run build && npm run test:lib",

@@ -45,19 +45,16 @@ "prepublishOnly": "npm run build-and-test"

"devDependencies": {
"@types/mocha": "8.0.3",
"@typescript-eslint/eslint-plugin": "4.6.0",
"@typescript-eslint/parser": "4.6.0",
"cp-cli": "2.0.0",
"@babel/cli": "7.12.10",
"@babel/core": "7.12.10",
"@babel/preset-env": "7.12.11",
"cpy-cli": "3.1.1",
"del-cli": "3.0.1",
"eslint": "7.12.1",
"eslint-config-standard": "16.0.1",
"eslint": "7.17.0",
"eslint-config-standard": "16.0.2",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"mocha": "8.2.0",
"rollup": "2.33.1",
"ts-node": "9.0.0",
"tslib": "2.0.3",
"typescript": "4.0.5",
"uglify-js": "3.11.5"
"mocha": "8.2.1",
"rollup": "2.36.1",
"uglify-js": "3.12.4"
}
}

@@ -1,6 +0,6 @@

# simple-json-repair
# jsonrepair
Repair invalid JSON documents.
Try it out: https://josdejong.github.io/simple-json-repair/
Try it out: https://josdejong.github.io/jsonrepair/

@@ -27,3 +27,3 @@ The following issues can be fixed:

```
$ npm install simple-json-repair
$ npm install jsonrepair
```

@@ -37,3 +37,3 @@

```js
import simpleJsonRepair from 'simple-json-repair'
import jsonrepair from 'jsonrepair'

@@ -45,3 +45,3 @@ // The following is invalid JSON: is consists of JSON contents copied from

const repaired = simpleJsonRepair(json)
const repaired = jsonrepair(json)
console.log(repaired) // '{"name": "John"}'

@@ -54,6 +54,6 @@ ```

```
simpleJsonRepair(json: string) : string
jsonrepair(json: string) : string
```
The function `simpleJsonRepair` throws an exception when an issue is encountered
The function `jsonrepair` throws an exception when an issue is encountered
which could not be solved. When no error is thrown, the output will be valid JSON.

@@ -60,0 +60,0 @@

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