gruntjs/grunt-contrib-lib — pull request #1 by lazd (2012-09-14 04:30:05+00:00)
Title: Added getNamespaceDeclaration for template tasks and unit tests

getNamespaceDeclaration will take a namespace in dot notation and return the corresponding non-destructive declaration for the namespace, as well as the namespace in bracket notation. Namespace parts are safely escaped using JSON.stringify.

That is:

helpers.getNamespaceDeclaration('GUI.Templates.Main');

Returns:

{
namespace: 'this["GUI"]["Templates"]["Main"]',
declaration: 'this["GUI"] = this["GUI"] || {};' +
'this["GUI"]["Templates"] = this["GUI"]["Templates"] || {};' +
'this["GUI"]["Templates"]["Main"] = this["GUI"]["Templates"]["Main"] || {};'
}

Special cases
* If `this` is provided, no declaration is returned and `this` is returned as the namespace.
* Providing `this.MyNamespace` produces the same output as providing `MyNamespace`.