Code Monkey home page Code Monkey logo

defiant.js's People

Contributors

blackwicked avatar bryant1410 avatar ds82 avatar hbi99 avatar hughxdev avatar ketys-from-meiro avatar mmoss avatar user1m avatar yehya 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  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  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  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  avatar  avatar  avatar  avatar  avatar

defiant.js's Issues

Internet Explorer 8 Support

Hi,

thank you for this great plugin.
It would save me a lot of time if it would support IE 8. At the moment it isn't working in this browser. I don't know if you know it already.

An answer would be great!

Wrong number of arguments or invalid property assignment IE 10

I get some javascript error in IE10 The same works fine in Google Chrome.

To reproduce the issue, you can use this fiddle: http://jsfiddle.net/xLBH8/2/

The expected result would be:
expectedresult
This is the error I get in IE:
ieconsole
As a help, here is the stack:
stack

Version infos:
IE10 (10.0.9200.16750 & Windows 7 Service Pack 1 inside Virtualbox):
ieversion
Chrome (32.0.1700.77 & Kubuntu 13.10):
chrome version

Any help is highly appretiated.

Searching with multiple words

Hi there,
Quick question, I want to search for multiple words separately. From the book example in the evaluator, if my search term is "word century" then I want the 1st and the 3rd book highlighted.

I tried using the below

 //*[contains(title,"century sword")]  <-- does not work

//*[contains(title,"century") or contains(title,"sword")] <-- highlights only 3rd book

//*[contains(title,"century") or contains(title,"word")] <-- highlights 1st & 3d

Not sure if something is wrong with my query string. Hopefully you can give me some pointers.

IE 9 - 10 ActiveXObject is undefined Error

I was trying to emulate explorer 9-10 from windows 10 / edge and i a m getting SCRIPT5009: 'ActiveXObject' is undefined

i am using 1.3.1v
is there anything i can do , or its the intended if tested on emulator?

IE problem

Hi,
thanks for Defiant, has helped me a lot!

I have a IE 11 issue, i am getting this error in the console:

"Object doesn't support property or method 'selectNodes' "
"File node.select.js, Line 14, Column: 3"

I get the same error in IE when I paste the demo code from json-search.htm into my file. I tested the json-search.htm on IE 11 and can confirm it's working.

I am using the 1.0-version of Defiant. All works as it should on Chrome Mac/PC

So I guess, there is a conflict with some other javascript library in my project, It's a rather big project with a lot of jquery, backbone, underscore, require etc...

Is there a possible workaround or update for this?

Xpath query issue multiple words

Hi there,
Couldn't find anything online, just putting it here for exposure.

JSON.search(snapshot,'//*[contains(title, "manage") and contains(title, "project")]')
JSON.search(snapshot,'//*[contains(title, "manage project")]')

The second query returns me 1 object while the first one doesn't for some unknown reason.
Check attached image, see title for returned object.
screen shot1

Search mangles source object by converting list containing single item to only that item

Consider...

var obj = {
    key: [
        {
            child_key: "value"
        }
    ]
 };
console.log( "Before: " + JSON.stringify( obj, null, 4 ) );

JSON.search( obj, "//key" );
console.log( "After: " + JSON.stringify( obj, null, 4 ) );

Output is...

Before: {
    "key": [
        {
            "child_key": "value"
        }
    ]
}
After: {
    "key": {
        "child_key": "value"
    }
} 

I've not looked within the library to see if there is a nice way to fix it since I can get away with only using the library for search to see if something exists on a cloned object then extract from the original using regular object manipulation. The root of the problem is that XML doesn't have the idea of an array, so that would need to be expressed somehow in the generated XML.

It would be very handy if it did work, though. As it currently exists, match results are often not useful.

JSON.search(object, query) fails if object changes

I'm building an application that allows users to build a "dictionary", and I'm having the data save into a single JS object currentDictionary with each entry as an object in an array words within currentDictionary. I have a simple search box set up that works perfectly right up until I add a new word, which changes the currentDictionary object by inserting the new word into the words array. After adding the new word, the search no longer works.

Here is the code that runs whenever the search is executed:

var searchResults = [];
if (document.getElementById("searchOptionWord").checked) {
    var wordNameSearch = JSON.search(currentDictionary, '//words[contains(name, "' + search + '")]/name');
    for (var i = 0; i < wordNameSearch.length; i++) {
        searchResults.push(wordNameSearch[i]);
    }
}
if (document.getElementById("searchOptionSimple").checked) {
    var simpleDefinitionSearch = JSON.search(currentDictionary, '//words[contains(simpleDefinition, "' + search + '")]/name');
    for (var i = 0; i < simpleDefinitionSearch.length; i++) {
        if (searchResults.indexOf(simpleDefinitionSearch[i]) < 0) {
            searchResults.push(simpleDefinitionSearch[i]);
        }
    }
}
if (document.getElementById("searchOptionLong").checked) {
    var longDefinitionSearch = JSON.search(currentDictionary, '//words[contains(longDefinition, "' + search + '")]/name');
    for (var i = 0; i < longDefinitionSearch.length; i++) {
        if (searchResults.indexOf(longDefinitionSearch[i]) < 0) {
            searchResults.push(longDefinitionSearch[i]);
        }
    }
}

It would make sense to me that JSON.search() should run anew on the target object each time it is executed, but since it fails after the target changes, it seems that this is not the case?

Is this a limitation of the JS Objects or of Defiant.js?

(tested in Chrome 46.0.2490.80 m and Firefox 40.0.3)

EDIT: Interestingly enough, I've found that if I remove a word instead of adding one to the words array, the search still works. I don't know what this necessarily means, but it does seem strange.

Unexpected behavior when using multiple conditions

I have spotted something strange when trying to connect multiple conditions with OR operator.

Demonstration of the issue:

XPATH EVALUATOR with default data:

//*[contains(title, "The") or contains(author, "Evelyn")]
Returns only 2 items - those which have the word "the" in their title.

//*[contains(title, "The") or contains(author, "velyn")]
Surprisingly it works when I delete the first character from the author condition.
All 3 items are returned in this case.

Must be some kind of problem with the regex replace. I will try to locate and fix it.

Alphanumeric keys

Hi,

I am trying to search json with alphanumeric keys. Its failing to search.

here is my json. I would really appreciate your help.

"sizes": [
{
"L": "20/18",
"M": "10/7",
"S": "30/26",
"2XL": "50/20",
"color": "MIX"
},
{
"L": "10/6",
"M": "10/6",
"S": "10/8",
"2XL": "20/18",
"color": "SR"
},
{
"L": "10/7",
"M": "30/26",
"S": "50/20",
"3XL": "10/6",
"color": "MIX"
},
{
"L": "10/6",
"M": "10/8",
"S": "20/18",
"XL": "10/7",
"color": "BL"
},
{
"L": "30/26",
"M": "50/20",
"S": "10/6",
"3XL": "10/6",
"color": "FGN"
}
]

Bug in XPath Evaluator?

I try the following xpath: "//book[2]/category" with the XPath Evaluator. And the first "category" element is incorrectly highlighted. The second "category" element should be hightlighted instead.

Sorting results

Greetings Hakan,
My current xpath query is like so

//*[contains(title,"century") or contains(title,"honour")]

If I run this in the online xpath evaluator, it highlights the correct records, but the returned object will return in the same order the JSON is in. So in the above example, I want "Sayings of the Century" to be returned as the first object and then "Sword of Honour" as the next object. Is this possible at all?

JSON.search is failing when a string contains double quotes...

Hi,

I tried to use this library to perform some extraction of nodes in my JSON array. However, the function JSON.search is crashing when it is trying to evaluate this line

