Skip to content

Commit

Permalink
Added acceptObjects.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed Dec 22, 2024
1 parent d1526bd commit 2c54b7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/filters/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ const filterBase = require('./filter-base.js');
const withParser = require('../utils/with-parser.js');

const filter = options => {
const specialAction = options?.acceptObjects ? 'accept' : 'accept-token';
let previousStack = [];
return filterBase({
specialAction: 'accept-token',
specialAction,
transition(stack, chunk, _action, options) {
// debugger;
// console.log('STACK:', previousStack, stack, chunk, _action, '\n');
const returnTokens = [];

// find the common part
Expand Down
14 changes: 14 additions & 0 deletions tests/test-filter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ test.asPromise('filter: array with skipped values', (t, resolve, reject) => {
pipeline.resume();
});

test.asPromise('filter: accept objects', (t, resolve, reject) => {
const data = {a: 1, b: true, c: ['d']},
asm = assembler(),
pipeline = chain([readString(JSON.stringify(data)), filter.withParser({acceptObjects: true, filter: /^(a|c)$/}), asm.tapChain]);

pipeline.on('error', reject);
pipeline.on('end', () => {
t.deepEqual(asm.current, {a: 1, c: ['d']});
resolve();
});

pipeline.resume();
});

test.asPromise('filter: bug46', (t, resolve, reject) => {
const data = [
{data: {a: 1, b: 2}, x: 1},
Expand Down

0 comments on commit 2c54b7d

Please sign in to comment.