Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smarty4js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smarty4js - npm Package Compare versions

Comparing version 0.1.6-beta to 0.1.6

lib/compiler.js

4

index.js

@@ -8,4 +8,4 @@ /**

var parser = require('./lib/parser/index');
var Compiler = require('./lib/Compiler');
var Renderer = require('./lib/Renderer');
var Compiler = require('./lib/compiler');
var Renderer = require('./lib/renderer');
var phpfunc = require('./lib/phpfunc');

@@ -12,0 +12,0 @@ var func = require('./lib/func');

@@ -1,104 +0,1 @@

/**
* @file smarty build-in function
* @author johnson [zoumiaojiang@gmail.com]
*/
module.exports = {
// TODO: counter, cycle ...
'html_image': function (p) {
var height = p.height ? ' height="' + p.height + '"' : '';
var width = p.width ? ' width="' + p.width + '"' : '';
var border = p.border ? ' border="' + p.border + '"' : '';
var alt = p.alt ? ' alt="' + p.alt + '"' : '';
__h += '<img src="' + (p.file || '') + '"' + height + width + border + alt + '/>';
},
'html_checkboxes': function (p) {
if (p.values && p.output) {
for (var i in p.values) {
if (p.values.hasOwnProperty(i)) {
var val = p.values[i];
var out = p.output[i];
__h += '<label><input type="checkbox" name="' + (p.name || '') + '" value="' + val + '"'
+ (val === '' + p.selected ? ' checked' : '') + '/>' + out + '</label>' + (p.separator || '');
}
}
}
else if (p.options) {
var opts = p.options;
for (var j in opts) {
if (opts.hasOwnProperty(j)) {
__h += '<label><input type="checkbox" name="' + (p.name || '') + '" value="' + j + '"'
+ (j === '' + p.selected ? ' checked' : '') + '/>' + opts[j] + '</label>' + (p.separator || '');
}
}
}
},
'html_options': function (p) {
__h += '<select name="' + (p.name || '') + '">';
if (p.values && p.output) {
for (var i in p.values) {
if (p.values.hasOwnProperty(i)) {
var val = p.values[i];
var out = p.output[i];
__h += '<option label="' + out + '" value="' + val + '"'
+ (val === '' + p.selected ? ' selected' : '') + '>' + out + '</option>';
}
}
}
else if (p.options) {
var opts = p.options;
for (var j in opts) {
if (opts.hasOwnProperty(j)) {
__h += '<option label="' + opts[j] + '" value="' + j + '"'
+ (j === '' + p.selected ? ' selected="selected"' : '') + '>' + opts[j] + '</option>';
}
}
}
__h += '</select>';
},
'html_radios': function (p) {
var name = p.name || '';
if (p.values && p.output) {
for (var i in p.values) {
if (p.values.hasOwnProperty(i)) {
var val = p.values[i];
var out = p.output[i];
__h += '<label for="' + name + '_' + val + '">'
+ '<input type="radio" name="' + (p.name || '') + '" value="' + name + '_' + val + '"'
+ (val === '' + p.selected ? ' checked' : '') + '/>' + out + '</label>' + (p.separator || '');
}
}
}
else if (p.options) {
var opts = p.options;
for (var j in opts) {
if (opts.hasOwnProperty(j)) {
__h += '<label for="' + name + '_' + val + '">'
+ '<input type="radio" name="' + (p.name || '') + '" value="' + name + '_' + j + '"'
+ (j === '' + p.selected ? ' checked' : '') + '/>' + opts[j] + '</label>' + (p.separator || '');
}
}
}
},
math: function (p) {
var ret = '';
if (p.equation) {
ret = (new Function('o', 'return ' + p.equation.replace(/[_\w][_\w\d]*/g, function (s) {
return (Math[s] ? 'Math.' : 'o.') + s;
})))(p);
}
if (p.format) {
ret = __f["string_format"]('' + ret, p.format);
}
if (p.assign) {
__da[p.assign] = ret;
}
else {
__h += ret;
}
}
};
module.exports={html_image:function(e){var a=e.height?' height="'+e.height+'"':"";var t=e.width?' width="'+e.width+'"':"";var r=e.border?' border="'+e.border+'"':"";var o=e.alt?' alt="'+e.alt+'"':"";return'<img src="'+(e.file||"")+'"'+a+t+r+o+"/>"},html_checkboxes:function(e){var a="";var t=e.name||"checkboxs";if(e.values&&e.output){for(var r in e.values){if(e.values.hasOwnProperty(r)){var o=e.values[r];var n=e.output[r];a+='<label><input type="checkbox" name="'+t+'" value="'+o+'"'+(o==e.selected?" checked":"")+"/>"+n+"</label>"+(e.separator||"")}}}else if(e.options){var i=e.options;for(var l in i){if(i.hasOwnProperty(l)){a+='<label><input type="checkbox" name="'+t+'" value="'+l+'"'+(l==e.selected?" checked":"")+"/>"+i[l]+"</label>"+(e.separator||"")}}}return a},html_options:function(e){var a=e.name||"select";var t='<select name="'+a+'">';if(e.values&&e.output){for(var r in e.values){if(e.values.hasOwnProperty(r)){var o=e.values[r];var n=e.output[r];t+='<option label="'+n+'" value="'+o+'"'+(o==e.selected?" selected":"")+">"+n+"</option>"}}}else if(e.options){var i=e.options;for(var l in i){if(i.hasOwnProperty(l)){t+='<option label="'+i[l]+'" value="'+l+'"'+(l==e.selected?" selected":"")+">"+i[l]+"</option>"}}}return t+"</select>"},html_radios:function(e){var a="";var t=e.name||"radios";if(e.values&&e.output){for(var r in e.values){if(e.values.hasOwnProperty(r)){var o=e.values[r];var n=e.output[r];a+='<label for="'+t+"_"+o+'">'+'<input type="radio" name="'+t+'" value="'+t+"_"+o+'"'+(o==e.checked?" checked":"")+"/>"+n+"</label>"+(e.separator||"")}}}else if(e.options){var i=e.options;for(var l in i){if(i.hasOwnProperty(l)){a+='<label for="'+t+"_"+l+'">'+'<input type="radio" name="'+t+'" value="'+t+"_"+l+'"'+(l==e.checked?" checked":"")+"/>"+i[l]+"</label>"+(e.separator||"")}}}return a},math:function(e){var a="";if(e.equation){a=new Function("o","return "+e.equation.replace(/[_\w][_\w\d]*/g,function(e){return(Math[e]?"Math.":"o.")+e}))(e)}if(e.format){a=__f["string_format"](""+a,e.format)}if(e.assign){__da[e.assign]=a;a=""}return a}};

@@ -1,936 +0,1 @@

/**
* @file php function module
* @author johnson [zoumiaojiang@gmail.com]
*/
var __nre = /[\.\(\)\[\]\{\}\+\-\*\?\|\^\$]/g;
module.exports = {
escape: function (str, f) {
var tmp = '';
function padnum (n, w, r, p) {
n = n.toString(r || 10); p = p || '0';
while (n.length < w) {
n = p + n;
}
return n.toUpperCase();
}
if (!str) {
return '';
}
if (typeof str === 'string') {
if (!f) {
return this.escape(str, 'html');
}
if (f === 'html' || f === 'htmlall') {
var obj = {'<': '&#60;', '>': '&#62;', '\'': '&#039;', '"': '&#034;', '&': '&#038;'};
return str.replace(/['"<>&']/g, function (s) {
return obj[s];
});
}
if (f === 'url') {
return encodeURI(str);
}
if (f === 'urlpathinfo') {
return encodeURIComponent(str).replace(/%2F/g, '/');
}
if (f === 'quotes') {
return str.replace(/\'/g, '\\\'').replace(/\"/g, '\\\"');
}
if (f === 'mail') {
return str.replace(/@/g, ' [AT] ').replace(/\./g, ' [DOT] ');
}
if (f === 'hex') {
for (var i = 0, l = str.length; i < l; i++) {
tmp += '%' + padnum(str.charCodeAt(i), 2, 16);
}
return tmp;
}
if (f === 'hexentity') {
for (i = 0, l = str.length; i < l; i++) {
tmp += '&#x' + padnum(str.charCodeAt(i), 4, 16);
}
return tmp;
}
if (f === 'decentity') {
for (i = 0, l = str.length; i < l; i++) {
tmp += '&#' + str.charCodeAt(i) + ';';
}
return tmp;
}
if (f === 'javascript') {
var map = {'\\': '\\\\', '\'': '\\\'', '"': '\\"', '\r': '\\r', '\n': '\\n', '</': '<\\/'};
return str.replace(/[\\'"\r\n]|<\//g, function (s) {
return map[s];
});
}
}
return str;
},
strip: function (str, s) {
return str.replace(/[\s\n\r\t]+/g, ((s && ('string' === typeof s)) ? s : ' '));
},
isset: function (any) {
return any === undefined ? false : true;
},
empty: function (obj) {
var n = 0;
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
n++;
}
}
return (n > 0) ? false : true;
},
count: function (obj) {
var n = 0;
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
n++;
}
}
return n;
},
sizeof: function (obj) {
var n = 0;
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
n++;
}
}
return n;
},
time: function () {
var d = new Date();
return ''
+ [d.getFullYear(), d.getMonth() + 1, d.getDate()].join('-') + ' '
+ [d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
},
capitalize: function (str, cnb) {
return str.replace(/\w+\s*/g, function (item) {
return /\d/g.test(item)
? ((cnb === true) ? item.charAt(0).toUpperCase() + item.slice(1) : item)
: item.charAt(0).toUpperCase() + item.slice(1);
});
},
cat: function (a, b) {
return '' + a + b;
},
'count_characters': function (str, iws) {
return iws ? str.length : str.split(/\s*/).join('').length;
},
'count_paragraphs': function (str, iws) {
return str.split(new RegExp('[\r\n]' + iws ? '' : '+')).length;
},
'count_sentences': function (str) {
return str.split('.').length;
},
'count_words': function (str) {
return str.split(/\w+\s*/).length - 1;
},
'default': function (str, con) {
return str !== undefined ? str : con;
},
indent: function (str, num, repl) {
function gotSpace(n) {
var s = '';
for (var i = 0; i < n; i++) {
s += (repl ? '' + repl : ' ');
}
return s;
}
return ('number' === typeof num && num > 0) ? (gotSpace(num) + str) : (gotSpace(4) + str);
},
lower: function (str) {
return ('' + str).toLowerCase();
},
nl2br: function (str) {
return ('' + str).replace(/\n/g, '<br/>');
},
'regex_replace': function (str, re, rs) {
return ('' + str).replace((new Function('return ' + re))(), rs);
},
replace: function (str, s, o) {
return ('' + str).split(s).join(o);
},
spacify: function (str, ss) {
return ss !== undefined ? str.split('').join(ss) : str.split('').join(' ');
},
'string_format': function (num, f) {
num = parseFloat('' + (num || 0), 10);
return f !== undefined
? f === '%d'
? parseInt('' + num, 10)
: (/%\.(\d)f/.test(f)) ? num.toFixed(parseInt(RegExp.$1, 10)) : num
: num;
},
'strip_tags': function (str) {
return ('' + str).replace(/<.*?>/g, '');
},
truncate: function (str, num, s) {
str = '' + str;
return num >= str.length ? str : str.substr(0, ((num >= 0) ? num : 80)) + (s ? '' + s : '...');
},
upper: function (str) {
return ('' + str).toUpperCase();
},
wordwrap: function (str, num, s) {
str = ('' + str).split('');
num = (num >= 0 ? num : 80);
for (var i = 0, l = str.length; i < l; i++) {
if (i % num === 0 && i !== 0) {
str[i] = str[i] + (s ? '' + s : '\n');
}
}
return str.join('');
},
'is_array': function (obj) {
return ({}.toString.call(obj) === '[object Object]' || {}.toString.call(obj) === '[object Array]');
},
ceil: function (num) {
return Math.ceil(parseFloat((num || 0), 10));
},
range: function (a, b, step) {
var arr = [];
step = step || 1;
if (typeof a === 'number' && typeof b === 'number' && a < b) {
for (var i = a; i <= b; i += step) {
arr[(i - a) / step] = i;
}
}
if (typeof a === 'string' && typeof b === 'string') {
a = ('' + a).charCodeAt(0);
b = ('' + b).charCodeAt(0);
if (a < b) {
for (i = a; i <= b; i += step) {
arr[(i - a) / step] = String.fromCharCode('' + i);
}
}
}
return arr;
},
'in_array': function (any, array) {
return array[any] ? true : false;
},
explode: function (s, str) {
var obj = {};
var arr = str.split(s);
for (var i = 0, l = arr.length; i < l; i++) {
obj['__a' + i] = arr[i];
}
return obj;
},
implode: function (s, obj) {
var arr = [];
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
arr.push(obj[p]);
}
}
return arr.join(s);
},
join: function (s, obj) {
var arr = [];
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
arr.push(obj[p]);
}
}
return arr.join(s);
},
array: function () {
return [];
},
'array_unique': function (array) {
var obj = {};
var ret = {};
for (var p in array) {
if (array.hasOwnProperty(p) && !obj[array[p]]) {
obj[array[p]] = true;
ret[p] = array[p];
}
}
return ret;
},
'array_sum': function (array) {
var sum = 0;
for (var p in array) {
if (array.hasOwnProperty(p) && typeof array[p] === 'number') {
sum += array[p];
}
}
return sum;
},
'array_product': function (array) {
var sum = 1;
for (var p in array) {
if (array.hasOwnProperty(p) && typeof array[p] === 'number') {
sum *= array[p];
}
}
return sum;
},
'array_merge': function () {
var arrs = Array.prototype.slice.call(arguments);
var obj = {};
var ind = 0;
for (var i = 0, l = arrs.length; i < l; i++) {
var arr = arrs[i];
for (var p in arr) {
if (arr.hasOwnProperty(p)) {
obj[(p.indexOf('__a') > -1) ? ('__a' + ind++) : p] = arr[p];
}
}
}
return obj;
},
'array_merge_recursive': function () { // TODO:
var arrs = Array.prototype.slice.call(arguments);
var obj = {};
var ind = 0;
for (var i = 0, l = arrs.length; i < l; i++) {
var arr = arrs[i];
for (var p in arr) {
if (arr.hasOwnProperty(p)) {
obj[(p.indexOf('__a') > -1) ? ('__a' + ind++) : p] = arr[p];
}
}
}
return obj;
},
'array_keys': function (obj) {
var t = [];
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
t.push(p.replace('__a', ''));
}
}
return t;
},
'array_key_exists': function (any, array) {
return !array[any] === undefined ? true : false;
},
// string method
addcslashes: function (str, c) {
return ('' + str).split(c).join('\\' + c);
},
stripcslashes: function (str) {
return ('' + str).replace(/\\/, '');
},
addslashes: function (str) {
return ('' + str).replace(/[\'\"\\]/g, function (s) {
return '\\' + s;
});
},
stripslashes: function (str) {
return ('' + str).replace(/(\\\')|(\\\")|(\\\\)/g, function (s) {
return s.replace('\\', '');
});
},
// rtrim alias
chop: function (str, clist) {
var res = (clist !== undefined)
? '[' + ('' + clist).replace(__nre, function (s) {
return '\\' + s;
}) + ']+$'
: '[\\0\\t\\n\\r\\s]+$';
return ('' + str).replace(new RegExp(res), '');
},
chr: function (asc) {
return String.fromCharCode('' + asc);
},
'chunk_split': function (str, len, end) {
str = '' + str;
len = len || 0;
end = end || '';
return len === 0 ? str : str.replace(new RegExp('.{' + len + '}', 'g'), function (s) {
return s + end;
});
},
ltrim: function (str, clist) {
var res = (clist !== undefined)
? '^[' + ('' + clist).replace(__nre, function (s) {
return '\\' + s;
}) + ']+'
: '^[\\0\\t\\n\\r\\s]+';
return ('' + str).replace(new RegExp(res), '');
},
rtrim: function (str, clist) {
var res = (clist !== undefined)
? '[' + ('' + clist).replace(__nre, function (s) {
return '\\' + s;
}) + ']+$'
: '[\\0\\t\\n\\r\\s]+$';
return ('' + str).replace(new RegExp(res), '');
},
trim: function (str, clist) {
var tmps = (clist !== undefined)
? ('' + clist).replace(__nre, function (s) {
return '\\' + s;
})
: '\\0\\t\\n\\r\\s';
return ('' + str).replace(new RegExp('(^[' + tmps + ']+)|([' + tmps + ']+$)', 'g'), '');
},
ord: function (str) {
return ('' + str).charCodeAt(0);
},
'parse_str': function (str) {
var obj = {};
var arr = ('' + str).split('&');
for (var i = 0, l = arr.length; i < l; i++) {
var item = arr[i];
item = item.indexOf('%') > -1 ? decodeURI(item) : item;
var pi = item.split('=');
obj[pi[0]] = pi[1] || '';
}
return obj;
},
print: function () {
var args = Array.prototype.slice.call(arguments);
var s = '';
for (var i = 0, l = args.length; i < l; i++) {
var ts = args[i];
s += ts ? ts : '';
}
return s;
},
quotemeta: function (str) {
return ('' + str).replace(__nre, function (s) {
return '\\' + s;
});
},
'str_pad': function (str, len, pad, type) {
var to = {'STR_PAD_RIGHT': 0, 'STR_PAD_LEFT': 1, 'STR_PAD_BOTH': 2};
var par = '';
var t = 0;
str = '' + str;
var ret = str;
len = len || 0;
pad = pad || '';
type = type || 'STR_PAD_RIGHT';
if (len > str.length) {
if (to[type] !== 2) {
t = (len - str.length) / pad.length;
while (t-- > 0) {
par += pad;
}
ret = to[type] === 0 ? (str + par) : (par + str);
}
else {
t = (len - str.length) / pad.length / 2;
while (t-- > 0) {
par += pad;
}
ret = par + str + par;
}
}
return ret;
},
'str_repeat': function (str, rn) {
var all = '';
while (rn--) {
all += str;
}
return all;
},
'str_split': function (str, len) {
var arr = [];
str = '' + str;
len = len || 0;
if (len !== 0) {
var mats = str.match(new RegExp('.{' + len + '}', 'g'));
for (var i = 0, l = mats.length; i < l; i++) {
arr.push(mats[i]);
}
var lef = str.slice(l * len);
if (lef) {
arr.push(lef);
}
}
else {
arr = [str];
}
return arr;
},
strcmp: function (str1, str2) {
str1 = '' + str1, str2 = '' + str2;
return str1 === str2 ? 0 : (str1 > str2 ? 1 : -1);
},
strcasecmp: function (str1, str2) {
str1 = ('' + str1).toLowerCase(), str2 = '' + str2.toLowerCase();
return str1 === str2 ? 0 : (str1 > str2 ? 1 : -1);
},
strchr: function (str, search) {
str = '' + str;
return str.slice(str.indexOf((typeof search === 'number' ? String.fromCharCode(search) : ('' + search))));
},
strstr: function (str, search) {
str = '' + str;
return str.slice(str.indexOf((typeof search === 'number' ? String.fromCharCode(search) : ('' + search))));
},
stristr: function (str, search) {
str = '' + str;
return str.slice(str.toLowerCase().indexOf(
(typeof search === 'number'
? String.fromCharCode(search).toLowerCase()
: ('' + search).toLowerCase())
));
},
stripos: function (str, find, start) {
str = '' + str, start = start || 0;
return str.toLowerCase().indexOf(('' + find).toLowerCase(), start);
},
strpos: function (str, find, start) {
str = '' + str, start = start || 0;
return str.indexOf(('' + find), start);
},
strlen: function (str) {
return ('' + str).length;
},
strrchr: function (str, search) {
str = '' + str;
return str.slice(str.lastIndexOf((typeof search === 'number' ? String.fromCharCode(search) : ('' + search))));
},
strrev: function (str) {
return ('' + str).split('').reverse().join('');
},
strripos: function (str, find, start) {
str = '' + str, start = start || 0;
return str.toLowerCase().lastIndexOf(('' + find).toLowerCase(), start);
},
strrpos: function (str, find, start) {
str = '' + str, start = start || 0;
return str.lastIndexOf(('' + find), start);
},
strtolower: function (str) {
return ('' + str).toLowerCase();
},
strtoupper: function (str) {
return ('' + str).toUpperCase();
},
substr: function (str, start, len) {
str = '' + str;
start = start || 0;
len = (len === undefined || typeof len !== 'number') ? -1 : len;
return str.substring(start, (len === -1 ? str.length : (start + len)));
},
'substr_count': function (str, substr, start, len) {
str = '' + str;
start = start || 0;
len = (len === undefined || typeof len !== 'number') ? -1 : len;
return str.substring(start, (len === -1 ? str.length : (start + len))).split(substr).length - 1;
},
ucfirst: function (str) {
str = '' + str;
return str.charAt(0).toUpperCase() + str.slice(1);
},
ucwords: function (str) {
return ('' + str).replace(/\w+\s*/g, function (item) {
return /\d/g.test(item) ? item : item.charAt(0).toUpperCase() + item.slice(1);
});
},
rawurldecode: function (str) {
return decodeURIComponent('' + str);
},
rawurlencode: function (url) {
return encodeURIComponent('' + url);
},
urldecode: function (str) {
return decodeURI('' + str);
},
urlencode: function (url) {
return encodeURI('' + url);
},
// varibal function
'is_bool': function (bool) {
return (bool === true || bool === false) ? true : false;
},
floatval: function (str) {
return parseFloat('' + str, 10);
},
intval: function (str) {
return parseInt('' + str, 10);
},
'is_float': function (f) {
return (typeof f === 'number' && parseInt(f, 10) !== f) ? true : false;
},
'is_real': function (f) {
return (typeof f === 'number' && parseInt(f, 10) !== f) ? true : false;
},
'is_int': function (i) {
return (typeof i === 'number' && parseInt(i, 10) === i) ? true : false;
},
'is_integer': function (i) {
return (typeof i === 'number') ? true : false;
},
'is_object': function (o) {
return {}.toString.call(o) === '[object Object]';
},
'is_callable': function (o) {
return (typeof o === 'function') ? true : false;
},
'is_string': function (s) {
return (typeof s === 'string') ? true : false;
},
'is_numeric': function (a) {
return (typeof a === 'number') ? true : false;
},
strval: function (any) {
return (any !== undefined && any.toString) ? any.toString() : '';
},
'var_dump': function (any) {
function isArray(o) {
return {}.toString.call(o) === '[object Array]';
}
function isObj(o) {
return {}.toString.call(o) === '[object Object]';
}
function isOA(o) {
return (isArray(o) || isObj(o)) ? true : false;
}
function isRealArr(o) {
for (var p in o) {
if (o.hasOwnProperty(p) && p.indexOf('__a') !== 0) {
return false;
}
}
return true;
}
function pa(o) {
var type = (isArray(o) || (isRealArr(o) && isObj(o))) ? 0 : ((isObj(o) && !isRealArr(o)) ? 1 : 2);
var __enc;
if (type === 0 || type === 1) {
__enc = type === 0 ? '[' : '{';
for (var p in o) {
if (o.hasOwnProperty(p)) {
var to = o[p];
__enc += (type === 0
? ''
: ('"' + p + '":')) + (isOA(to)
? pa(to)
: (typeof to === 'string' ? '"' + to + '"' : to)) + ',';
}
}
__enc = __enc.slice(0, __enc.length - 1) + (type === 0 ? ']' : '}');
}
else {
__enc = o;
}
return __enc;
}
return (isArray(any) || isObj(any)) ? pa(any).replace(/__a/g, '') : (any || '');
},
echo: function () {
var args = Array.prototype.slice.call(arguments);
var s = '';
for (var i = 0, l = args.length; i < l; i++) {
var ts = args[i];
s += ts ? ts : '';
}
return s;
},
// math
abs: function (num) {
return Math.abs(num);
},
acos: function (deg) {
return Math.acos(deg);
},
acosh: function (deg) {
return Math.acosh(deg);
},
asin: function (deg) {
return Math.asin(deg);
},
asinh: function (deg) {
return Math.asinh(deg);
},
atan2: function (x, y) {
return Math.atan2(x, y);
},
atan: function (p) {
return Math.atan(p);
},
atanh: function (x) {
return Math.atanh(x);
},
cos: function (x) {
return Math.cos(x);
},
sin: function (x) {
return Math.sin(x);
},
tan: function (x) {
return Math.tan(x);
},
cosh: function (x) {
return Math.cosh(x);
},
sinh: function (x) {
return Math.sinh(x);
},
tanh: function (x) {
return Math.tanh(x);
},
dexbin: function (num) {
return num.toString(2);
},
dechex: function (num) {
return num.toString(16);
},
decoct: function (num) {
return num.toString(8);
},
deg2rad: function (deg) {
return deg * Math.PI / 180;
},
rad2deg: function (rad) {
return rad * 180 / Math.PI;
},
exp: function (x) {
return Math.exp(x);
},
expm1: function (x) {
return Math.expm1(x);
},
floor: function (x) {
return Math.floor(x);
},
fmod: function (x, y) {
return (typeof x === 'number' && typeof y === 'number') && x % y;
},
hexdec: function (hex) {
return parseInt('' + hex, 16);
},
octdec: function (oct) {
return parseInt('' + oct, 8);
},
hypot: function (x, y) {
return (typeof x === 'number' && typeof y === 'number') && Math.sqrt(x * x + y * y);
},
'is_infinite': function (x) {
return (('' + x) === 'Infinity') ? true : false;
},
'is_nan': function (x) {
return (('' + x) === 'NaN') ? true : false;
},
'lcg_value': function () {
return Math.random();
},
log10: function (x) {
return Math.log10(x);
},
log1p: function (x) {
return Math.log1p(x);
},
log: function (x) {
return Math.log(x);
},
max: function () {
var arrs = Array.prototype.slice.call(arguments);
var obj = (typeof arrs[0] === 'object') ? arrs[0] : arrs;
var max = obj[0];
for (var p in obj) {
if (obj.hasOwnProperty(p) && obj[p] > max) {
max = obj[p];
}
}
return max;
},
min: function () {
var arrs = Array.prototype.slice.call(arguments);
var obj = (typeof arrs[0] === 'object') ? arrs[0] : arrs;
var min = obj[0];
for (var p in obj) {
if (obj.hasOwnProperty(p) && obj[p] < min) {
min = obj[p];
}
}
return min;
},
pi: function () {
return Math.PI;
},
pow: function (x, y) {
return (typeof x === 'number' && typeof y === 'number') ? Math.pow(x, y) : false;
},
round: function (x) {
return Math.round(x);
},
sqrt: function (x) {
return Math.sqrt(x);
},
// common php method
uniqid: function (prefix) {
return (prefix || '') + (new Date()).getTime();
},
highlight: function (str, type) {
return str;
},
'json_encode': function (obj) {
function isArray(o) {
return {}.toString.call(o) === '[object Array]';
}
function isObj(o) {
return {}.toString.call(o) === '[object Object]';
}
function isOA(o) {
return (isArray(o) || isObj(o)) ? true : false;
}
function isRealArr(o) {
for (var p in o) {
if (o.hasOwnProperty(p) && p.indexOf('__a') !== 0) {
return false;
}
}
return true;
}
function pa(o) {
var type = (isArray(o) || (isRealArr(o) && isObj(o))) ? 0 : ((isObj(o) && !isRealArr(o)) ? 1 : 2);
var __enc = type === 0 ? '[' : '{';
for (var p in o) {
if (o.hasOwnProperty(p)) {
var to = o[p];
__enc += (type === 0 ? '' : ('"' + p + '":')) + (isOA(to)
? pa(to)
: (typeof to === 'string' ? '"' + to + '"' : to)) + ',';
}
}
__enc = __enc.slice(0, __enc.length - 1) + (type === 0 ? ']' : '}');
return __enc;
}
return pa(obj).replace(/__a/g, '');
},
'json_decode': function (json) {
// TODO
}
};
var __nre=/[\.\(\)\[\]\{\}\+\-\*\?\|\^\$]/g;module.exports={escape:function(r,n){var t="";function e(r,n,t,e){r=r.toString(t||10);e=e||"0";while(r.length<n){r=e+r}return r.toUpperCase()}if(!r){return""}if(typeof r==="string"){if(!n){return this.escape(r,"html")}if(n==="html"||n==="htmlall"){var u={"<":"&#60;",">":"&#62;","'":"&#039;",'"':"&#034;","&":"&#038;"};return r.replace(/['"<>&']/g,function(r){return u[r]})}if(n==="url"){return encodeURI(r)}if(n==="urlpathinfo"){return encodeURIComponent(r).replace(/%2F/g,"/")}if(n==="quotes"){return r.replace(/\'/g,"\\'").replace(/\"/g,'\\"')}if(n==="mail"){return r.replace(/@/g," [AT] ").replace(/\./g," [DOT] ")}if(n==="hex"){for(var o=0,i=r.length;o<i;o++){t+="%"+e(r.charCodeAt(o),2,16)}return t}if(n==="hexentity"){for(o=0,i=r.length;o<i;o++){t+="&#x"+e(r.charCodeAt(o),4,16)}return t}if(n==="decentity"){for(o=0,i=r.length;o<i;o++){t+="&#"+r.charCodeAt(o)+";"}return t}if(n==="javascript"){var a={"\\":"\\\\","'":"\\'",'"':'\\"',"\r":"\\r","\n":"\\n","</":"<\\/"};return r.replace(/[\\'"\r\n]|<\//g,function(r){return a[r]})}}return r},strip:function(r,n){return r.replace(/[\s\n\r\t]+/g,n&&"string"===typeof n?n:" ")},isset:function(r){return r===undefined?false:true},empty:function(r){var n=0;for(var t in r){if(r.hasOwnProperty(t)){n++}}return n>0?false:true},count:function(r){var n=0;for(var t in r){if(r.hasOwnProperty(t)){n++}}return n},sizeof:function(r){var n=0;for(var t in r){if(r.hasOwnProperty(t)){n++}}return n},time:function(){var r=new Date;return""+[r.getFullYear(),r.getMonth()+1,r.getDate()].join("-")+" "+[r.getHours(),r.getMinutes(),r.getSeconds()].join(":")},capitalize:function(r,n){return r.replace(/\w+\s*/g,function(r){return/\d/g.test(r)?n===true?r.charAt(0).toUpperCase()+r.slice(1):r:r.charAt(0).toUpperCase()+r.slice(1)})},cat:function(r,n){return""+r+n},count_characters:function(r,n){return n?r.length:r.split(/\s*/).join("").length},count_paragraphs:function(r,n){return r.split(new RegExp("[\r\n]"+n?"":"+")).length},count_sentences:function(r){return r.split(".").length},count_words:function(r){return r.split(/\w+\s*/).length-1},"default":function(r,n){return r!==undefined?r:n},indent:function(r,n,t){function e(r){var n="";for(var e=0;e<r;e++){n+=t?""+t:" "}return n}return"number"===typeof n&&n>0?e(n)+r:e(4)+r},lower:function(r){return(""+r).toLowerCase()},nl2br:function(r){return(""+r).replace(/\n/g,"<br/>")},regex_replace:function(r,n,t){return(""+r).replace(new Function("return "+n)(),t)},replace:function(r,n,t){return(""+r).split(n).join(t)},spacify:function(r,n){return n!==undefined?r.split("").join(n):r.split("").join(" ")},string_format:function(r,n){r=parseFloat(""+(r||0),10);return n!==undefined?n==="%d"?parseInt(""+r,10):/%\.(\d)f/.test(n)?r.toFixed(parseInt(RegExp.$1,10)):r:r},strip_tags:function(r){return(""+r).replace(/<.*?>/g,"")},truncate:function(r,n,t){r=""+r;return n>=r.length?r:r.substr(0,n>=0?n:80)+(t?""+t:"...")},upper:function(r){return(""+r).toUpperCase()},wordwrap:function(r,n,t){r=(""+r).split("");n=n>=0?n:80;for(var e=0,u=r.length;e<u;e++){if(e%n===0&&e!==0){r[e]=r[e]+(t?""+t:"\n")}}return r.join("")},is_array:function(r){return{}.toString.call(r)==="[object Object]"||{}.toString.call(r)==="[object Array]"},ceil:function(r){return Math.ceil(parseFloat(r||0,10))},range:function(r,n,t){var e=[];t=t||1;if(typeof r==="number"&&typeof n==="number"&&r<n){for(var u=r;u<=n;u+=t){e[(u-r)/t]=u}}if(typeof r==="string"&&typeof n==="string"){r=(""+r).charCodeAt(0);n=(""+n).charCodeAt(0);if(r<n){for(u=r;u<=n;u+=t){e[(u-r)/t]=String.fromCharCode(""+u)}}}return e},in_array:function(r,n){return n[r]?true:false},explode:function(r,n){var t={};var e=n.split(r);for(var u=0,o=e.length;u<o;u++){t["__a"+u]=e[u]}return t},implode:function(r,n){var t=[];for(var e in n){if(n.hasOwnProperty(e)){t.push(n[e])}}return t.join(r)},join:function(r,n){var t=[];for(var e in n){if(n.hasOwnProperty(e)){t.push(n[e])}}return t.join(r)},array:function(){return[]},array_unique:function(r){var n={};var t={};for(var e in r){if(r.hasOwnProperty(e)&&!n[r[e]]){n[r[e]]=true;t[e]=r[e]}}return t},array_sum:function(r){var n=0;for(var t in r){if(r.hasOwnProperty(t)&&typeof r[t]==="number"){n+=r[t]}}return n},array_product:function(r){var n=1;for(var t in r){if(r.hasOwnProperty(t)&&typeof r[t]==="number"){n*=r[t]}}return n},array_merge:function(){var r=Array.prototype.slice.call(arguments);var n={};var t=0;for(var e=0,u=r.length;e<u;e++){var o=r[e];for(var i in o){if(o.hasOwnProperty(i)){n[i.indexOf("__a")>-1?"__a"+t++:i]=o[i]}}}return n},array_merge_recursive:function(){var r=Array.prototype.slice.call(arguments);var n={};var t=0;for(var e=0,u=r.length;e<u;e++){var o=r[e];for(var i in o){if(o.hasOwnProperty(i)){n[i.indexOf("__a")>-1?"__a"+t++:i]=o[i]}}}return n},array_keys:function(r){var n=[];for(var t in r){if(r.hasOwnProperty(t)){n.push(t.replace("__a",""))}}return n},array_key_exists:function(r,n){return!n[r]===undefined?true:false},addcslashes:function(r,n){return(""+r).split(n).join("\\"+n)},stripcslashes:function(r){return(""+r).replace(/\\/,"")},addslashes:function(r){return(""+r).replace(/[\'\"\\]/g,function(r){return"\\"+r})},stripslashes:function(r){return(""+r).replace(/(\\\')|(\\\")|(\\\\)/g,function(r){return r.replace("\\","")})},chop:function(r,n){var t=n!==undefined?"["+(""+n).replace(__nre,function(r){return"\\"+r})+"]+$":"[\\0\\t\\n\\r\\s]+$";return(""+r).replace(new RegExp(t),"")},chr:function(r){return String.fromCharCode(""+r)},chunk_split:function(r,n,t){r=""+r;n=n||0;t=t||"";return n===0?r:r.replace(new RegExp(".{"+n+"}","g"),function(r){return r+t})},ltrim:function(r,n){var t=n!==undefined?"^["+(""+n).replace(__nre,function(r){return"\\"+r})+"]+":"^[\\0\\t\\n\\r\\s]+";return(""+r).replace(new RegExp(t),"")},rtrim:function(r,n){var t=n!==undefined?"["+(""+n).replace(__nre,function(r){return"\\"+r})+"]+$":"[\\0\\t\\n\\r\\s]+$";return(""+r).replace(new RegExp(t),"")},trim:function(r,n){var t=n!==undefined?(""+n).replace(__nre,function(r){return"\\"+r}):"\\0\\t\\n\\r\\s";return(""+r).replace(new RegExp("(^["+t+"]+)|(["+t+"]+$)","g"),"")},ord:function(r){return(""+r).charCodeAt(0)},parse_str:function(r){var n={};var t=(""+r).split("&");for(var e=0,u=t.length;e<u;e++){var o=t[e];o=o.indexOf("%")>-1?decodeURI(o):o;var i=o.split("=");n[i[0]]=i[1]||""}return n},print:function(){var r=Array.prototype.slice.call(arguments);var n="";for(var t=0,e=r.length;t<e;t++){var u=r[t];n+=u?u:""}return n},quotemeta:function(r){return(""+r).replace(__nre,function(r){return"\\"+r})},str_pad:function(r,n,t,e){var u={STR_PAD_RIGHT:0,STR_PAD_LEFT:1,STR_PAD_BOTH:2};var o="";var i=0;r=""+r;var a=r;n=n||0;t=t||"";e=e||"STR_PAD_RIGHT";if(n>r.length){if(u[e]!==2){i=(n-r.length)/t.length;while(i-->0){o+=t}a=u[e]===0?r+o:o+r}else{i=(n-r.length)/t.length/2;while(i-->0){o+=t}a=o+r+o}}return a},str_repeat:function(r,n){var t="";while(n--){t+=r}return t},str_split:function(r,n){var t=[];r=""+r;n=n||0;if(n!==0){var e=r.match(new RegExp(".{"+n+"}","g"));for(var u=0,o=e.length;u<o;u++){t.push(e[u])}var i=r.slice(o*n);if(i){t.push(i)}}else{t=[r]}return t},strcmp:function(r,n){r=""+r,n=""+n;return r===n?0:r>n?1:-1},strcasecmp:function(r,n){r=(""+r).toLowerCase(),n=""+n.toLowerCase();return r===n?0:r>n?1:-1},strchr:function(r,n){r=""+r;return r.slice(r.indexOf(typeof n==="number"?String.fromCharCode(n):""+n))},strstr:function(r,n){r=""+r;return r.slice(r.indexOf(typeof n==="number"?String.fromCharCode(n):""+n))},stristr:function(r,n){r=""+r;return r.slice(r.toLowerCase().indexOf(typeof n==="number"?String.fromCharCode(n).toLowerCase():(""+n).toLowerCase()))},stripos:function(r,n,t){r=""+r,t=t||0;return r.toLowerCase().indexOf((""+n).toLowerCase(),t)},strpos:function(r,n,t){r=""+r,t=t||0;return r.indexOf(""+n,t)},strlen:function(r){return(""+r).length},strrchr:function(r,n){r=""+r;return r.slice(r.lastIndexOf(typeof n==="number"?String.fromCharCode(n):""+n))},strrev:function(r){return(""+r).split("").reverse().join("")},strripos:function(r,n,t){r=""+r,t=t||0;return r.toLowerCase().lastIndexOf((""+n).toLowerCase(),t)},strrpos:function(r,n,t){r=""+r,t=t||0;return r.lastIndexOf(""+n,t)},strtolower:function(r){return(""+r).toLowerCase()},strtoupper:function(r){return(""+r).toUpperCase()},substr:function(r,n,t){r=""+r;n=n||0;t=t===undefined||typeof t!=="number"?-1:t;return r.substring(n,t===-1?r.length:n+t)},substr_count:function(r,n,t,e){r=""+r;t=t||0;e=e===undefined||typeof e!=="number"?-1:e;return r.substring(t,e===-1?r.length:t+e).split(n).length-1},ucfirst:function(r){r=""+r;return r.charAt(0).toUpperCase()+r.slice(1)},ucwords:function(r){return(""+r).replace(/\w+\s*/g,function(r){return/\d/g.test(r)?r:r.charAt(0).toUpperCase()+r.slice(1)})},rawurldecode:function(r){return decodeURIComponent(""+r)},rawurlencode:function(r){return encodeURIComponent(""+r)},urldecode:function(r){return decodeURI(""+r)},urlencode:function(r){return encodeURI(""+r)},is_bool:function(r){return r===true||r===false?true:false},floatval:function(r){return parseFloat(""+r,10)},intval:function(r){return parseInt(""+r,10)},is_float:function(r){return typeof r==="number"&&parseInt(r,10)!==r?true:false},is_real:function(r){return typeof r==="number"&&parseInt(r,10)!==r?true:false},is_int:function(r){return typeof r==="number"&&parseInt(r,10)===r?true:false},is_integer:function(r){return typeof r==="number"?true:false},is_object:function(r){return{}.toString.call(r)==="[object Object]"},is_callable:function(r){return typeof r==="function"?true:false},is_string:function(r){return typeof r==="string"?true:false},is_numeric:function(r){return typeof r==="number"?true:false},strval:function(r){return r!==undefined&&r.toString?r.toString():""},var_dump:function(r){function n(r){return{}.toString.call(r)==="[object Array]"}function t(r){return{}.toString.call(r)==="[object Object]"}function e(r){return n(r)||t(r)?true:false}function u(r){for(var n in r){if(r.hasOwnProperty(n)&&n.indexOf("__a")!==0){return false}}return true}function o(r){var i=n(r)||u(r)&&t(r)?0:t(r)&&!u(r)?1:2;var a;if(i===0||i===1){a=i===0?"[":"{";for(var f in r){if(r.hasOwnProperty(f)){var c=r[f];a+=(i===0?"":'"'+f+'":')+(e(c)?o(c):typeof c==="string"?'"'+c+'"':c)+","}}a=a.slice(0,a.length-1)+(i===0?"]":"}")}else{a=r}return a}return n(r)||t(r)?o(r).replace(/__a/g,""):r||""},echo:function(){var r=Array.prototype.slice.call(arguments);var n="";for(var t=0,e=r.length;t<e;t++){var u=r[t];n+=u?u:""}return n},abs:function(r){return Math.abs(r)},acos:function(r){return Math.acos(r)},acosh:function(r){return Math.acosh(r)},asin:function(r){return Math.asin(r)},asinh:function(r){return Math.asinh(r)},atan2:function(r,n){return Math.atan2(r,n)},atan:function(r){return Math.atan(r)},atanh:function(r){return Math.atanh(r)},cos:function(r){return Math.cos(r)},sin:function(r){return Math.sin(r)},tan:function(r){return Math.tan(r)},cosh:function(r){return Math.cosh(r)},sinh:function(r){return Math.sinh(r)},tanh:function(r){return Math.tanh(r)},dexbin:function(r){return r.toString(2)},dechex:function(r){return r.toString(16)},decoct:function(r){return r.toString(8)},deg2rad:function(r){return r*Math.PI/180},rad2deg:function(r){return r*180/Math.PI},exp:function(r){return Math.exp(r)},expm1:function(r){return Math.expm1(r)},floor:function(r){return Math.floor(r)},fmod:function(r,n){return typeof r==="number"&&typeof n==="number"&&r%n},hexdec:function(r){return parseInt(""+r,16)},octdec:function(r){return parseInt(""+r,8)},hypot:function(r,n){return typeof r==="number"&&typeof n==="number"&&Math.sqrt(r*r+n*n)},is_infinite:function(r){return""+r==="Infinity"?true:false},is_nan:function(r){return""+r==="NaN"?true:false},lcg_value:function(){return Math.random()},log10:function(r){return Math.log10(r)},log1p:function(r){return Math.log1p(r)},log:function(r){return Math.log(r)},max:function(){var r=Array.prototype.slice.call(arguments);var n=typeof r[0]==="object"?r[0]:r;var t=n[0];for(var e in n){if(n.hasOwnProperty(e)&&n[e]>t){t=n[e]}}return t},min:function(){var r=Array.prototype.slice.call(arguments);var n=typeof r[0]==="object"?r[0]:r;var t=n[0];for(var e in n){if(n.hasOwnProperty(e)&&n[e]<t){t=n[e]}}return t},pi:function(){return Math.PI},pow:function(r,n){return typeof r==="number"&&typeof n==="number"?Math.pow(r,n):false},round:function(r){return Math.round(r)},sqrt:function(r){return Math.sqrt(r)},uniqid:function(r){return(r||"")+(new Date).getTime()},highlight:function(r,n){return r},json_encode:function(r){function n(r){return{}.toString.call(r)==="[object Array]"}function t(r){return{}.toString.call(r)==="[object Object]"}function e(r){return n(r)||t(r)?true:false}function u(r){for(var n in r){if(r.hasOwnProperty(n)&&n.indexOf("__a")!==0){return false}}return true}function o(r){var i=n(r)||u(r)&&t(r)?0:t(r)&&!u(r)?1:2;var a=i===0?"[":"{";for(var f in r){if(r.hasOwnProperty(f)){var c=r[f];a+=(i===0?"":'"'+f+'":')+(e(c)?o(c):typeof c==="string"?'"'+c+'"':c)+","}}a=a.slice(0,a.length-1)+(i===0?"]":"}");return a}return o(r).replace(/__a/g,"")},json_decode:function(r){}};
{
"name": "smarty4js",
"description": "A JavaScript Template Engine Most Like Smarty",
"version": "0.1.6-beta",
"version": "0.1.6",
"keywords": [

@@ -6,0 +6,0 @@ "smarty",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc