Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.parse = parse;
*/
const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
function (k, v) { return k === '' || Array.isArray(this) || -1 < replacer.indexOf(k) ? v : void 0; } :
(replacer || noop);
const known = new Map;
const input = [];
Expand Down
2 changes: 1 addition & 1 deletion esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const parse = (text, reviver) => {
*/
export const stringify = (value, replacer, space) => {
const $ = replacer && typeof replacer === object ?
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
function (k, v) { return k === '' || Array.isArray(this) || -1 < replacer.indexOf(k) ? v : void 0; } :
(replacer || noop);
const known = new Map;
const input = [];
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ if (typeof Symbol !== 'undefined') {
);
}());

(function () {
var a = ['a', 'b', 'c'];
var json = JSON.stringify(a, ['0']);
var restored = Flatted.parse(Flatted.stringify(a, ['0']));
console.assert(
JSON.stringify(restored) === json,
'whitelisted replacer does not filter Array values: '+ json
);
}());

(function () {
var a = { b: { '': { c: { d: 1 } } } };
a._circular = a.b[''];
Expand Down