Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
202 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module.exports = function(grunt) { | ||
|
||
// Configuration | ||
grunt.initConfig({ | ||
|
||
jshint: { | ||
files: ["*.js"], | ||
|
||
options: { | ||
// Enforcing | ||
bitwise: true, | ||
camelcase: true, | ||
curly: true, | ||
eqeqeq: true, | ||
immed: true, | ||
latedef: true, | ||
newcap: true, | ||
noarg: true, | ||
noempty: true, | ||
nonew: true, | ||
quotmark: true, | ||
undef: true, | ||
unused: true, | ||
|
||
// Environment | ||
node: true | ||
} | ||
}, | ||
|
||
uglify: { | ||
minify: { | ||
src: "dist/basespace.js", | ||
dest: "dist/basespace.min.js" | ||
} | ||
}, | ||
|
||
umd: { | ||
dist: { | ||
template: "unit", | ||
src: "index.js", | ||
dest: "dist/basespace.js", | ||
objectToExport: "namespace", | ||
globalAlias: "basespace" | ||
} | ||
} | ||
|
||
}); | ||
|
||
// Plugins | ||
grunt.loadNpmTasks("grunt-contrib-jshint"); | ||
grunt.loadNpmTasks("grunt-contrib-uglify"); | ||
grunt.loadNpmTasks("grunt-umd"); | ||
|
||
// Tasks | ||
grunt.registerTask("build", ["umd", "uglify"]); | ||
grunt.registerTask("default", ["jshint"]); | ||
grunt.registerTask("all", ["jshint", "build"]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### 0.0.2 / 2013-09-04 | ||
|
||
* add `Gruntfile` | ||
* add UMD distribution `dist/basespace.js` and `dist/basespace.min.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
(function(root, factory) { | ||
if(typeof exports === 'object') { | ||
module.exports = factory(require, exports, module); | ||
} | ||
else if(typeof define === 'function' && define.amd) { | ||
define(['require', 'exports', 'module'], factory); | ||
} | ||
else { | ||
var req = function(id) {return root[id];}, | ||
exp = root, | ||
mod = {exports: exp}; | ||
root.basespace = factory(req, exp, mod); | ||
} | ||
}(this, function(require, exports, module) { | ||
/** | ||
* @module basespace | ||
*/ | ||
|
||
/** | ||
* Create specified namespaces if they do not exist. | ||
* | ||
* @param {Array|String} names | ||
* Namespaces that should be created. | ||
* @param {Object} [context=global] | ||
* An object inside of which namespaces will be created. Global object (i.e. window in browser) by default. | ||
* @param {Any} [value={}] | ||
* A value that will be assigned to a final field. <code>{}</code> by default. | ||
* @return | ||
* The value for the last name. <code>undefined</code> by default (if no names were passed). | ||
* @alias module:basespace | ||
*/ | ||
function namespace(names, context, value) { | ||
/*jshint laxbreak:true*/ | ||
var bLastValue = arguments.length > 2, | ||
namePart, nI, nL, obj, sName, space; | ||
if (names) { | ||
if (typeof names === "string") { | ||
names = [names]; | ||
} | ||
if (! context) { | ||
context = (function() {return this;}).call(null); | ||
} | ||
if (! bLastValue) { | ||
value = {}; | ||
} | ||
for (nI = 0, nL = names.length; nI < nL; nI++) { | ||
namePart = names[nI].split("."); | ||
space = context; | ||
while (namePart.length) { | ||
sName = namePart.shift(); | ||
if (namePart.length) { | ||
obj = space[sName]; | ||
if (! obj || (typeof obj !== "object" && typeof obj !== "function")) { | ||
obj = space[sName] = {}; | ||
} | ||
space = obj; | ||
} | ||
else { | ||
space = ! (sName in space) || bLastValue | ||
? (space[sName] = value) | ||
: space[sName]; | ||
} | ||
} | ||
} | ||
} | ||
return space; | ||
} | ||
|
||
/** | ||
* Create specified namespaces inside <code>this</code> object if they do not exist. | ||
* <br> | ||
* This function is a "wrap" for the following code: | ||
* <code><pre> | ||
* var namespace = require("basespace"); | ||
* namespace(arguments, this); | ||
* </pre></code> | ||
* It can be transferred to an object to use as a method. | ||
* | ||
* @param {...String} name | ||
* A namespace that should be created. | ||
* @return | ||
* The value for the last name. <code>undefined</code> by default (if no names were passed). | ||
*/ | ||
namespace.space = function(name) { | ||
/*jshint unused:vars*/ | ||
return namespace(arguments, this); | ||
}; | ||
|
||
module.exports = namespace; | ||
|
||
return namespace; | ||
})); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters