Skip to content

Commit

Permalink
[eslint] clean up formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 16, 2024
1 parent d390c99 commit 21e95e5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"no-redeclare": 1,
"no-restricted-syntax": 1,
"object-curly-newline": 0,
"max-statements": 1,
"operator-linebreak": 0,
"max-statements": 1,
"operator-linebreak": 0,
"sort-keys": 1,
},

Expand Down
98 changes: 50 additions & 48 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,56 @@ module.exports = function stableStringify(obj) {
};

var seen = [];
return (function stringify(parent, key, node, level) {
var indent = space ? '\n' + strRepeat(level, space) : '';
var colonSeparator = space ? ': ' : ':';

if (node && node.toJSON && typeof node.toJSON === 'function') {
node = node.toJSON();
}

node = replacer(parent, key, node);

if (node === undefined) {
return;
}
if (typeof node !== 'object' || node === null) {
return jsonStringify(node);
}
if (isArray(node)) {
return (
function stringify(parent, key, node, level) {
var indent = space ? '\n' + strRepeat(level, space) : '';
var colonSeparator = space ? ': ' : ':';

if (node && node.toJSON && typeof node.toJSON === 'function') {
node = node.toJSON();
}

node = replacer(parent, key, node);

if (node === undefined) {
return;
}
if (typeof node !== 'object' || node === null) {
return jsonStringify(node);
}
if (isArray(node)) {
var out = [];
for (var i = 0; i < node.length; i++) {
var item = stringify(node, i, node[i], level + 1) || jsonStringify(null);
out[out.length] = indent + space + item;
}
return '[' + $join(out, ',') + indent + ']';
}

if ($indexOf(seen, node) !== -1) {
if (cycles) { return jsonStringify('__cycle__'); }
throw new TypeError('Converting circular structure to JSON');
} else {
seen[seen.length] = node;
}

var keys = $sort(objectKeys(node), cmp && cmp(node));
var out = [];
for (var i = 0; i < node.length; i++) {
var item = stringify(node, i, node[i], level + 1) || jsonStringify(null);
out[out.length] = indent + space + item;
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = stringify(node, key, node[key], level + 1);

if (!value) { continue; }

var keyValue = jsonStringify(key)
+ colonSeparator
+ value;

out[out.length] = indent + space + keyValue;
}
return '[' + $join(out, ',') + indent + ']';
}

if ($indexOf(seen, node) !== -1) {
if (cycles) { return jsonStringify('__cycle__'); }
throw new TypeError('Converting circular structure to JSON');
} else {
seen[seen.length] = node;
}

var keys = $sort(objectKeys(node), cmp && cmp(node));
var out = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = stringify(node, key, node[key], level + 1);

if (!value) { continue; }

var keyValue = jsonStringify(key)
+ colonSeparator
+ value;

out[out.length] = indent + space + keyValue;
}
$splice(seen, $indexOf(seen, node), 1);
return '{' + $join(out, ',') + indent + '}';

}({ '': obj }, '', obj, 0));
$splice(seen, $indexOf(seen, node), 1);
return '{' + $join(out, ',') + indent + '}';

}({ '': obj }, '', obj, 0)
);
};

0 comments on commit 21e95e5

Please sign in to comment.