Moving type conversion in its own file and adding
Added buffer object to carry functions and comments related to oe buffer
This commit is contained in:
80
lib/types.js
Normal file
80
lib/types.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @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;
|
||||
Reference in New Issue
Block a user