application-config
Advanced tools
+62
| # Node.js Application Config | ||
| Store your applications config where the operating system wants you to. | ||
| ## Installation | ||
| ```sh | ||
| npm install --save application-config | ||
| ``` | ||
| ## Usage | ||
| ```js | ||
| import createApplicationConfig from 'application-config' | ||
| const cfg = createApplicationConfig('App Name') | ||
| // Read the stored data | ||
| const data = await cfg.read() | ||
| // Write new config | ||
| await cfg.write({ n: 1337 }) | ||
| // Trash the stored config | ||
| await cfg.trash() | ||
| ``` | ||
| ## API | ||
| ### `createApplicationConfig(name)` | ||
| Creates and return a new instance with the provided name. | ||
| ### `cfg.read()` | ||
| Read the stored configuration. Returns a Promise that settles with the data. | ||
| ### `cfg.write(data)` | ||
| Write new configuration. Returns a Promise. | ||
| ### `cfg.trash()` | ||
| Remove the stored configuration. Returns a Promise. | ||
| ### `cfg.filePath` | ||
| The path to the underlying file in which the configuration is stored. | ||
| ## Config location | ||
| Platform | Location | ||
| --- | --- | ||
| OS X | `~/Library/Application Support/<name>/config.json` | ||
| Linux (XDG) | `$XDG_CONFIG_HOME/<name>/config.json` | ||
| Linux (Legacy) | `~/.config/<name>/config.json` | ||
| Windows (> Vista) | `%LOCALAPPDATA%/<name>/config.json` | ||
| Windows (XP, 2000) | `%USERPROFILE%/Local Settings/Application Data/<name>/config.json` | ||
| ## License | ||
| MIT |
+1
-2
@@ -8,3 +8,2 @@ declare class ApplicationConfig { | ||
| declare function createApplicationConfig (mame: String): ApplicationConfig | ||
| export = createApplicationConfig | ||
| export default function createApplicationConfig (mame: String): ApplicationConfig |
+8
-13
@@ -1,11 +0,8 @@ | ||
| const fs = require('fs') | ||
| const path = require('path') | ||
| const { promisify } = require('util') | ||
| import fs from 'node:fs/promises' | ||
| import path from 'node:path' | ||
| const applicationConfigPath = require('application-config-path') | ||
| const loadJsonFile = require('load-json-file') | ||
| import applicationConfigPath from 'application-config-path' | ||
| import { loadJsonFile } from 'load-json-file' | ||
| import { writeJsonFile } from 'write-json-file' | ||
| const rmdir = promisify(fs.rmdir) | ||
| const unlink = promisify(fs.unlink) | ||
| class ApplicationConfig { | ||
@@ -30,4 +27,2 @@ constructor (name) { | ||
| const writeJsonFile = require('write-json-file') | ||
| await writeJsonFile(this.filePath, data) | ||
@@ -38,4 +33,4 @@ } | ||
| try { | ||
| await unlink(this.filePath) | ||
| await rmdir(path.dirname(this.filePath)) | ||
| await fs.unlink(this.filePath) | ||
| await fs.rmdir(path.dirname(this.filePath)) | ||
| } catch (err) { | ||
@@ -48,4 +43,4 @@ if (err.code === 'ENOENT') return | ||
| module.exports = function createApplicationConfig (name) { | ||
| export default function createApplicationConfig (name) { | ||
| return new ApplicationConfig(name) | ||
| } |
+1
-1
| The MIT License (MIT) | ||
| Copyright (c) 2014 Linus Unnebäck | ||
| Copyright (c) 2014, 2023 Linus Unnebäck | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
+9
-8
| { | ||
| "name": "application-config", | ||
| "version": "2.0.0", | ||
| "version": "3.0.0", | ||
| "license": "MIT", | ||
| "repository": "LinusU/node-application-config", | ||
| "type": "module", | ||
| "exports": "./index.js", | ||
| "files": [ | ||
@@ -14,14 +16,13 @@ "index.d.ts", | ||
| "dependencies": { | ||
| "application-config-path": "^0.1.0", | ||
| "load-json-file": "^6.2.0", | ||
| "write-json-file": "^4.2.0" | ||
| "application-config-path": "^1.0.0", | ||
| "load-json-file": "^7.0.1", | ||
| "write-json-file": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "assert-rejects": "^1.0.0", | ||
| "mocha": "^6.2.2", | ||
| "standard": "^14.3.1" | ||
| "mocha": "^10.2.0", | ||
| "standard": "^17.0.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=8.3" | ||
| "node": "^14.18.0 || ^16.14.0 || >=18.0.0" | ||
| } | ||
| } |
-60
| # Node.js Application Config | ||
| Store your applications config where the operating system wants you to. | ||
| ## Installation | ||
| ```sh | ||
| npm install --save application-config | ||
| ``` | ||
| ## Usage | ||
| ```js | ||
| var cfg = require('application-config')('App Name') | ||
| // Read the stored data | ||
| const data = await cfg.read() | ||
| // Write new config | ||
| await cfg.write({ n: 1337 }) | ||
| // Trash the stored config | ||
| await cfg.trash() | ||
| ``` | ||
| ## API | ||
| ### `applicationConfig(name)` | ||
| Creates and return a new instance with the provided name. | ||
| ### `cfg.read()` | ||
| Read the stored configuration. Returns a Promise that settles with the data. | ||
| ### `cfg.write(data)` | ||
| Write new configuration. Returns a Promise. | ||
| ### `cfg.trash()` | ||
| Remove the stored configuration. Returns a Promise. | ||
| ### `cfg.filePath` | ||
| The path to the underlying file in which the configuration is stored. | ||
| ## Config location | ||
| Platform | Location | ||
| --- | --- | ||
| OS X | `~/Library/Application Support/<name>/config.json` | ||
| Linux (XDG) | `$XDG_CONFIG_HOME/<name>/config.json` | ||
| Linux (Legacy) | `~/.config/<name>/config.json` | ||
| Windows (> Vista) | `%LOCALAPPDATA%/<name>/config.json` | ||
| Windows (XP, 2000) | `%USERPROFILE%/Local Settings/Application Data/<name>/config.json` | ||
| ## License | ||
| MIT |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
-33.33%63
3.28%1
-50%Yes
NaN4111
-0.6%43
-8.51%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated