Skip to content

add "filter" function #11

Description

@gajus

Filter function is used to filter out matches before evaluating the quantifier-expression.

The filter supports a single expression "has".

Example:

test('finds a node which satisfies a parent node selector', (t) => {
  const x = surgeon();

  const document = `
  <div>
    <article>
      <h1>foo</h1>
    </article>
    <article>
      <h1>bar</h1>
      <p></p>
    </article>
  </div>
  `;

  const schema = {
    filter: {
      has: 'p'
    },
    properties: {
      heading: 'h1'
    },
    selector: 'article'
  };

  t.true(x(document, schema).heading === 'bar');
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions