Server : nginx/1.20.1 System : Linux ccpf-production-2021 5.4.0-148-generic #165-Ubuntu SMP Tue Apr 18 08:53:12 UTC 2023 x86_64 User : forge ( 1000) PHP Version : 7.4.21 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /lib/node_modules/pm2/node_modules/js-git/lib/ |
"use strict";
// This is for working with git config files like .git/config and .gitmodules.
// I believe this is just INI format.
module.exports = {
encode: encode,
decode: decode
};
function encode(config) {
var lines = [];
Object.keys(config).forEach(function (name) {
var obj = config[name];
var deep = {};
var values = {};
var hasValues = false;
Object.keys(obj).forEach(function (key) {
var value = obj[key];
if (typeof value === 'object') {
deep[key] = value;
}
else {
hasValues = true;
values[key] = value;
}
});
if (hasValues) {
encodeBody('[' + name + ']', values);
}
Object.keys(deep).forEach(function (sub) {
var child = deep[sub];
encodeBody('[' + name + ' "' + sub + '"]', child);
});
});
return lines.join("\n") + "\n";
function encodeBody(header, obj) {
lines.push(header);
Object.keys(obj).forEach(function (name) {
lines.push( "\t" + name + " = " + obj[name]);
});
}
}
function decode(text) {
var config = {};
var section;
text.split(/[\r\n]+/).forEach(function (line) {
var match = line.match(/\[([^ \t"\]]+) *(?:"([^"]+)")?\]/);
if (match) {
section = config[match[1]] || (config[match[1]] = {});
if (match[2]) {
section = section[match[2]] = {};
}
return;
}
match = line.match(/([^ \t=]+)[ \t]*=[ \t]*(.+)/);
if (match) {
section[match[1]] = match[2];
}
});
return config;
}