81 lines
1.7 KiB
JavaScript
81 lines
1.7 KiB
JavaScript
/**
|
|
* @function color
|
|
* Convert a color to message string
|
|
* @param {string|number} value Color to convert
|
|
* @return {string} Converted color
|
|
*/
|
|
function color (value) {
|
|
"use strict";
|
|
|
|
return value ? value : "none";
|
|
}
|
|
|
|
/**
|
|
* @function bool
|
|
* Convert a boolean value to message string
|
|
* @param {bool} value Boolean to convert
|
|
* @return {string} Converted boolean
|
|
*/
|
|
function bool (value) {
|
|
"use strict";
|
|
|
|
return value ? "T" : "F";
|
|
}
|
|
|
|
/**
|
|
* @function position
|
|
* Convert a position to message string
|
|
* @param {number} line Line of position starting with 1
|
|
* @param {number} col Column of position starting with 0
|
|
* @return {string} Converted position
|
|
*/
|
|
function position (line, col) {
|
|
"use strict";
|
|
|
|
return line+"/"+col;
|
|
}
|
|
|
|
/**
|
|
* @function string
|
|
* Convert a string to message string
|
|
* @param {string} value String to convert
|
|
* @return {string} Converted string
|
|
*/
|
|
function string (value) {
|
|
"use strict";
|
|
|
|
var buffer = "\"";
|
|
|
|
for (var i = 0 ; i < value.length ; ++i){
|
|
switch (value[i]) {
|
|
case "\n" :
|
|
buffer += "\\n";
|
|
break;
|
|
case "\t" :
|
|
buffer += "\\t";
|
|
break;
|
|
case "\r" :
|
|
buffer += "\\r";
|
|
break;
|
|
case "\\" :
|
|
buffer += "\\\\";
|
|
break;
|
|
case "\"" :
|
|
buffer += "\\\"";
|
|
break;
|
|
default :
|
|
buffer += value[i];
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
buffer += "\"";
|
|
return buffer;
|
|
}
|
|
|
|
module.exports.string = string;
|
|
module.esports.color = color;
|
|
module.exports.position = position;
|
|
module.exports.bool = bool;
|