Pythonic library for JavaScript


Often in JavaScript you'll find yourself thinking "why is this so hard?". The answer is not immediately obvious. In my opinion JavaScript is a fairly mediocre language with a pretty nice object model but is severely hampered by an underwhelming standard library. The problem largely disappears when you use jQuery but there are still general programming tasks which are needlessly difficult (like trimming or formatting a string). I've always thought Python is the language to use if you want to get something done so implementing a generous set of Python's API seemed an obvious answer to the question "how can I make it easier?".

Some of these functions do just wrap native JavaScript methods but some which you might think are simply wrappers are in fact more useful: e.g. try calling Math.max with an array. You can't, it's a variable argument list, which is a pain to build at run-time. Another strange one is String.split(); in IE this is completely broken, but all the other major browsers agree that '1,2,3'.split(',', 1) should return ['1'] and drop the rest of the string. Python thinks that it should return ['1','2,3'], which is more sensible.


pythonic.js is now hosted along with my other smallish JavaScript projects in a public Mercurial repository.

You can either clone the repository:

hg clone javascript-stuff

Or download the old fashioned way:

This has been tested [] in IE6-9, Firefox and Chrome and Konqueror (note that Konqueror has a minor bug with pysplitlines not detecting trailing empty lines, it's not obvious why).

Library Contents

A complete list of what this library provides:A complete function list follows. Consult the Python docs for more info on any particular one, this is just a contents list.

Note that Python's idea of 'None' (a lot like NULL, but it's actually a singleton object) is sort of equated interally with the JavaScript: (typeof(x) == 'undefined' || x == null). So if you want to pass a default argument which you have to define, it's easiest and neatest to pass 'null' rather than undefined.

Global Functions

RegExp Methods

Array Methods

String Methods

Last edited by mark at 16:33:24 31/01/11 -- "Page creation"

Page loaded in 0.075s