Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- 'use strict';
- var specialConsole = (function () {
- var writeLine = function () {
- var args = Array.prototype.slice.call(arguments);
- if (args.length > 0) {
- var outputString = createString(args);
- console.log(outputString);
- }
- };
- var writeError = function () {
- var args = Array.prototype.slice.call(arguments);
- if (args.length > 0) {
- var outputString = createString(args);
- console.error(outputString);
- }
- };
- function createString(dataArr) {
- var regExp = new RegExp('(\\{(0)\\})', ['gi']);
- var workString = dataArr[0].toString();
- var ocurrArr = workString.match(regExp);
- var count = 1;
- while (ocurrArr) {
- workString = workString.replace(regExp, (dataArr[count] || '').toString());
- regExp = new RegExp('(\\{(' + count + ')\\})', ['gi']);
- ocurrArr = workString.match(regExp);
- count++;
- }
- return workString;
- }
- return {
- writeLine: writeLine,
- writeError: writeError
- };
- })();
- specialConsole.writeLine();
- specialConsole.writeLine('Test message!');
- specialConsole.writeLine('Test message with {1} {0}{2}', 'placeholders', 'some', '!');
- specialConsole.writeLine('Test message with {1} {0}{2} and missing parameter!', 'placeholders', 'some');
- specialConsole.writeError();
- specialConsole.writeError('Error message!');
- specialConsole.writeError('Error message with {1} {0}{2}', 'placeholders', 'some', '!');
- specialConsole.writeError('Error message with {1} {0}{2} and missing parameter!', 'placeholders', 'some');
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement