Giter Site home page Giter Site logo

defiant.js's Introduction

DefiantJS provides the ability for you to build smart templates applicable on JSON structures, based upon proven & standardized technologies such as XSLT and XPath.

DefiantJS also extends the global object JSON with the method "search", which enables searches on JSON structures with XPath expressions and returns matches as an array-like object.

For detailed information, please visit defiantjs.com and try out the XPath Evaluator.

###Example usage

  • Snapshots - very large JSON
var data = {
  // ...biiig JSON structure...
};

// this way has a non-blocking effect on the UI-thread
Defiant.getSnapshot(data, function(snapshot) {
  // executed when the snapshot is created
  found = JSON.search(snapshot, '//item');  
});
  • Snapshot feature
var data = {
  // ...large JSON structure...
};

// Regular search
found = JSON.search(data, '//item');

var snapshot = Defiant.getSnapshot(data);
// Snapshot search - this is more than 100 times faster than 'regular search'
found = JSON.search(snapshot, '//item');
  • Simple search
var data = [
       { "x": 2, "y": 0 },
       { "x": 3, "y": 1 },
       { "x": 4, "y": 1 },
       { "x": 2, "y": 1 }
    ],
    res = JSON.search( data, '//*[ y > 0 ]' );

console.log( res );
// [{ x=3, y=1}, { x=4, y=1}, { x=2, y=1}]
  • XSLT Templating
<!-- Defiant template -->
<script type="defiant/xsl-template">
    <xsl:template name="books_template">
        <xsl:for-each select="//movie">
            <xsl:value-of select="title"/><br/>
        </xsl:for-each>
    </xsl:template>
</script>
 
<script type="text/javascript">
    var data = {
            "movie": [{"title": "The Usual Suspects"},
                      {"title": "Pulp Fiction"},
                      {"title": "Independence Day"}]
        },
        htm = Defiant.render('books_template', data);
    console.log(htm);
    // The Usual Suspects<br>Pulp Fiction<br>Independence Day<br>
</script>

###Update highlights

  • v1.2.6 As of this version, snapshots can be created with web workers - consequently the UI thread is not blocked when creating snapshots of large JSON structures.

  • v1.2.0 As of version 1.2.0, the snapshot feature was added. Using this feature, the performance of the search is increased by more than 100 times. Use 'snapshot search' when you are certain that the JSON structure hasn't been changed. If the structure changes, create a new snapshot and always make searches on the latest snapshot. The example below shows how it can be used.

Changelog

  • 1.3.8 Handling null value in arrays
  • 1.3.7 Safari / VueJS related bugfix
  • 1.3.6 Fixed bug in gulp file
  • 1.3.5 Handling special occasion of 'null' in array
  • 1.3.4 Syncing up package version with release version
  • 1.3.3 Safari handles "XSLTProcessor" - adapting
  • 1.3.2 Throws error if "transformNode" is not supported
  • 1.3.1 Fixing MSIE11 detection
  • 1.3.0 Zero values threw error in "match tracer"
  • 1.2.9 Handling '\r\n' in string (throws error)
  • 1.2.8 Automatically case insensitive - global regular expression
  • 1.2.7 JSON data containing functions will throw error
  • 1.2.6 Snapshot can be created with web worker (x10.js)
  • 1.2.5 Bugfix related to not() preceding 'contains'-method
  • 1.2.4 UI-related bugg fix
  • 1.2.2 The XPath method 'contains' is automatically case insensitive
  • 1.2.0 Added snapshot search feature

defiant.js's People

Contributors

blackwicked avatar ds82 avatar hbi99 avatar yehya avatar

Watchers

 avatar  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.