-
-
Save anonymous/4391929 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var prime = require('prime') | |
var ghost = require('prime/util/ghost') | |
var typeOf = require('prime/util/type') | |
var shells = { | |
"string" : require("prime/types/string"), | |
"number" : require("prime/types/number"), | |
"array" : require("prime/collection/list"), | |
"object" : require("prime/collection/hash"), | |
//"date" : require("prime/es5/date"), | |
"function" : require("prime/es5/function"), | |
"regexp" : require("prime/es5/regexp") | |
} | |
module.exports = function(typeCheck){ | |
if (!typeCheck) typeCheck = typeOf | |
var _ = function(self){ | |
if (self == null || self instanceof lodash) return self | |
var l = _[typeCheck(self)] | |
return l ? new l(self) : self | |
} | |
var lodash = prime({ | |
mutator: function(key, method){ | |
this.prototype[key] = function(){ | |
// this is basically the only difference, ghost wraps it in ƒ while _ directly returns the result. | |
return method.apply(this.valueOf(), arguments) | |
} | |
} | |
}) | |
_.chain = function(obj){ | |
return ghost(obj); | |
} | |
_.register = function(type, shell){ | |
var l = _[type] = prime({ | |
inherits: lodash, | |
constructor: function(self){ | |
if (!this || this.constructor !== l) return new l(self) | |
this.valueOf = function(){ | |
return self | |
} | |
} | |
}) | |
l.implement(shell.prototype) | |
} | |
for (var type in shells) _.register(type, shells[type]) | |
return _ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment