I have done this before and can talk a little about the experience of writing covers for the library / toolkit.
The plan was to switch from Prototype to another library. Dojo was the first choice, but at that time I was not sure that the library would move everything to (and all I mean ~ 5 MB Prototype-happy JS). Therefore, based on the world of clean interfaces, I was set to record one of Prototype and Dojo; an amazing interface that would disconnect from the Dojo a breeze, if it was really necessary.
It was a mistake that cost a lot of time and effort for several reasons. The first is that although two libraries can provide the same functionality, (a) their API will almost always be different, and most importantly (b) how you program in the same library will be different.
To demonstrate, let's take something in common, like adding a class name:
// Prototype $("target").addClassName('highlighted'); // Dojo dojo.addClass("target", "highlighted"); // jQuery $("target").addClass("highlighted"); // MooTools $('target').set('class', 'highlighted');
Still pretty straightforward. Let's complicate a bit:
// Prototype Element.addClassName('target', 'highlighted selected'); // Dojo dojo.addClass("target", ["highlighted", "selected"]); // jQuery $("target").addClass(function() { return 'highlighted selected'; }); // MooTools $("target").set({ "class": "highlighted selected" });
Now, after choosing the interface for your addClass version, you have two options: (1) code for the lowest common denominator or (2) implement all disjoint library functions.
If you go 1st, you will lose the “personality” / best qualities of each library. If you go from No. 2, your addClass code will be 4 times larger than the one provided by any of the libraries, because, for example, when Dojo is enabled, you will need to write code for the function as the first parameter (jQuery) and Object as the first parameter (MooTools).
Therefore, although it is theoretically possible, it is impractical, but it is a very good way to understand the intricacies of libraries there.