Git Product home page Git Product logo

js-xpath's Introduction

js-xpath

An XPath Parser/Generator for JavaScript using the Jison parser/generator.

Demo

See the xpath.html file for a very simple usage for parsing xpath expressions.

Usage

First include the libraries and xpath.js and models.js files in your document. Then try the following to get started.

var expr = "/some/xpath/expression"
var parsed = xpath.parse(expr);
var regenerated = parsed.toXPath();

For examples of supported expressions, see the tests!

models.js provides a default xpathmodels which does not support the hashtag preprocessor. If you want to support hashtags within xpaths, you can use:

hashtagConfig = {
  isValidNamespace: function(namespace),
  hashtagToXPath: function(hashtag),
  toHashtag: function(expr)
}
xPathModels = XPathModels(hashtagConfig)

hashtags use the format #namespace/arbitrarily/long/path and do not support filtering

Tests

  • Open test/tests.html to run tests (must be serving all files in the library).
  • Individual tests are found in test/parserTests.js and test/generatorTests.js

Known Limitations

  • Filter expressions are not supported due to a known bug in jison.
  • See the failing tests for examples of expressions that are known not to work.

Code Structure

File Content
dist/ contains a browser-ready build of the parser
src/jison/ contains the jison parser files.
src/lib/ external libraries that the parser depends on.
src/main.js the entry point for non-browser users.
src/models.js the underlying models used in parsing.
src/parser.js the jison built parser file, do not edit manually.
test/ qunit tests for the parser and generator.

Build

This is built using jison. To build the parser file yourself run:

$ npm run build - This will build both the distribution (browserify) package in dist/ and rebuild the Jison parser (src/parser.js) from the src/jison/ files. $ npm run jison - Rebuild parser.js from the Jison specification files. $ npm run dist - Rebuild the browser friendly distribution from the current source files.

For more information on jison see the jison project website at: http://zaach.github.com/jison/.

js-xpath's People

Contributors

biyeun avatar czue avatar dannyroberts avatar dependabot[bot] avatar emord avatar gburtini avatar gherceg avatar millerdev avatar mwhite avatar philomates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-xpath's Issues

Module parse failed: Invalid labeled declaration

So, i use webpack and babel-loader with next presets: "env", "react".
An error occurs during the build:

ERROR in ./node_modules/js-xpath/src/parser.js
Module parse failed: Invalid labeled declaration (423:26)
You may need an appropriate loader to handle this file type.
|                 lstack.length = lstack.length - n;
|             }
|             _token_stack: var lex = function lex() {
|                 var token;
|                 token = lexer.lex() || EOF;
 @ ./node_modules/js-xpath/src/main.js 3:13-35

schemeNumber.js (and bigNumber.js if necessary) should come in via npm.

Browserify should be capable of resolving the dependency if we require() it, then the reference can be to the distribution file alone.

There's probably also a 'bug' in having xpath.html refer to src/models as well as the distribution file, as the distribution file likely already includes the models (and if it doesn't, we should resolve that issue instead).

Deploy to NPM

I am happy to do this, but do you guys have an internal NPM account you'd like me to make an admin. of the new deployment?

I want to do this basically just so that I can reference the package as js-xpath instead of the seemingly unreliable git URL package identifier.

`jison` and `browserify` are global dependencies.

It looks like node-qunit-phantomjs and jshint are global devDependencies required too. This should be documented somewhere, as the npm run build instructions fail somewhat ambiguously if browserify isn't installed.

Rewrite tests to use a nicer testing infrastructure.

I'm mostly just making notes for myself at this point, but most of these tests could be written with Jest or Mocha and mocked to not need PhantomJS at all.

This would be a cleaner way to run the tests. I will prepare a PR as soon as possible to show you guys what I mean.

package.json says MIT, but LICENSE says BSD.

I was going to create a PR to fix this, but I realize now I'm not sure which is right. I've also got a set of PRs open that touch package.json at the moment.

You guys are based in Cambridge, so I vote MIT. ;)

`main.js` is misleading

The entry point is actually xpath.js right now according to package.json. Perhaps rename main.js or move to a tools, src, or dist subdirectory.

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.