diff --git a/.eslintrc.json b/.eslintrc.json index 61e8895..24b8984 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,8 @@ { + "extends": [ + "eslint:recommended" + ], + "env": { "browser": false, "es6": true, @@ -6,6 +10,15 @@ "mocha": true }, + "parserOptions":{ + "ecmaVersion": 9, + "sourceType": "module", + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true + } + }, + "globals": { "document": false, "navigator": false, diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 1fd107d..abb200f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ os: language: node_js node_js: - node + - '10' - '9' - '8' - '7' diff --git a/LICENSE b/LICENSE index f8de063..7cccaf9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2018, Jon Schlinkert. +Copyright (c) 2015-present, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/index.js b/index.js index eb39bdf..081bae5 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ /*! * parse-git-config * - * Copyright (c) 2015-2018, Jon Schlinkert. + * Copyright (c) 2015-present, Jon Schlinkert. * Released under the MIT License. */ @@ -9,13 +9,11 @@ const fs = require('fs'); const path = require('path'); +const util = require('util'); const ini = require('ini'); const configPath = require('git-config-path'); const expand = require('expand-tilde'); -const read = promisify(fs.readFile); -const stat = promisify(fs.stat); - /** * Asynchronously parse a `.git/config` file. If only the callback is passed, * the `.git/config` file relative to `process.cwd()` is used. @@ -61,23 +59,22 @@ function parse(options, callback) { * @api public */ -parse.promise = function(options) { - const opts = Object.assign({}, options); - const filepath = parse.resolveConfigPath(opts); +parse.promise = options => { + const filepath = parse.resolveConfigPath(options); + const read = util.promisify(fs.readFile); + const stat = util.promisify(fs.stat); if (!filepath) { return Promise.resolve(null); } return stat(filepath) - .then(() => { - return read(filepath, 'utf8'); - }) + .then(() => read(filepath, 'utf8')) .then(str => { - if (opts.include === true) { + if (options && options.include === true) { str = injectInclude(str, path.resolve(path.dirname(filepath))); } - return parseIni(str, opts); + return parseIni(str, options); }); }; @@ -95,7 +92,7 @@ parse.promise = function(options) { * @api public */ -parse.sync = function(options) { +parse.sync = options => { const opts = Object.assign({}, options); const filepath = parse.resolveConfigPath(opts); if (filepath && fs.existsSync(filepath)) { @@ -116,7 +113,7 @@ parse.sync = function(options) { * Resolve the git config path */ -parse.resolveConfigPath = function(options) { +parse.resolveConfigPath = options => { if (typeof options === 'string') { options = { type: options }; } @@ -129,9 +126,7 @@ parse.resolveConfigPath = function(options) { * Deprecated: use `.resolveConfigPath` instead */ -parse.resolve = function(options) { - return parse.resolveConfigPath(options); -}; +parse.resolve = options => parse.resolveConfigPath(options); /** * Returns an object with only the properties that had ini-style keys @@ -146,7 +141,7 @@ parse.resolve = function(options) { * @api public */ -parse.expandKeys = function(config) { +parse.expandKeys = config => { for (const key of Object.keys(config)) { const m = /(\S+) "(.*)"/.exec(key); if (!m) continue; @@ -173,10 +168,7 @@ function parseIni(str, options) { } function injectInclude(input, cwd) { - const lines = input.split('\n').filter(function(line) { - return line.trim() !== ''; - }); - + const lines = input.split('\n').filter(line => line.trim() !== ''); const len = lines.length; const res = []; @@ -194,22 +186,6 @@ function injectInclude(input, cwd) { return res.join('\n'); } -/** - * Wraps an arbitrary function in a Promise. - * - * @param {Function} `fn` The function to be wrapped. - */ - -function promisify(fn) { - return (...args) => { - return new Promise((resolve, reject) => { - fn(...args, (err, res) => { - err ? reject(err) : resolve(res); - }); - }); - }; -} - /** * Expose `parse` */