As part of my research on design interfaces, I recently started to work on a personal project that has got me really busy lately. I don’t want to say much, sufficient to disclose that it is a JavaScript library, it involves graphics on canvas, and if I manage to bring it as far as I wish, it is going to be amazing (ehem, ehem…)
Nevertheless, I soon realized it was a pretty ambitious project for several reasons, not only in functional terms, but also in developing all the necessary support that a fully developed code library needs: a carefully designed API, unit tests, minification, documentation, etc… And since it was to be my first attempt at trying to make other people’s lives easier, I thought I may ease mine as well by warming up with a reduced scope enterprise.
During the development of insert library nickname here
, I found myself repeatedly performing type check on primitive objects, equality comparators, etc. Since JavaScript is such a weakly-typed language, these checks can be really tedious and expensive to perform, with the code getting clunkier and clunkier. For example, the appropriate way of checking if myObj
is a JavaScript object would be:
Object.prototype.toString.call(myObj) === '[object Object]'
I couldn’t help wander if this process could be optimized and wrapped into a cleaner form, easier to remember and leaner to express.
All these thoughts lead to the creation of ontology.js, a mighty, yet lightweight library to inquire about the nature of being in JavaScript objects. It provides a clean API of chained lexical methods for data type checks, property checks and equality comparators. With ontology.js the above check would look like this:
is(myObj).type('object'); // true or false
Ontology.js is probably nothing really innovative. There are other libraries out there that perform similar operations, and potentially in a more optimized way. But for me, it served as a testbench for many different aspects of designing and developing a code library to its ultimate consequences. It was a fantastic exercise in designing an abstract, yet coherent lexical interface for other users that provides not only intuitiveness, but ultimately anticipation (a topic I am increasingly interested in). It was also interesting to explore chain methods in JavaScript, and the details involved in their implementation. Unit test development also proved really helpful, although rather boring and time consuming. And finally, packaging, minification and distribution releases… check!
You can read more about ontology.js in the project page, or fork the project on github. Enjoy!