Underscore.string 2.0 Release
Why 2.0?
In this version we moved Underscore.string library to separate namespace _.string for solve name conflicts with Underscore library. There are some functions that available in both libraries, for ex. include and reverse. In 1.1.6 and lower Underscore.string provided includes function, but we decided that two function include and (includes or includeString) in one namespace and with same functionality but one function for collections another for strings, it’s a little bit ugly.
Do we always need to write _.string?
Nope. Underscore.string provide exports function _.string.exports(), this function returns only non-conflict functions and we can mix in these functions to Underscore scope if you want.
1 2 3 4 5 6 7 8 9 10 11 |
|
Problems
We lose two things for include and reverse methods from _.string:
- Calls like
_('foobar').include('bar')
aren’t available; - Chaining isn’t available too.
But if you need this functionality you can create aliases for conflict functions which will be convnient for you.
1 2 3 4 5 6 7 |
|
Standalone Usage
If you are using Underscore.string without Underscore. You also have .string namespace for it. And current version number you can find through VERSION constant .string.VERSION. If you want you can just reassign _ variable with _.string
1 2 3 |
|
Node.js Installation
1
|
|
Standalone usage:
1
|
|
Integrate with Underscore.js:
I recommend you this way for integrating with Underscore.js:
1 2 3 4 5 6 7 8 9 10 |
|
Upgrade
In new version function includes has been removed, you should replace this function by .str.include or create alias .includes = _.str.include and all will work fine.