Comparing version 1.5.15 to 1.5.16
{ | ||
"name": "markup-js", | ||
"version": "1.5.15", | ||
"version": "1.5.16", | ||
"description": "Markup.js - Powerful JavaScript Templates", | ||
@@ -24,2 +24,4 @@ "homepage": "https://github.com/adammark/Markup.js", | ||
}, | ||
"main": "./src/markup.js", | ||
"bin": "./src/markup.js", | ||
"bugs": { | ||
@@ -26,0 +28,0 @@ "url" : "https://github.com/adammark/Markup.js/issues" |
@@ -13,2 +13,6 @@ # Markup.js — Powerful JavaScript templates | ||
### Ports | ||
Markup.js is also available for [PHP][3]. | ||
## Usage | ||
@@ -1201,1 +1205,2 @@ | ||
[2]: https://github.com/adammark/Markup.js/issues | ||
[3]: https://github.com/mattparlane/Markup.php |
/* | ||
Markup.js v1.5.15: http://github.com/adammark/Markup.js | ||
Markup.js v1.5.16: http://github.com/adammark/Markup.js | ||
MIT License | ||
@@ -7,15 +7,15 @@ (c) 2011 - 2013 Adam Mark | ||
var Mark = { | ||
// templates to include, by name | ||
// Templates to include, by name. A template is a string. | ||
includes: {}, | ||
// global variables, by name | ||
// Global variables, by name. Global variables take precedence over context variables. | ||
globals: {}, | ||
// argument delimiter | ||
// The delimiter to use in pipe expressions, e.g. {{if color|like>red}}. | ||
delimiter: ">", | ||
// compact white space between HTML nodes | ||
// Collapse white space between HTML elements in the resulting string. | ||
compact: false, | ||
// return a copy of array A or copy array A into array B (returning B) | ||
// Shallow-copy an object. | ||
_copy: function (a, b) { | ||
@@ -31,3 +31,3 @@ b = b || []; | ||
// get the length of array A, or simply return A. see pipes, below | ||
// Get the value of a number or size of an array. This is a helper function for several pipes. | ||
_size: function (a) { | ||
@@ -37,3 +37,3 @@ return a instanceof Array ? a.length : (a || 0); | ||
// an object with an index (0...n-1) ("#") and size (n) ("##") | ||
// This object represents an iteration. It has an index and length. | ||
_iter: function (idx, size) { | ||
@@ -44,2 +44,4 @@ this.idx = idx; | ||
this.sign = "#"; | ||
// Print the index if "#" or the count if "##". | ||
this.toString = function () { | ||
@@ -50,14 +52,21 @@ return this.idx + this.sign.length - 1; | ||
// pipe an obj through filters. e.g. _pipe(123, ["add>10","times>5"]) | ||
_pipe: function (val, filters) { | ||
// get the first filter, e.g. "add>10" | ||
var filter = filters.shift(), parts, fn; | ||
// Pass a value through a series of pipe expressions, e.g. _pipe(123, ["add>10","times>5"]). | ||
_pipe: function (val, expressions) { | ||
var expression, parts, fn, result; | ||
if (filter) { | ||
parts = filter.split(this.delimiter); // e.g. ["add", "10"] | ||
fn = parts.shift().trim(); // e.g. "add" | ||
// If we have expressions, pull out the first one, e.g. "add>10". | ||
if ((expression = expressions.shift())) { | ||
// Split the expression into its component parts, e.g. ["add", "10"]. | ||
parts = expression.split(this.delimiter); | ||
// Pull out the function name, e.g. "add". | ||
fn = parts.shift().trim(); | ||
try { | ||
// apply the piped fn to val, then pipe again | ||
val = this._pipe(Mark.pipes[fn].apply(null, [val].concat(parts)), filters); | ||
// Run the function, e.g. add(123, 10) ... | ||
result = Mark.pipes[fn].apply(null, [val].concat(parts)); | ||
// ... then pipe again with remaining expressions. | ||
val = this._pipe(result, expressions); | ||
} | ||
@@ -68,7 +77,7 @@ catch (e) { | ||
// return the result of the piped value | ||
// Return the piped value. | ||
return val; | ||
}, | ||
// evaluate an array or object and process its child contents (if any) | ||
// TODO doc | ||
_eval: function (context, filters, child) { | ||
@@ -81,3 +90,2 @@ var result = this._pipe(context, filters), | ||
// if result is array, iterate | ||
if (result instanceof Array) { | ||
@@ -101,11 +109,12 @@ result = ""; | ||
// get "if" or "else" string from piped result | ||
_test: function (result, child, context, options) { | ||
var str = Mark.up(child, context, options).split(/\{\{\s*else\s*\}\}/), | ||
res = (result === false ? str[1] : str[0]); | ||
// Process the contents of an IF or IF/ELSE block. | ||
_test: function (bool, child, context, options) { | ||
// Process the child string, then split it into the IF and ELSE parts. | ||
var str = Mark.up(child, context, options).split(/\{\{\s*else\s*\}\}/); | ||
return Mark.up(res || "", context, options); | ||
// Return the IF or ELSE part. If no ELSE, return an empty string. | ||
return (bool === false ? str[1] : str[0]) || ""; | ||
}, | ||
// get the full extent of a block tag given a template and token (e.g. "if") | ||
// Determine the extent of a block expression, e.g. "{{foo}}...{{/foo}}" | ||
_bridge: function (tpl, tkn) { | ||
@@ -142,3 +151,3 @@ var exp = "{{\\s*" + tkn + "([^/}]+\\w*)?}}|{{/" + tkn + "\\s*}}", | ||
// return "{{abc}}xyz{{/abc}}" and "xyz" | ||
// Return the block, e.g. "{{foo}}bar{{/foo}}" and its child, e.g. "bar". | ||
return [tpl.substring(a, d), tpl.substring(b, c)]; | ||
@@ -148,3 +157,3 @@ } | ||
// fill a template string with context data. return transformed template | ||
// Inject a template string with contextual data and return a new string. | ||
Mark.up = function (template, context, options) { | ||
@@ -154,34 +163,33 @@ context = context || {}; | ||
// pattern matching any tag, e.g. "{{apples}}" and "{{/apples}}" | ||
// Match all tags like "{{...}}". | ||
var re = /\{\{(.+?)\}\}/g, | ||
// an array of tags | ||
// All tags in the template. | ||
tags = template.match(re) || [], | ||
// the tag being evaluated | ||
// The tag being evaluated, e.g. "{{hamster|dance}}". | ||
tag, | ||
// the string to evaluate, e.g. "hamster|dance" | ||
// The expression to evaluate inside the tag, e.g. "hamster|dance". | ||
prop, | ||
// the token that might be terminated by "{{/token}}" | ||
// The token itself, e.g. "hamster". | ||
token, | ||
// an array of filters, e.g. ["more>1", "less>2"] | ||
// An array of pipe expressions, e.g. ["more>1", "less>2"]. | ||
filters = [], | ||
// is the tag self-closing? e.g. "{{stuff/}}" | ||
// Does the tag close itself? e.g. "{{stuff/}}". | ||
selfy, | ||
// is the tag an "if" statement? | ||
// Is the tag an "if" statement? | ||
testy, | ||
// the string inside a block tag, e.g. "{{a}}...{{/a}}" | ||
// The contents of a block tag, e.g. "{{aa}}bb{{/aa}}" -> "bb". | ||
child, | ||
// a shortcut for context[prop] | ||
ctx, | ||
// the result string | ||
// The resulting string. | ||
result, | ||
// the global being evaluated, or undefined | ||
// The global variable being evaluated, or undefined. | ||
global, | ||
// the include being evaluated, or undefined | ||
// The included template being evaluated, or undefined. | ||
include, | ||
// iterator variable | ||
// A placeholder variable. | ||
ctx, | ||
// Iterators. | ||
i = 0, | ||
// iterator variable | ||
j = 0; | ||
// set custom pipes, if any | ||
// Set custom pipes, if provided. | ||
if (options.pipes) { | ||
@@ -191,3 +199,3 @@ this._copy(options.pipes, this.pipes); | ||
// set templates to include, if any | ||
// Set templates to include, if provided. | ||
if (options.includes) { | ||
@@ -197,3 +205,3 @@ this._copy(options.includes, this.includes); | ||
// set global variables, if any | ||
// Set global variables, if provided. | ||
if (options.globals) { | ||
@@ -203,3 +211,3 @@ this._copy(options.globals, this.globals); | ||
// override delimiter | ||
// Optionally override the delimiter. | ||
if (options.delimiter) { | ||
@@ -209,3 +217,3 @@ this.delimiter = options.delimiter; | ||
// compact HTML? | ||
// Optionally collapse white space. | ||
if (options.compact !== undefined) { | ||
@@ -215,3 +223,3 @@ this.compact = options.compact; | ||
// loop through tags, e.g. {{a}}, {{b}}, {{c}}, {{/c}} | ||
// Loop through tags, e.g. {{a}}, {{b}}, {{c}}, {{/c}}. | ||
while ((tag = tags[i++])) { | ||
@@ -232,3 +240,3 @@ result = undefined; | ||
// assume testing for empty | ||
// If an "if" statement without filters, assume "{{if foo|notempty}}" | ||
if (testy && !filters.length) { | ||
@@ -238,3 +246,3 @@ filters = ["notempty"]; | ||
// determine the full extent of a block tag and its child | ||
// Does the tag have a corresponding closing tag? If so, find it and move the cursor. | ||
if (!selfy && template.indexOf("{{/" + token) > -1) { | ||
@@ -247,3 +255,3 @@ result = this._bridge(template, token); | ||
// skip "else" tags. these will be pulled out in _test() | ||
// Skip "else" tags. These are pulled out in _test(). | ||
if (/^\{\{\s*else\s*\}\}$/.test(tag)) { | ||
@@ -253,3 +261,3 @@ continue; | ||
// tag refers to a global | ||
// Evaluating a global variable. | ||
else if ((global = this.globals[prop]) !== undefined) { | ||
@@ -259,3 +267,3 @@ result = this._eval(global, filters, child); | ||
// tag refers to included template | ||
// Evaluating an included template. | ||
else if ((include = this.includes[prop])) { | ||
@@ -268,3 +276,3 @@ if (include instanceof Function) { | ||
// tag refers to loop counter | ||
// Evaluating a loop counter ("#" or "##"). | ||
else if (prop.indexOf("#") > -1) { | ||
@@ -275,3 +283,3 @@ options.iter.sign = prop; | ||
// tag refers to current context | ||
// Evaluating the current context. | ||
else if (prop === ".") { | ||
@@ -281,3 +289,3 @@ result = this._pipe(context, filters); | ||
// tag has dot notation, e.g. "a.b.c" | ||
// Evaluating a variable with dot notation, e.g. "a.b.c" | ||
else if (prop.indexOf(".") > -1) { | ||
@@ -295,3 +303,3 @@ prop = prop.split("."); | ||
// get the actual context | ||
// Get the actual context | ||
while (ctx && j < prop.length) { | ||
@@ -304,3 +312,3 @@ ctx = ctx[prop[j++]]; | ||
// tag is otherwise testable | ||
// Evaluating an "if" statement. | ||
else if (testy) { | ||
@@ -310,3 +318,3 @@ result = this._pipe(ctx, filters); | ||
// context is an array. loop through it | ||
// Evaluating an array, which might be a block expression. | ||
else if (ctx instanceof Array) { | ||
@@ -316,3 +324,3 @@ result = this._eval(ctx, filters, child); | ||
// tag is a block, e.g. {{foo}}child{{/foo}} | ||
// Evaluating a block expression. | ||
else if (child) { | ||
@@ -322,3 +330,3 @@ result = ctx ? Mark.up(child, ctx) : undefined; | ||
// else all others | ||
// Evaluating anything else. | ||
else if (context.hasOwnProperty(prop)) { | ||
@@ -328,3 +336,3 @@ result = this._pipe(ctx, filters); | ||
// resolve "if" statements | ||
// Evaluating an "if" statement. | ||
if (testy) { | ||
@@ -334,3 +342,3 @@ result = this._test(result, child, context, options); | ||
// replace the tag, e.g. "{{name}}", with the result, e.g. "Adam" | ||
// Replace the tag, e.g. "{{name}}", with the result, e.g. "Adam". | ||
template = template.replace(tag, result === undefined ? "???" : result); | ||
@@ -342,3 +350,3 @@ } | ||
// "out of the box" pipes. see README | ||
// Freebie pipes. See usage in README.md | ||
Mark.pipes = { | ||
@@ -485,3 +493,3 @@ empty: function (obj) { | ||
// shim | ||
// Shim for IE. | ||
if (typeof String.prototype.trim !== "function") { | ||
@@ -493,7 +501,7 @@ String.prototype.trim = function() { | ||
// export | ||
// Export for Node.js and AMD. | ||
if (typeof module !== "undefined" && module.exports) { | ||
module.exports = Mark; | ||
} | ||
else if (typeof define !== "undefined") { | ||
else if (typeof define === "function" && define.amd) { | ||
define(function() { | ||
@@ -500,0 +508,0 @@ return Mark; |
@@ -1,6 +0,1 @@ | ||
/* | ||
Markup.js v1.5.15: http://github.com/adammark/Markup.js | ||
MIT License | ||
(c) 2011 - 2013 Adam Mark | ||
*/ | ||
var Mark={includes:{},globals:{},delimiter:">",compact:false,_copy:function(d,c){c=c||[];for(var e in d){c[e]=d[e]}return c},_size:function(b){return b instanceof Array?b.length:(b||0)},_iter:function(a,b){this.idx=a;this.size=b;this.length=b;this.sign="#";this.toString=function(){return this.idx+this.sign.length-1}},_pipe:function(g,c){var b=c.shift(),f,a;if(b){f=b.split(this.delimiter);a=f.shift().trim();try{g=this._pipe(Mark.pipes[a].apply(null,[g].concat(f)),c)}catch(d){}}return g},_eval:function(e,g,h){var a=this._pipe(e,g),b=a,d=-1,c,f;if(a instanceof Array){a="";c=b.length;while(++d<c){f={iter:new this._iter(d,c)};a+=h?Mark.up(h,b[d],f):b[d]}}else{if(a instanceof Object){a=Mark.up(h,b)}}return a},_test:function(a,f,d,b){var e=Mark.up(f,d,b).split(/\{\{\s*else\s*\}\}/),c=(a===false?e[1]:e[0]);return Mark.up(c||"",d,b)},_bridge:function(h,e){var f="{{\\s*"+e+"([^/}]+\\w*)?}}|{{/"+e+"\\s*}}",n=new RegExp(f,"g"),p=h.match(n)||[],o,g,m=0,l=0,k=-1,j=0;for(g=0;g<p.length;g++){o=g;k=h.indexOf(p[o],k+1);if(p[o].indexOf("{{/")>-1){l++}else{m++}if(m===l){break}}m=h.indexOf(p[0]);l=m+p[0].length;j=k+p[o].length;return[h.substring(m,j),h.substring(l,k)]}};Mark.up=function(s,b,e){b=b||{};e=e||{};var m=/\{\{(.+?)\}\}/g,l=s.match(m)||[],t,d,g,h=[],r,c,f,n,k,o,a,q=0,p=0;if(e.pipes){this._copy(e.pipes,this.pipes)}if(e.includes){this._copy(e.includes,this.includes)}if(e.globals){this._copy(e.globals,this.globals)}if(e.delimiter){this.delimiter=e.delimiter}if(e.compact!==undefined){this.compact=e.compact}while((t=l[q++])){k=undefined;f="";r=t.indexOf("/}}")>-1;d=t.substr(2,t.length-(r?5:4));d=d.replace(/`(.+?)`/g,function(i,j){return Mark.up("{{"+j+"}}",b)});c=d.trim().indexOf("if ")===0;h=d.split("|");h.shift();d=d.replace(/^\s*if/,"").split("|").shift().trim();g=c?"if":d.split("|")[0];n=b[d];if(c&&!h.length){h=["notempty"]}if(!r&&s.indexOf("{{/"+g)>-1){k=this._bridge(s,g);t=k[0];f=k[1];q+=t.match(m).length-1}if(/^\{\{\s*else\s*\}\}$/.test(t)){continue}else{if((o=this.globals[d])!==undefined){k=this._eval(o,h,f)}else{if((a=this.includes[d])){if(a instanceof Function){a=a()}k=this._pipe(Mark.up(a,b),h)}else{if(d.indexOf("#")>-1){e.iter.sign=d;k=this._pipe(e.iter,h)}else{if(d==="."){k=this._pipe(b,h)}else{if(d.indexOf(".")>-1){d=d.split(".");n=Mark.globals[d[0]];if(n){p=1}else{p=0;n=b}while(n&&p<d.length){n=n[d[p++]]}k=this._eval(n,h,f)}else{if(c){k=this._pipe(n,h)}else{if(n instanceof Array){k=this._eval(n,h,f)}else{if(f){k=n?Mark.up(f,n):undefined}else{if(b.hasOwnProperty(d)){k=this._pipe(n,h)}}}}}}}}}}if(c){k=this._test(k,f,b,e)}s=s.replace(t,k===undefined?"???":k)}return this.compact?s.replace(/>\s+</g,"><"):s};Mark.pipes={empty:function(a){return !a||(a+"").trim().length===0?a:false},notempty:function(a){return a&&(a+"").trim().length?a:false},blank:function(b,a){return !!b||b===0?b:a},more:function(d,c){return Mark._size(d)>c?d:false},less:function(d,c){return Mark._size(d)<c?d:false},ormore:function(d,c){return Mark._size(d)>=c?d:false},orless:function(d,c){return Mark._size(d)<=c?d:false},between:function(e,d,f){e=Mark._size(e);return e>=d&&e<=f?e:false},equals:function(d,c){return d==c?d:false},notequals:function(d,c){return d!=c?d:false},like:function(b,a){return new RegExp(a,"i").test(b)?b:false},notlike:function(b,a){return !Mark.pipes.like(b,a)?b:false},upcase:function(a){return String(a).toUpperCase()},downcase:function(a){return String(a).toLowerCase()},capcase:function(a){return a.replace(/\b\w/g,function(b){return b.toUpperCase()})},chop:function(a,b){return a.length>b?a.substr(0,b)+"...":a},tease:function(c,d){var b=c.split(/\s+/);return b.slice(0,d).join(" ")+(b.length>d?"...":"")},trim:function(a){return a.trim()},pack:function(a){return a.trim().replace(/\s{2,}/g," ")},round:function(a){return Math.round(+a)},clean:function(a){return String(a).replace(/<\/?[^>]+>/gi,"")},size:function(a){return a.length},length:function(a){return a.length},reverse:function(a){return Mark._copy(a).reverse()},join:function(a,b){return a.join(b)},limit:function(b,c,a){return b.slice(+a||0,+c+(+a||0))},split:function(b,a){return b.split(a||",")},choose:function(b,c,a){return !!b?c:(a||"")},toggle:function(c,b,a,d){return a.split(",")[b.match(/\w+/g).indexOf(c+"")]||d},sort:function(a,c){var b=function(e,d){return e[c]>d[c]?1:-1};return Mark._copy(a).sort(c?b:undefined)},fix:function(a,b){return(+a).toFixed(b)},mod:function(a,b){return(+a)%(+b)},divisible:function(a,b){return a&&(+a%b)===0?a:false},even:function(a){return a&&(+a&1)===0?a:false},odd:function(a){return a&&(+a&1)===1?a:false},number:function(a){return parseFloat(a.replace(/[^\-\d\.]/g,""))},url:function(a){return encodeURI(a)},bool:function(a){return !!a},falsy:function(a){return !a},first:function(a){return a.idx===0},last:function(a){return a.idx===a.size-1},call:function(b,a){return b[a].apply(b,[].slice.call(arguments,2))},set:function(b,a){Mark.globals[a]=b;return""},log:function(a){console.log(a);return a}};if(typeof String.prototype.trim!=="function"){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}if(typeof module!=="undefined"&&module.exports){module.exports=Mark}else{if(typeof define!=="undefined"){define(function(){return Mark})}}; | ||
var Mark={includes:{},globals:{},delimiter:">",compact:false,_copy:function(d,c){c=c||[];for(var e in d){c[e]=d[e]}return c},_size:function(b){return b instanceof Array?b.length:(b||0)},_iter:function(a,b){this.idx=a;this.size=b;this.length=b;this.sign="#";this.toString=function(){return this.idx+this.sign.length-1}},_pipe:function(h,c){var g,f,b,a;if((g=c.shift())){f=g.split(this.delimiter);b=f.shift().trim();try{a=Mark.pipes[b].apply(null,[h].concat(f));h=this._pipe(a,c)}catch(d){}}return h},_eval:function(e,g,h){var a=this._pipe(e,g),b=a,d=-1,c,f;if(a instanceof Array){a="";c=b.length;while(++d<c){f={iter:new this._iter(d,c)};a+=h?Mark.up(h,b[d],f):b[d]}}else{if(a instanceof Object){a=Mark.up(h,b)}}return a},_test:function(a,e,c,b){var d=Mark.up(e,c,b).split(/\{\{\s*else\s*\}\}/);return(a===false?d[1]:d[0])||""},_bridge:function(h,e){var f="{{\\s*"+e+"([^/}]+\\w*)?}}|{{/"+e+"\\s*}}",n=new RegExp(f,"g"),p=h.match(n)||[],o,g,m=0,l=0,k=-1,j=0;for(g=0;g<p.length;g++){o=g;k=h.indexOf(p[o],k+1);if(p[o].indexOf("{{/")>-1){l++}else{m++}if(m===l){break}}m=h.indexOf(p[0]);l=m+p[0].length;j=k+p[o].length;return[h.substring(m,j),h.substring(l,k)]}};Mark.up=function(s,b,e){b=b||{};e=e||{};var m=/\{\{(.+?)\}\}/g,l=s.match(m)||[],t,d,g,h=[],r,c,f,k,o,a,n,q=0,p=0;if(e.pipes){this._copy(e.pipes,this.pipes)}if(e.includes){this._copy(e.includes,this.includes)}if(e.globals){this._copy(e.globals,this.globals)}if(e.delimiter){this.delimiter=e.delimiter}if(e.compact!==undefined){this.compact=e.compact}while((t=l[q++])){k=undefined;f="";r=t.indexOf("/}}")>-1;d=t.substr(2,t.length-(r?5:4));d=d.replace(/`(.+?)`/g,function(i,j){return Mark.up("{{"+j+"}}",b)});c=d.trim().indexOf("if ")===0;h=d.split("|");h.shift();d=d.replace(/^\s*if/,"").split("|").shift().trim();g=c?"if":d.split("|")[0];n=b[d];if(c&&!h.length){h=["notempty"]}if(!r&&s.indexOf("{{/"+g)>-1){k=this._bridge(s,g);t=k[0];f=k[1];q+=t.match(m).length-1}if(/^\{\{\s*else\s*\}\}$/.test(t)){continue}else{if((o=this.globals[d])!==undefined){k=this._eval(o,h,f)}else{if((a=this.includes[d])){if(a instanceof Function){a=a()}k=this._pipe(Mark.up(a,b),h)}else{if(d.indexOf("#")>-1){e.iter.sign=d;k=this._pipe(e.iter,h)}else{if(d==="."){k=this._pipe(b,h)}else{if(d.indexOf(".")>-1){d=d.split(".");n=Mark.globals[d[0]];if(n){p=1}else{p=0;n=b}while(n&&p<d.length){n=n[d[p++]]}k=this._eval(n,h,f)}else{if(c){k=this._pipe(n,h)}else{if(n instanceof Array){k=this._eval(n,h,f)}else{if(f){k=n?Mark.up(f,n):undefined}else{if(b.hasOwnProperty(d)){k=this._pipe(n,h)}}}}}}}}}}if(c){k=this._test(k,f,b,e)}s=s.replace(t,k===undefined?"???":k)}return this.compact?s.replace(/>\s+</g,"><"):s};Mark.pipes={empty:function(a){return !a||(a+"").trim().length===0?a:false},notempty:function(a){return a&&(a+"").trim().length?a:false},blank:function(b,a){return !!b||b===0?b:a},more:function(d,c){return Mark._size(d)>c?d:false},less:function(d,c){return Mark._size(d)<c?d:false},ormore:function(d,c){return Mark._size(d)>=c?d:false},orless:function(d,c){return Mark._size(d)<=c?d:false},between:function(e,d,f){e=Mark._size(e);return e>=d&&e<=f?e:false},equals:function(d,c){return d==c?d:false},notequals:function(d,c){return d!=c?d:false},like:function(b,a){return new RegExp(a,"i").test(b)?b:false},notlike:function(b,a){return !Mark.pipes.like(b,a)?b:false},upcase:function(a){return String(a).toUpperCase()},downcase:function(a){return String(a).toLowerCase()},capcase:function(a){return a.replace(/\b\w/g,function(b){return b.toUpperCase()})},chop:function(a,b){return a.length>b?a.substr(0,b)+"...":a},tease:function(c,d){var b=c.split(/\s+/);return b.slice(0,d).join(" ")+(b.length>d?"...":"")},trim:function(a){return a.trim()},pack:function(a){return a.trim().replace(/\s{2,}/g," ")},round:function(a){return Math.round(+a)},clean:function(a){return String(a).replace(/<\/?[^>]+>/gi,"")},size:function(a){return a.length},length:function(a){return a.length},reverse:function(a){return Mark._copy(a).reverse()},join:function(a,b){return a.join(b)},limit:function(b,c,a){return b.slice(+a||0,+c+(+a||0))},split:function(b,a){return b.split(a||",")},choose:function(b,c,a){return !!b?c:(a||"")},toggle:function(c,b,a,d){return a.split(",")[b.match(/\w+/g).indexOf(c+"")]||d},sort:function(a,c){var b=function(e,d){return e[c]>d[c]?1:-1};return Mark._copy(a).sort(c?b:undefined)},fix:function(a,b){return(+a).toFixed(b)},mod:function(a,b){return(+a)%(+b)},divisible:function(a,b){return a&&(+a%b)===0?a:false},even:function(a){return a&&(+a&1)===0?a:false},odd:function(a){return a&&(+a&1)===1?a:false},number:function(a){return parseFloat(a.replace(/[^\-\d\.]/g,""))},url:function(a){return encodeURI(a)},bool:function(a){return !!a},falsy:function(a){return !a},first:function(a){return a.idx===0},last:function(a){return a.idx===a.size-1},call:function(b,a){return b[a].apply(b,[].slice.call(arguments,2))},set:function(b,a){Mark.globals[a]=b;return""},log:function(a){console.log(a);return a}};if(typeof String.prototype.trim!=="function"){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}if(typeof module!=="undefined"&&module.exports){module.exports=Mark}else{if(typeof define==="function"&&define.amd){define(function(){return Mark})}}; |
50585
1204
419