🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

comment-json

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comment-json - npm Package Compare versions

Comparing version
4.6.1
to
4.6.2
+1
-2
package.json
{
"name": "comment-json",
"version": "4.6.1",
"version": "4.6.2",
"description": "Parse and stringify JSON with comments. It will retain comments even after saved!",

@@ -65,5 +65,4 @@ "main": "src/index.js",

"array-timsort": "^1.0.3",
"core-util-is": "^1.0.3",
"esprima": "^4.0.1"
}
}

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

const {isArray} = require('core-util-is')
const {sort} = require('array-timsort')

@@ -251,3 +250,3 @@

const prev = length
length += isArray(item)
length += Array.isArray(item)
? item.length

@@ -254,0 +253,0 @@ : 1

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

const {
isObject,
isArray,
isString,
isNumber,
isFunction
} = require('core-util-is')
const PREFIX_BEFORE = 'before'

@@ -50,3 +42,11 @@ const PREFIX_AFTER_PROP = 'after-prop'

const normalize_key = key => isString(key) || isNumber(key)
const is_string = subject => typeof subject === 'string'
const is_number = subject => typeof subject === 'number'
/**
* @param {unknown} v
* @returns {v is NonNullable<object>}
*/
const is_object = v => typeof v === 'object' && v !== null
const normalize_key = key => is_string(key) || is_number(key)
? String(key)

@@ -56,3 +56,3 @@ : null

const set_raw_string_literal = (host, key, raw) => {
if (!isObject(host) || !isString(raw)) {
if (!is_object(host) || !is_string(raw)) {
return

@@ -76,3 +76,3 @@ }

const get_raw_string_literal = (host, key) => {
if (!isObject(host)) {
if (!is_object(host)) {
return

@@ -179,3 +179,3 @@ }

keys.forEach(key => {
if (!isString(key) && !isNumber(key)) {
if (typeof key !== 'string' && typeof key !== 'number') {
return

@@ -195,3 +195,3 @@ }

const is_raw_json = isFunction(JSON.isRawJSON)
const is_raw_json = typeof JSON.isRawJSON === 'function'
// For backward compatibility,

@@ -204,7 +204,7 @@ // since JSON.isRawJSON is not supported in node < 21

const set_comment_line_breaks = (comment, before, after) => {
if (isNumber(before) && before >= 0) {
if (is_number(before) && before >= 0) {
LINE_BREAKS_BEFORE.set(comment, before)
}
if (isNumber(after) && after >= 0) {
if (is_number(after) && after >= 0) {
LINE_BREAKS_AFTER.set(comment, after)

@@ -247,2 +247,6 @@ }

is_string,
is_number,
is_object,
is_raw_json,

@@ -284,7 +288,7 @@ set_raw_string_literal,

assign (target, source, keys) {
if (!isObject(target)) {
if (!is_object(target)) {
throw new TypeError('Cannot convert undefined or null to object')
}
if (!isObject(source)) {
if (!is_object(source)) {
return target

@@ -302,3 +306,3 @@ }

assign_non_prop_comments(target, source)
} else if (!isArray(keys)) {
} else if (!Array.isArray(keys)) {
throw new TypeError('keys must be array or undefined')

@@ -361,3 +365,3 @@ } else if (keys.length === 0) {

}, override = false) {
if (!isObject(source)) {
if (!is_object(source)) {
throw new TypeError('source must be an object')

@@ -370,3 +374,3 @@ }

if (!isObject(target)) {
if (!is_object(target)) {
// No target to move to

@@ -426,3 +430,3 @@ return

}) {
if (!isObject(target)) {
if (!is_object(target)) {
throw new TypeError('target must be an object')

@@ -429,0 +433,0 @@ }

@@ -31,2 +31,3 @@ // JSON formatting

is_object,
define,

@@ -458,4 +459,2 @@ set_raw_string_literal,

const isObject = subject => Object(subject) === subject
/**

@@ -524,3 +523,3 @@ * Converts a JavaScript Object Notation (JSON) string with comments into an

if (!no_comments && result !== null) {
if (!isObject(result)) {
if (!is_object(result)) {
// 1 -> new Number(1)

@@ -527,0 +526,0 @@ // true -> new Boolean(1)

const {
isArray, isObject, isFunction, isNumber, isString
} = require('core-util-is')
const {
PREFIX_BEFORE_ALL,

@@ -23,2 +19,7 @@ PREFIX_BEFORE,

UNDEFINED,
is_string,
is_number,
is_object,
get_raw_string_literal,

@@ -48,3 +49,3 @@ get_comment_line_breaks_before,

const repeat_line_breaks = (line_breaks, gap) => (LF + gap).repeat(line_breaks)
const read_line_breaks = line_breaks => isNumber(line_breaks) && line_breaks >= 0
const read_line_breaks = line_breaks => is_number(line_breaks) && line_breaks >= 0
? line_breaks

@@ -67,4 +68,4 @@ : null

|| !start
|| !isNumber(end.line)
|| !isNumber(start.line)
|| !is_number(end.line)
|| !is_number(start.line)
) {

@@ -191,3 +192,3 @@ return null

const raw = get_raw_string_literal(holder, key)
if (isString(raw)) {
if (is_string(raw)) {
try {

@@ -274,3 +275,3 @@ if (JSON.parse(raw) === value) {

const keys = isArray(replacer)
const keys = Array.isArray(replacer)
? replacer

@@ -340,3 +341,3 @@ : Object.keys(value)

// If the value has a toJSON method, call it to obtain a replacement value.
if (isObject(value) && isFunction(value.toJSON)) {
if (is_object(value) && typeof value.toJSON === 'function') {
value = value.toJSON(key)

@@ -347,3 +348,3 @@ }

// obtain a replacement value.
if (isFunction(replacer)) {
if (typeof replacer === 'function') {
value = replacer.call(holder, key, value)

@@ -375,3 +376,3 @@ }

return isArray(value)
return Array.isArray(value)
? array_stringify(value, gap)

@@ -387,6 +388,6 @@ : object_stringify(value, gap)

const get_indent = space => isString(space)
const get_indent = space => typeof space === 'string'
// If the space parameter is a string, it will be used as the indent string.
? space
: isNumber(space)
: typeof space === 'number'
? SPACE.repeat(space)

@@ -454,3 +455,3 @@ : EMPTY

// vanilla `JSON.parse` allow invalid replacer
if (!isFunction(replacer_) && !isArray(replacer_)) {
if (typeof replacer_ !== 'function' && !Array.isArray(replacer_)) {
replacer_ = null

@@ -468,3 +469,3 @@ }

return isObject(value)
return is_object(value)
? process_comments(value, PREFIX_BEFORE_ALL, EMPTY, true).trimLeft()

@@ -471,0 +472,0 @@ + str