DailyJS

DailyJS

The JavaScript blog.


Tagutilities
Featured

libraries ui ajax utilities dom http rest

Curl Converter, aja.js, sneakpeek

Posted on .

Curl Converter

Chrome's "Copy as cURL" menu item is useful, but what if you want to duplicate the same request with Node? Curl Converter (GitHub: NickCarneiro/curlconverter, License: MIT, npm: curlconverter) by Nick Carneiro can convert between cURL syntax and Node's popular request module. It also supports Python, and can be installed with npm.

aja.js

aja.js (Bower: aja, npm: aja, License: MIT) by Bertrand Chevrier is an Ajax library that supports JSON and JSONP. It can be used to load large chunks of HTML or JSON, and can be installed with npm or Bower.

The API is fluent, so it can be used as a REST client like this:

aja()  
  .method('GET')
  .url('/api/customer')
  .data({ firstname: 'John Romuald' })
  .on('200', function(response) {})
  .go();

It also supports some DOM manipulation:

aja()  
  .url('/views/page.html')
  .into('.container')
  .go();

It comes with tests that can be run with Grunt, and the readme has more examples for things like posting data.

sneakpeek

If you're looking for a library to hide the header when the page is scrolled, then sneakpeek (GitHub: antris/sneakpeek, License: MIT, npm: sneakpeek) is nice because it's small, installable with npm, and has no external dependencies.

It's a bit like headroom.js, but easier to use with Browserify.

Featured

language utilities

Tracer

Posted on .

I just finished reading about Angus Croll's
tracer utility -- a tiny pure JavaScript method tracer. It traverses prototype
chains and wraps each method in a new function that calls the tracer's
code.

To understand this, remember that functions on objects can be iterated
over. Also recall that functions in JavaScript are first class objects,
which means they can be decorated with properties. Combining these two
facts allows object methods to be iterated over and safely modified to
call external code.

This can even be done recursively:

tracer.traceAll(jQuery, true)
>> tracing init
>> tracing size
>> tracing toArray
// ...

The source code is in the article: A tracer utility in
2kb
.