mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Use lib* prefix for the modules impored from the lib package to help distinguish them more from ordinary variables. Fix up the naming convention for files to be consistently lowercase_underscore for JavaScript files.
27 lines
470 B
JavaScript
27 lines
470 B
JavaScript
/**
|
|
* Utilities for dealing with Lua
|
|
* @module lib/lua_tools
|
|
*/
|
|
"use strict";
|
|
|
|
/**
|
|
* Escapes a string for inclusion into a lua string
|
|
*
|
|
* @param {string} content - String to escape.
|
|
* @returns {string} Escaped string.
|
|
*/
|
|
function escapeString(content) {
|
|
return content
|
|
.replace(/\\/g, "\\\\")
|
|
.replace(/"/g, '\\"')
|
|
.replace(/'/g, "\\'")
|
|
.replace(/\0/g, "\\0")
|
|
.replace(/\n/g, "\\n")
|
|
.replace(/\r/g, "\\r")
|
|
;
|
|
}
|
|
|
|
module.exports = {
|
|
escapeString,
|
|
};
|