npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

defiant

v1.4.5

Published

Search JSON structures plus smart templating with XSLT and XPath.

Downloads

318

Readme

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

:point_right: Join the chat at https://gitter.im/hbi99/defiantjs.com Chat with Defiant.js users

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

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