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

dt-server

v0.0.3

Published

Server-side processing implemention for datatables

Downloads

4

Readme

dt-server - A wrapper around a datatable server side processing

Build Status via Travis CI Coverage Status

Installation

npm install dt-server

Dependencies

None

Example Usage (Express)

There are four main objects in this project.

DtRequest

  • Wraps the raw query from a datatable with added helper functionality

DtResponse

  • Wraps an adapter - a SQLite adapter is provided - and generates a valid response

DtServer

  • Handles creation of the above objects and returns the response

Adapter

  • A class that implements the interface seen below in the DtSql3 Object
var DtServer = require('dt-server')
var db       = require('MockSql3DB').Database

router.get('/dtsql3', function(req, res, next) {  

  var dtServer = DtServer('sql3', db, {
    response: {
      format: 'object-array'
    }
  })

  dtServer.get(req.query,'USERS')
  .then(function(results) {
    res.status(200).json(results)
  })
  .catch(function(err) {
    res.status(400).json(err)
  })
})

API

  • DtServer([adapter], [options])

    • [adapter] Adapter for a database I.E. DtSql3 wraps the SQLite database
    • [options] Custom options
  • DtServer.get([request], [model], (optional)[params])

    • [request] Datatable JSON request object
    • [model] Model to get from the database
    • [params] Optional database parameters
    • returns {Promise}
  • DtSql3([Database])

    • [Database] Database object`
  • DtSql3.get([dtRequest], [model], (optional)[params])

    • [dtRequest] DtRequest object`
    • [model] Model to get from the database`
    • [params] Optional database parameters`
    • returns{Promise}`

Extending

Implementing the interface seen in DtSql3 will allow you to pass that adapter as you would the DtSql3 object

Available Options

Defaults

{
  request: {
    excludeRegex: 'true' //'true'|'false'
    filter: function(str, regex) {
      return str
    },
    validate: 'true' //'true'|'false'
  },

  response: {
    format: 'object-array', //object-array, value-array,
    formatData: undefined, //Array function(data, format) { }
    validate: 'false', 'true'|'false'
  }
}

Pass an object with one, or more of these options to override the defaults

  • request.exlcudeRegex removes search columns using regex

  • request.filter A function that augments incoming search strings

  • request.validate Flag to validate the datatable JSON request object

  • response.format Format of the response data from an adapter

  • Example Formats

    • object-array => [{name: 'a', address: 'b'}, ...]
    • value-array => [['a', 'b'], ...]
  • request.formatData Custom data formatting function used in-place of the default format function

  • request.validate Flag to validate JSON response object

License

MIT