7

I'm wondering if such a library exists, where the library contains only a collection of common utility functions such as trim, indexOf (for arrays), map, each, typeOf and so on...

I'm aware that jQuery provides some of the functions I listed above, but I'm looking for something that is designed purely for this (I really don't need jQuery on the server-side running node.js for instance, nor do I want to depend on it if I'm writing a non-jQuery-related JavaScript library). I've recently begun collecting an assortment of these functions for future copy/pasting, but my guess is that there are many others that I won't even know to look for, or think of using, unless someone presents them to me.

Kara
  • 6,115
  • 16
  • 50
  • 57
David Tang
  • 92,262
  • 30
  • 167
  • 149
  • The core Dojo library would also be helpful. I recommend you start using either jQuery, Dojo or other library of the kind. There's a good chance you end up using them anyway at some point. – Marcelo Jan 13 '11 at 14:40
  • There's a zillion. Enough that this is a nonconstructive question. – djechlin May 02 '13 at 18:31

5 Answers5

8

I'm fond of underscore.js; it doesn't provide string utilities such as trim; it's focused on object-oriented and functional utilities, including all of the other things you mention. Another nice thing about it is that it doesn't reference the DOM at all, so it's useful for javascript programming that isn't web-based or DOM related.

Jacob Mattison
  • 50,258
  • 9
  • 107
  • 126
4

The functions you mention are all standard in ECMAScript 5. And this library implements them in such a way that you can use them in older browsers/JavaScript versions as well, in a way that will be compatible when your environment catches up with the standard:

https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js

Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
1

Boiler.js is an up and coming utility library that offers many useful JavaScript utilities and is a direct competitor with Underscore.js.

Xaxis
  • 1,935
  • 15
  • 17
0

jQuery provides all of those and many more, you would be better off just using it.

jQuery can sit side-by-side with other frameworks, so can be independent if another framework is present.

See: jQuery Utilities Documentation

Orbling
  • 20,413
  • 3
  • 53
  • 64
  • 1
    Wasn't the question looking for something not related to JQuery? But you are right it is independent :) – Aim Kai Jan 13 '11 at 14:38
  • @Aim Kai: It was, yes. But I thought I would state that this may well be the best alternative anyway. ;-) – Orbling Jan 13 '11 at 16:49
0

Javascript itself has many of these functions built into the basic types. Before building your own, perhaps a copy of JavaScript: The Definitive Guide, focusing on the API reference in the back, would do you some solid good.

After that investigate frameworks, or at least being looking into how you can create your own framework for your functions (as opposed to copying and pasting). Here the module pattern would be helpful to you.

justkt
  • 14,610
  • 8
  • 42
  • 62