User:Bluedeck/serve/pare-min.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
var Pare_str = (function(){
"use strict";
function Pare_str(pare_string, config)
{
this.str = pare_string;
this.left = "(";
this.delim = ":";
this.right = ")";
if(typeof config !== "string")
config = String(config);
if(pare_string.length > 6 && /[@#%][sS][eE][tT]/.test(pare_string.slice(0,4)) && config.indexOf("ignore-set") === -1)
{
this.left = pare_string[4];
this.delim = pare_string[5];
this.right = pare_string[6];
if(this.left === this.right || this.left === this.delim || this.right == this.delim)
{
throw new SyntaxError("Pound set statement has repetitive characters. E.g. '#set|:|' is illegal.")
}
}
}
Pare_str.prototype.find = function(lookup_key)
{
lookup_key = this.left + lookup_key + this.delim;
if(this.str.indexOf(lookup_key) === -1)
{
return null;
}
else
{
return this.str.split(lookup_key)[1].split(this.right)[0];
}
};
Pare_str.prototype.new = function(new_key, new_value) // will not check for existance
{
if (new_key.indexOf(this.left) !== -1 || new_key.indexOf(this.right) !== -1 || new_key.indexOf(this.delim) !== -1 ||
new_value.indexOf(this.left) !== -1 || new_value.indexOf(this.right) !== -1)
{
throw new Error("Pare_str: Illegal key or value. Key mustn't have any bound or delimiter, value mustn't have any bound.");
}
this.str = this.left + new_key + this.delim + new_value + this.right + this.str;
return this;
};
Pare_str.prototype.update = function(lookup_key, new_value) // will create if not exist
{
if(this.find(lookup_key) === null)
{
this.new(lookup_key, new_value);
}
else
{
var new_str = this.str.split(this.left + lookup_key + this.delim);
new_str[1] = new_str[1].split(this.right);
new_str[1][0] = new_value;
new_str[1] = new_str[1].join(this.right);
new_str = new_str.join(this.left + lookup_key + this.delim);
this.str = new_str;
}
return this;
};
function intep(celldata)
{
if(/^\$[fF]alse$/.test(celldata))
return false;
else if(/^\$[tT]rue$/.test(celldata))
return true;
else if(/^\$-?(0*|[1-9][0-9]*)(|.[0-9]+)(|[eE](|\+|-)[0-9]*)$/.test(celldata))
return parseFloat(celldata.slice(1));
else if(/^\$[nN](ull|one|il)$/.test(celldata))
return null;
else
return celldata;
}
Pare_str.prototype.intep = function(lookup_key)
{
return intep(this.find(lookup_key));
};
return Pare_str;
})();