Tuesday, October 25th, 2005

MochiKit 1.0 Released

Category: Toolkit

<p>MockiKit is a quality JavaScript library like Dojo and Prototype/Scriptaculous.

Bob Ippolito has blessed the 1.0 release, which offers a few updates:

  • MochiKit.Async: MochiKit.Async’s sendXMLHttpRequest and anything that uses it will now call the errback chain under ANY error. This means that if the web server is down or if the user has gone to another page or started closing the browser, then you’ll get an error. From what I’ve seen, the error under both of these conditions is going to be an XMLHttpRequestError with undefined status. That’s right, you won’t be able to discern one from the other, so don’t do anything obtrusive (like an alert) if you see an XMLHttpRequestError in your errback! The best thing to do is just log or ignore these errors.
  • MochiKit.Base: has a new updatetree(self, obj[, ...]) function to update an object tree, in order to support new MochiKit.DOM updateNodeAttributes functionality (below).
  • MochiKit.DOM: updateNodeAttributes now uses updatetree if it sees object values, so you can now set style attributes inline:

    var div = DIV({“style”: {“display”: “block”}}, “div contents here…”);

  • MochiKit.DateTime: isoTimestamp now uses one of the ugliest regexps I’ve ever written in order to parse ANY ISO 8601 timestamp. It doesn’t attempt to validate, so it will accept a large subset of incorrectly formatted ISO 8601-ish timestamps. RegExps in JavaScript are so bad that I had to write MochiRegExp to get this right!
  • MochiKit.Format: New functions have been added:

    truncToFixed(aNumber, precision): Truncate a number to the given precision (does NOT round).

    roundToFixed(aNumber, precision): Round a number to the given precision (because Safari’s Number methods are mostly broken)

    numberFormatter(pattern, placeholder=”", locale=”default”)

    formatLocale(locale=”default”) brings Java style number formatting to JavaScript:

    assert( percentFormat(1.234567) == “123.46%” );
    assert( numberFormatter(“###,###%”)(125) == “12,500%” );
    assert( numberFormatter(“##.000″)(1.25) == “1.250″ );

There are also new examples for you to peruse:

Interpreter:

An interactive JavaScript interpreter, much like python when run with no arguments. Very useful!

MochiRegExp:

A “live” RegExp explorer, good for debugging those gnarly
JavaScript RegExps. RegExps without named groups or a verbose flag
suck, you need this.

MochiKit

Related Content:

Posted by Dion Almaer at 12:20 pm
2 Comments

+++--
3.6 rating from 5 votes

2 Comments »

Comments feed

More interesting is that the interpreter allows you to throw in arbitrary DOM objects:
http://flickr.com/photos/35034349324@N01/55881084/

Comment by Bob Ippolito — October 25, 2005

I blogged about this:

http://jjinux.blogspot.com/2005/10/javascript-quickies.html

Comment by Shannon -jj Behrens — October 25, 2005

Leave a comment

You must be logged in to post a comment.