Skip to content

Commit

Permalink
lib/config.js: async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
samuela committed Oct 17, 2021
1 parent f923f67 commit a557fed
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
var util = require("util");
var NodeGit = require("../");
const util = require("util");
const NodeGit = require("../");

var Config = NodeGit.Config;
const Config = NodeGit.Config;

var _getBool = Config.prototype.getBool;
var _setBool = Config.prototype.setBool;
const _getBool = Config.prototype.getBool;
const _setBool = Config.prototype.setBool;

/**
* @async
* @param {String} name The variable's name
* @return {Boolean} The variable's value
*/
Config.prototype.getBool = function(name) {
return _getBool.call(this, name)
.then(result => Boolean(result));
Config.prototype.getBool = async function (name) {
return Boolean(await _getBool.call(this, name));
};

/**
Expand All @@ -22,27 +21,22 @@ Config.prototype.getBool = function(name) {
* @param {Boolean} name The variable's value
* @return {Number} 0 or an error code
*/
Config.prototype.setBool = function(name, value) {
Config.prototype.setBool = function (name, value) {
return _setBool.call(this, name, value ? 1 : 0);
};

// Backwards compatibility.
Config.prototype.getString = function() {
Config.prototype.getString = function () {
return this.getStringBuf.apply(this, arguments);
};

NodeGit.Enums.CVAR = {};
var DEPRECATED_CVAR_ENUMS = [
"FALSE",
"TRUE",
"INT32",
"STRING"
];
var DEPRECATED_CVAR_ENUMS = ["FALSE", "TRUE", "INT32", "STRING"];
DEPRECATED_CVAR_ENUMS.forEach((key) => {
Object.defineProperty(NodeGit.Enums.CVAR, key, {
get: util.deprecate(
() => Config.MAP[key],
`Use NodeGit.Config.MAP.${key} instead of NodeGit.Enums.CVAR.${key}.`
)
),
});
});

0 comments on commit a557fed

Please sign in to comment.