Created
December 15, 2010 18:59
-
-
Save orlin/742422 to your computer and use it in GitHub Desktop.
underscore.js with strings and other mixins (a node.js module)
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
define (require, exports, module) -> | |
_ = require("underscore") | |
_.mixin require("underscore.string") | |
_.mixin | |
# Converts the arguments list to an Array | |
aToArr: (list) -> | |
if _.isArguments(list) | |
_.toArray(list).slice(0) | |
else | |
console.log "aToArr called with these non-arguments: #{list}" | |
[list] | |
# Merges all from a list of objects in return for a single one | |
# sequentially overwrites keys (with disrespect for nested values) | |
allFurther: (into, rest...) -> | |
# _.each rest, (item) -> _.map item, (val, key) -> into[key] = val | |
for item in rest | |
for key, val of item | |
into[key] = val | |
into | |
module.exports = _ |
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
var __slice = Array.prototype.slice; | |
define(function(require, exports, module) { | |
var _; | |
_ = require("underscore"); | |
_.mixin(require("underscore.string")); | |
_.mixin({ | |
aToArr: function(list) { | |
if (_.isArguments(list)) { | |
return _.toArray(list).slice(0); | |
} else { | |
console.log("aToArr called with these non-arguments: " + list); | |
return [list]; | |
} | |
}, | |
allFurther: function() { | |
var into, item, key, rest, val, _i, _len; | |
into = arguments[0], rest = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | |
for (_i = 0, _len = rest.length; _i < _len; _i++) { | |
item = rest[_i]; | |
for (key in item) { | |
val = item[key]; | |
into[key] = val; | |
} | |
} | |
return into; | |
} | |
}); | |
return module.exports = _; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment