This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+1080
View File
File diff suppressed because it is too large Load Diff
+65
View File
@@ -0,0 +1,65 @@
// Based on iniparser by shockie <https://npmjs.org/package/iniparser>
/*
* get the file handler
*/
var fs = require('fs');
/*
* define the possible values:
* section: [section]
* param: key=value
* comment: ;this is a comment
*/
var regex = {
section: /^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$/,
param: /^\s*([\w\.\-\_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$/,
comment: /^\s*[#;].*$/
};
/*
* parses a .ini file
* @param: {String} file, the location of the .ini file
* @param: {Function} callback, the function that will be called when parsing is done
* @return: none
*/
module.exports.parse = function (file, callback) {
if (!callback) {
return;
}
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
callback(err);
} else {
callback(null, parse(data));
}
});
};
module.exports.parseSync = function (file) {
return parse(fs.readFileSync(file, 'utf8'));
};
function parse (data) {
var sectionBody = {};
var sectionName = null;
var value = [[sectionName, sectionBody]];
var lines = data.split(/\r\n|\r|\n/);
lines.forEach(function (line) {
var match;
if (regex.comment.test(line)) {
return;
} else if (regex.param.test(line)) {
match = line.match(regex.param);
sectionBody[match[1]] = match[2];
} else if (regex.section.test(line)) {
match = line.match(regex.section);
sectionName = match[1];
sectionBody = {};
value.push([sectionName, sectionBody]);
}
});
return value;
}
module.exports.parseString = parse;
+48
View File
@@ -0,0 +1,48 @@
function Version(version) {
var args = arguments;
this.components = typeof version === "string" ?
version.split(".").map(function(x){return parseInt(x, 10);}) :
Object.keys(arguments).map(function(k){return args[k];});
var len = this.components.length;
this.major = len ? this.components[0] : 0;
this.minor = len > 1 ? this.components[1] : 0;
this.build = len > 2 ? this.components[2] : 0;
this.revision = len > 3 ? this.components[3] : 0;
if (typeof version !== "string") {
return;
}
var ext = version.split("-");
if (ext.length === 2) {
this.configuration = ext[1];
}
}
Version.prototype = {
toString: function() {
var version = this.components.join(".");
if (typeof this.configuration !== "undefined") {
version += "-" + this.configuration;
}
return version;
},
gte: function(other){
if (this.major < other.major) {
return false;
}
if (this.minor < other.minor) {
return false;
}
if (this.build < other.build) {
return false;
}
if (this.revision < other.revision) {
return false;
}
return true;
}
};
module.exports = Version;