Sugar
Sugar copied to clipboard
Simplify modules like Array to not export the global object.
Sugar currently allows requiring by "module", however all modules return the global object:
require('sugar');
require('sugar/array');
require('sugar/enumerable');
All of the above return simply the root Sugar
object. The reason for this is that modules are simply packages for convenience, and may define methods for different types. For example, the enumerable
package defines methods on both Array
and Object
that share common code. Other modules are es5
, es6
, and es7
, which define polyfills, as well as inflections
and language
, which define extra methods on String
that are complex, and not desirable in most contexts.
The proposal here is to simplify this so that require('sugar/array')
would return Sugar.Array
instead of Sugar
. This would unfortunately mean that sugar/enumerable
would either have to not exist any more, or continue to return the global Sugar
object, which could be confusing. Alternatively, modules could continue to exist, but simply as their npm package names (sugar-enumerable
, etc), and just be collections of like methods, but no longer carry any meaning in Sugar itself.
I'm considering different approaches and open to input here.