diff options
author | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-06-04 08:51:19 +0200 |
commit | b22f6770c8bd084d66950655203c61dd701b3d90 (patch) | |
tree | 873d7fb19584ec2709b95cc1ca05a1fc7cfd0fc4 /node_modules/configstore/index.js | |
parent | 383285ecd5292bf9a825e05904955b937de84cc9 (diff) | |
download | equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.gz equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.bz2 equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.zip |
Remove node_modules
Diffstat (limited to 'node_modules/configstore/index.js')
-rw-r--r-- | node_modules/configstore/index.js | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/node_modules/configstore/index.js b/node_modules/configstore/index.js deleted file mode 100644 index 561dbdd..0000000 --- a/node_modules/configstore/index.js +++ /dev/null @@ -1,109 +0,0 @@ -'use strict'; -const path = require('path'); -const os = require('os'); -const fs = require('graceful-fs'); -const makeDir = require('make-dir'); -const xdgBasedir = require('xdg-basedir'); -const writeFileAtomic = require('write-file-atomic'); -const dotProp = require('dot-prop'); -const uniqueString = require('unique-string'); - -const configDirectory = xdgBasedir.config || path.join(os.tmpdir(), uniqueString()); -const permissionError = 'You don\'t have access to this file.'; -const makeDirOptions = {mode: 0o0700}; -const writeFileOptions = {mode: 0o0600}; - -class Configstore { - constructor(id, defaults, options = {}) { - const pathPrefix = options.globalConfigPath ? - path.join(id, 'config.json') : - path.join('configstore', `${id}.json`); - - this.path = options.configPath || path.join(configDirectory, pathPrefix); - - if (defaults) { - this.all = { - ...defaults, - ...this.all - }; - } - } - - get all() { - try { - return JSON.parse(fs.readFileSync(this.path, 'utf8')); - } catch (error) { - // Create directory if it doesn't exist - if (error.code === 'ENOENT') { - return {}; - } - - // Improve the message of permission errors - if (error.code === 'EACCES') { - error.message = `${error.message}\n${permissionError}\n`; - } - - // Empty the file if it encounters invalid JSON - if (error.name === 'SyntaxError') { - writeFileAtomic.sync(this.path, '', writeFileOptions); - return {}; - } - - throw error; - } - } - - set all(value) { - try { - // Make sure the folder exists as it could have been deleted in the meantime - makeDir.sync(path.dirname(this.path), makeDirOptions); - - writeFileAtomic.sync(this.path, JSON.stringify(value, undefined, '\t'), writeFileOptions); - } catch (error) { - // Improve the message of permission errors - if (error.code === 'EACCES') { - error.message = `${error.message}\n${permissionError}\n`; - } - - throw error; - } - } - - get size() { - return Object.keys(this.all || {}).length; - } - - get(key) { - return dotProp.get(this.all, key); - } - - set(key, value) { - const config = this.all; - - if (arguments.length === 1) { - for (const k of Object.keys(key)) { - dotProp.set(config, k, key[k]); - } - } else { - dotProp.set(config, key, value); - } - - this.all = config; - } - - has(key) { - return dotProp.has(this.all, key); - } - - delete(key) { - const config = this.all; - dotProp.delete(config, key); - this.all = config; - } - - clear() { - this.all = {}; - } -} - -module.exports = Configstore; |