A JavaScript CRC32

Here is a micro JavaScript library for computing the CRC32 of a string.

After importing the crc32.js file, a function with this signature

will be available in the global scope.

If you supply only the str (which is mandatory), it returns the CRC32 code of that string (using 0 as a start, which is a de facto standard), and if you also supply the crc, it will use that number as a start. This comes in handy for chaining crc32 calls, maybe in a loop, in fact:

A JavaScript heredoc

JavaScript lacks PHP’s concept of heredoc:

Another way to delimit strings is by using heredoc syntax (<<<). One should provide an identifier after <<<, then the string, and then the same identifier to close the quotation.

Here is a little function that can be used to emulate it. But it only works in IE (sigh). If you know how to do it also in Firefox, I’ll be very glad to update this post.

Really it should be called herescript, because fn (the mandatory argument) is a function declaration, so the text must be syntactically correct JavaScript code, not just plain text. This feature is very convenient when I want to defer the execution of some statements while having them highlighted by my editor, but it bothers a little when I want just a plain text.

To solve this, the function also accepts the optional arguments from and top. If I supply two numbers, the heredoc text will be all the lines between from included and top excluded. In this case I can supply also an optional separator to put in between lines. If I supply two strings, the heredoc text will be all the characters between from and top, both excluded.

myHereDoc1: when the content is a script

myHereDoc2: when the content is text, delimited by line number

myHereDoc3: when the content is text, delimited by substrings

To try all these examples together, we can write this: {[.example-standard /enzymes/chili-js.php]}

to get this:

But cha-chaaa, here goes a bonus. Using a heredoc like this:

the same result is achieved, but the javascript code is much cleaner:

jQuery: API documentation /4

It was the beginning of October when I posted here three articles about this subject.

Yesterday I updated my experimental jQuery interface, re-introducing the A through Z index, and making it crossbrowser for IE, FF, and Opera (this one could be better). This is the official xml data seen through my interface.

There are empty spaces, because my proposal was about making the xml data richer than actually is. And there is still work to do for making it more robust and flexible.

For example, the next thing to add will be a list of keywords at the bottom. Clicking any of them, the function list will hide the functions that do not match that keyword. I’m speaking of keywords here rather than categories, because there exist other partitions as much interesting as categories, like “deprecated” for example, or “chainable”, or “multiplex” (acts upon a collection), or “stacked” (changes a collection) and so on.