Git Product home page Git Product logo

fontoxpath's Introduction

fontoxpath Build Status devDependency Status NPM version

A minimalistic XPath 3.1 selector engine for (XML) nodes.

Demo page

How to use

const { evaluateXPathToBoolean } = require('fontoxpath');
const documentNode = new DOMParser().parseFromString('<xml/>', 'text/xml');
console.log(evaluateXPathToBoolean('/xml => exists()', documentNode)); // => true

FontoXPath supplies a number of API functions:

  • A number of evaluateXPath.* functions:
    • evaluateXPath(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, returnType: number) => *
    • evaluateXPathToNodes(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => Node[]
    • evaluateXPathToFirstNode(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => Node
    • evaluateXPathToBoolean(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => boolean
    • evaluateXPathToNumber(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => number
    • evaluateXPathToNumbers(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => number[]
    • evaluateXPathToString(xpath: string, contextNode: Node, domFacade: ?DomFacade=, variables: Object={}, options: {namespaceResolver: function(string):string?}) => string
  • precompileXPath(xpath: string) => Promise<string>
    • Precompile an XPath expression for future use. This uses a webworker to populate an IndexedDB database so that the XPath is available for future use. This is a no-op on systems without indexedDB.
  • registerCustomXPathFunction(name: string, signature: string[], returnType: string, callback: function)
    • Can be used to register custom functions. They are registered globally.

Features

Note that this engine assumes XPath 1.0 compatibility mode turned off.

Not all XPath 3.1 functions are implemented yet. We accept pull requests for missing features.

The following features are unavailable at this moment, but will be implemented at some point in time (and even sooner if you can help!):

  • Some DateTime related functions
  • Collation related functions (fn:compare#3)
  • functions using patterns
  • Some other miscellaneous functions
  • The ? lookup operator for maps and arrays
  • XML parsing
  • The treat as operator
  • The >> and << operators

For all available features, see the unit tests.

Compatibility

This engine is pretty DOM-agnostic, it has a good track record with the browser DOM implementations and slimdom.js. There are a number of known issues with xmldom because it does not follow the DOM spec on some features including namespaces.

Contribution

Please refer to the Contribution Guide.

fontoxpath's People

Contributors

drrataplan avatar thomasgravekamp avatar bwrrp avatar evandervalk avatar mvanbutselaar avatar thomasbrekelmans avatar devatwork avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.