JSON.search(x,"//*[title = 'this is "NOT" me']);

I tried using escape, double escape but it continue to fail. Is it a bug or a problem with my expression ?

Thks

Creating snapshot too slow

Hi,
How long does it take a snapshot for a JSON of 500KB ? It takes around 30 minutes for me.
ALso, the web worker thing does not seem to be working for me, as the UI is being blocked. Any ideas on this?

Thanks.

defiant in IE

I used defiant to do search on JSON s but didnt work for Internet explorer .
Defiant is not supported by IE ??

IE8: Reference to undeclared namespace prefix: 'xsl'.

Thank you for the great little library, downloaded it today. The Defiant.search method works excellent. But trying out your simple sample from the website on my local machine the following error is thrown when Defiant.render is invoked:

"Reference to undeclared namespace prefix: 'xsl'."
Line: 695, coming from line 61 (render method)

Occurs in IE8 (company's default browser). Copied the code from the website and included defiant.js. Anything missing? Any ideas?

Trying to paginate the snapshot

Thanks for this great library. I'm trying to use

[position() >= 10 and not(position() > 20]

to paginate/limit the result.

What's the right syntax? Thanks!

Defiant not returning results for large json data

I tried defiant and the search with xpath works great, but when the data is huge it's not going all the way till the end, I think its getting broken somewhere inbetween, The data that I tried was of 500KB.

easyer piping

I wonder if it is possible for you to implement the result output like the jq language is doing: https://jqplay.org/

they have a great way to form the return json value.

when XSLTProcessor is undefined

hello
first thanks for the effort put in this project.
I am using PhantomJS and since XSLTProcessor is not supported the ie.polyfill.js can be improved to at least add a message like so

if (typeof (data.transformNode) != "undefined") {
                    var str = data.transformNode(this.xsldoc),
                    span = document.createElement('span');
                    span.innerHTML = str;
                    return span;
                }
                else {
                    span = document.createElement('span');
                    span.innerHTML = "XSLTProcessor transformNode not implemented";
                    return  span;
                }

i was trying to add support myself but looks like it needs more time if ever it was easy.
Thanks and thats all for now.
ehab

Elements with value=0

Hi,
Thanks for the awesome work :)

I've encountered a weird behaviour on objects with value=0, which I believe is a bug:

a = {"obj": {"four": 4, "zero":0, "zerodotone":0.1}}
JSON.search(a, "//zero")
> []

Whereas it works fine for every other number:

a = {"obj": {"four": 4, "zero":0, "zerodotone":0.1}}
JSON.search(a, "//zerodotone")
> [0.1]

This is a bit confusing because a search on a non-existing key also returns [], making it just like if my "zero" object does not exist.

a = {"obj": {"four": 4, "zero":0, "zerodotone":0.1}}
JSON.search(a, "//zero")
> []
JSON.search(a, "//notexistingkey")
> []

DefiantJS in combination with the Wordpress API

I'm using DefiantJS in combination with the Wordpress API. The WP-API JSON output is different then the example in the XPath Evaluator. The posts itself doesn't have a name as identifier. You just use the index to loop through an array.

Example of 10 Wordpress posts > https://jsonblob.com/5551ff82e4b0b306c890a7d1

I need to query through a lot of posts and for example query based on a location. This is working with DefiantJS. But I can't get it working with your pagination example.

Retrieve posts by 2 locations:
//*[contains(locations,"saba") or contains(locations,"curacao")]/..

Can you please help me? Thanks!

JSON<>XML attributes prefix

Currently, there is no way to change the prefix ('@') of the XML attributes during the JSON conversion.
Use the '@' is quite painless when we have to manipulate the corresponding JSON property in Javascript.
It would be great to add a setter for the prefix string.

ios memory usage

Hi,
Thanks for the excellent work! Go Sweden!

Im using v. 1.2.8 to create a webworker snapshot.
Completes in about 12 secs (its a 10MB JSON file), and performs great.
I then packed up the app with cordova (for iOS), and watched memory usage peak above 600MB when the lib attempts to return the snapshot from the webworker to the main thread.
(At least, thats where I think the problem occurs).
This makes iOS call the applicationDidReceiveMemoryWarning, and then the app crashes :-(
Works fine in the simulator (which is not limited on RAM).

Ideas?

Best,

j.

Return full JSON object

I am trying to return the full object from a JSON snapshot search. For example:

 function search1(searchterm) {
  var searched2 = JSON.search( snapshot, '//attributes[contains(Country, "'+searchterm+'")]' );
  console.log(searched2);
 }

I am trying to get the FULL object from the search

[{
    "label": "Jean Makoun",
    "x": 430.8337097167969,
    "y": 257.7498474121094,
    "id": "321",
    "attributes": {
        "Eigenvector Centrality": "0.3346787587121599",
        "Betweenness Centrality": "0.0017126023775967546",
        "Appearances": "66",
        "No": "11",
        "Country": "Cameroon",
        "Club Country": "France",
        "Club": "Rennes",
        "Weighted Degree": "23.0",
        "Modularity Class": "17",
        "Date of birth / Age": "29 May 1983 (aged 31)",
        "Degree": "23",
        "Position": "MF",
        "Eccentricity": "5.0",
        "Closeness Centrality": "0.3202614379084967"
    },
    "color": "rgb(67,132,229)",
    "size": 11.333333015441895
}];

However, it only returns the "attributes" portion of the object. I want the whole object that contains that searched term inside the "attribute" portion. Here is the return...

Object {Eigenvector Centrality: "0.4349752953094465", Betweenness Centrality: "0.007469372100698354", Appearances: "56", No: "4", Country: "Japan"}Appearances: "56"Betweenness Centrality: "0.007469372100698354"Closeness Centrality: "0.3309320126069338"Club: "Milan"Club Country: "Italy"Country: "Japan"Date of birth / Age: "13 June 1986 (aged 27)"Degree: "29"Eccentricity: "5.0"Eigenvector Centrality: "0.4349752953094465"Modularity Class: "27"No: "4"Position: "MF"Weighted Degree: "29.0"__proto__: Object

xpath evaluator highlighting error on defiantjs.com

Hi, Your project looks really interesting. Just to let you know I was trying out the xpath evaluator on http://defiantjs.com/#xpath_evaluator and found that the highlighting was wrong for xpaths that I cooked up myself, for example //book/category seems to only highlight 2 of the 4 books, although I can see they all have a category property. I did try the expression in the console and it worked correctly, so I suppose it is just a highlighting problem.

Nice work!

Cheers,
Peter

Loss of node attributes

JSON.toXML(Defiant.node.toJSON(Defiant.xmlFromString('<data><product id="100">MacBook Pro</product><product id="32">Sony Vaio</product></data>')))

Notice that the id attributes are lost when converting back to XML for String | Number elements

Searching Performance

Hi,

I have been playing around with relatively large json object with multiple levels. in total probably there are 3000 leaf nodes in the json tree.

It takes roughly about 170-250 ms to find a node.

I am not sure where all this time is spent but was wondering if:
1 - It is possible to pre-parse or compile the JSON some how to make it more performant for multiple searches. So you would do something like var compiledJSON = JSON.compile(); var search1Result = compiledJSON.search();var search2Result = compiledJSON.search();

2 - I do not seem to be seeing a difference with //leaf as a search path, or providing the full path. I would have expected that providing the full path or narrowing down the search should make it faster, but it does not.

Thanks a lot

Charbel

Case Insensitive "contains" searches?

It appears that //*[contains(key, "text")] is case sensitive only. I could apply ".toLowerCase()" to the search text, but is there a way to apply it to the key argument?

Perhaps for things that don't directly use the key or field name, you could make it its own function instead of using XPath and have an argument for case sensitive or not? Or perhaps add that in addition to the functionality that already exists?

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.