src/mini-template-engine.js
function miniTemplateEngine(str, props, callback) {
    var isCallback = false,
        errorString = 'The first parameter must be a string';

    if (callback && isFunction(callback)) {
        isCallback = true;
    }

    if (!str || !isString(str)) {
        if (isCallback) {
            callback(null, errorString);
        } else {
            throw new Error(errorString);
        }
    }

    if (!props || !isObject(props)) {
        props = {};
    }

    if (isCallback) {
        setTimeout(function() {
            return callback(
                new TemplateBuilder(str, props)
                    .getRenderedTemplate()
            );
        }, 1);
    } else {
        return new TemplateBuilder(str, props)
            .getRenderedTemplate();
    }
}
function miniTemplateEngine(str, props, callback) {
    var isCallback = false,
        errorString = 'The first parameter must be a string';

    if (callback && isFunction(callback)) {
        isCallback = true;
    }

    if (!str || !isString(str)) {
        if (isCallback) {
            callback(null, errorString);
        } else {
            throw new Error(errorString);
        }
    }

    if (!props || !isObject(props)) {
        props = {};
    }

    if (isCallback) {
        setTimeout(function() {
            return callback(
                new TemplateBuilder(str, props)
                    .getRenderedTemplate()
            );
        }, 1);
    } else {
        return new TemplateBuilder(str, props)
            .getRenderedTemplate();
    }
}
function miniTemplateEngine ( str , props , callback ) { var isCallback = false , errorString = 'The first parameter must be a string' ; if ( callback && isFunction ( callback ) ) { isCallback = true ; } if ( ! str || ! isString ( str ) ) { if ( isCallback ) { callback ( null , errorString ) ; } else { throw new Error ( errorString ) ; } } if ( ! props || ! isObject ( props ) ) { props = { } ; } if ( isCallback ) { setTimeout ( function ( ) { return callback ( new TemplateBuilder ( str , props ) . getRenderedTemplate ( ) ) ; } , 1 ) ; } else { return new TemplateBuilder ( str , props ) . getRenderedTemplate ( ) ; } }
This is a small easy template engine.
It just replaces variable placeholders with objects passed to the function.
@param {string} the string with placeholders
@param {object} the properties to replace the placeholders
@throws {Error} Throws an error if the first parameter is not a string
@returns {string}
This is a small easy template engine . It just replaces variable placeholders with objects passed to the function .