Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
101 lines (86 sloc) 2.21 KB
String.prototype.last = function() {
return this.substring(this.length-1)
}
String.prototype.first = function() {
return this.substring(0,1)
}
String.prototype.decode = function() {
return unescape(this)
}
String.prototype.encode = function() {
return escape(this)
}
String.prototype.append = function() {
var retval = this
for (var J = 0; J < arguments.length; ++J) retval += arguments[J].toString()
return retval
}
String.prototype.contains = function(S) {
return 0 <= this.indexOf(S)
}
String.prototype.name = function() {
return this
}
String.prototype.eval = function() {
var R = false
var Args = Array.prototype.slice.apply(arguments,[0])
var F = Function.prototype.constructor.apply(window,[ 'return ('.append(this,')') ])
try {
R = F.apply(window,Args)
} catch(E) {
R = E
}
return R
}
String.prototype.params = function() {
var m = /\(([^)]*)\)/.exec(this);
return m ? m[1].split(',').every(function(v) { return eval(v) }) : [];
}
String.prototype.deparameterized = function() {
var m = /(\w+)\(/.exec(this.toString());
return m ? m[1] : this;
}
String.prototype.isCall = function() {
return /\w+\([^)]*\)$/.exec(this);
}
String.prototype.use = function() {
var I = this
var Modules = []
Modules.push.apply(Modules,arguments)
var M = Modules.shift()
var Url = I.append(M)
var F = function(T) {
if (!T) console.error('Failed to load '.append(Url))
try {
Function.prototype.constructor.apply(window,[T])()
} catch(E) {
console.error('Load error: '.append(E,':',T))
}
if (Modules.length > 0 ) {
var M = modules.shift()
var Url = I.append(M)
console.error(M)
Url.get(F)
}
}
Url.get(F)
return this
}
String.prototype.request = function(M,F,D) {
var R = XMLHttpRequest ? new XMLHttpRequest(): _doc.createRequest()
R.onreadystatechange = function () {
if (this.readyState != 4 || typeof(F) != "function") return false
if (this.status == 404) F(null)
if (this.status == 200) F(this.responseText)
}
R.open(M,this,true)
R.setRequestHeader('Content-Type','application/json')
R.send(D ? D : '')
return this
}
String.prototype.get = function(F) {
return this.request("GET",F)
}
String.prototype.post = function(D,F) {
return this.request("POST",F,D)
}