const Handlebars = require('handlebars'); module.exports = { toJSON: function(object) { if(typeof object === 'object') { return JSON.stringify(object); } else { throw 'no object type'; } }, isObject: function(value, options) { return typeof value === 'object' && value !== null && !Array.isArray(value) ? options.fn(this) : options.inverse(this); }, isArray: function(value, options) { return Array.isArray(value) ? options.fn(this) : options.inverse(this); }, isRGB: function(value) { return Array.isArray(value) && (value.length === 3 || value.length === 4); }, rgbString: function(value) { if (Array.isArray(value)) { return value.length === 3 ? `rgb(${value.join(',')})` : value.length === 4 ? `rgba(${value.join(',')})` : ''; } return ''; }, toArray: function(value) { if (Array.isArray(value)) return value; if (typeof value === "string") return [value]; return []; }, replaceAll: function(string, pattern, replacement) { return new Handlebars.SafeString(string.replaceAll(pattern, replacement) || ''); }, equaler: function(v1, operator, v2, options) { switch (operator) { case '==': return (v1 == v2) ? options.fn(this) : options.inverse(this); case '===': return (v1 === v2) ? options.fn(this) : options.inverse(this); case '!=': return (v1 != v2) ? options.fn(this) : options.inverse(this); case '!==': return (v1 !== v2) ? options.fn(this) : options.inverse(this); case '<': return (v1 < v2) ? options.fn(this) : options.inverse(this); case '<=': return (v1 <= v2) ? options.fn(this) : options.inverse(this); case '>': return (v1 > v2) ? options.fn(this) : options.inverse(this); case '>=': return (v1 >= v2) ? options.fn(this) : options.inverse(this); case '&&': return (v1 && v2) ? options.fn(this) : options.inverse(this); case '||': return (v1 || v2) ? options.fn(this) : options.inverse(this); case 'typeof': return (typeof v1 === v2) ? options.fn(this) : options.inverse(this); case 'like': return (v1.indexOf(v2)) > -1 ? options.fn(this) : options.inverse(this); case 'includes': return (v1.includes(v2)) <= 0 ? options.inverse(this) : options.fn(this); case '%': return (v1 % v2) == 0 ? options.fn(this) : options.inverse(this); default: return options.inverse(this); } }, };