Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

package-config

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

package-config - npm Package Compare versions

Comparing version 0.1.0 to 5.0.0

index.d.ts

91

index.js

@@ -1,40 +0,55 @@

var path = require('path');
var fs = require('fs');
var PackageConfig = {
load: function(packageFile) {
if (packageFile === undefined) {
packageFile = this.getStandardPackageFile();
}
// sets default NODE_ENV to development if not defined
if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = 'development';
}
try {
var packageContent = fs.readFileSync(packageFile);
var parsed = JSON.parse(packageContent);
if (typeof parsed.config === "object") {
var expectedConfig = parsed.config[process.env.NODE_ENV];
if (expectedConfig !== undefined && typeof expectedConfig === "object") {
return expectedConfig;
} else {
throw new Error('package.json does not have config information');
}
} else {
throw new Error('package.json does not have config information');
}
} catch(err) {
throw new Error('Error loading package.json file: ' + err.message);
}
},
/**
* Returns the package.json that is in the same dir of the file that required fhis module
* @return {String} the expected package.json file location.
*/
getStandardPackageFile: function () {
var requester = module.parent.filename;
return path.dirname(requester) + "/package.json";
import path from 'node:path';
import {findUp, findUpSync} from 'find-up-simple';
import {loadJsonFile, loadJsonFileSync} from 'load-json-file';
}
const filePaths = new WeakMap();
const findNextCwd = packagePath => path.resolve(path.dirname(packagePath), '..');
const addFilePath = (object, filePath) => {
filePaths.set(object, filePath);
return object;
};
module.exports = PackageConfig;
export async function packageConfig(namespace, options = {}) {
if (!namespace) {
throw new TypeError('Expected a namespace');
}
const filePath = await findUp('package.json', options.cwd ? {cwd: options.cwd} : {});
if (!filePath) {
return addFilePath({...options.defaults}, filePath);
}
const packageJson = await loadJsonFile(filePath);
if (options.skipOnFalse && packageJson[namespace] === false) {
return packageConfig(namespace, {...options, cwd: findNextCwd(filePath)});
}
return addFilePath({...options.defaults, ...packageJson[namespace]}, filePath);
}
export function packageConfigSync(namespace, options = {}) {
if (!namespace) {
throw new TypeError('Expected a namespace');
}
const filePath = findUpSync('package.json', options.cwd ? {cwd: options.cwd} : {});
if (!filePath) {
return addFilePath({...options.defaults}, filePath);
}
const packageJson = loadJsonFileSync(filePath);
if (options.skipOnFalse && packageJson[namespace] === false) {
return packageConfigSync(namespace, {...options, cwd: findNextCwd(filePath)});
}
return addFilePath({...options.defaults, ...packageJson[namespace]}, filePath);
}
export function packageJsonPath(config) {
return filePaths.get(config);
}
{
"name": "package-config",
"version": "0.1.0",
"description": "Node.js config loader based on package.json file.",
"main": "index.js",
"scripts": {
"test": "mocha test -R spec --colors --bail"
},
"repository": {
"type": "git",
"url": "https://github.com/leorossi/node-package-config.git"
},
"keywords": [
"package.json",
"config",
"environments"
],
"author": "Leonardo Rossi <leonardo.rossi@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/leorossi/node-package-config/issues"
},
"homepage": "https://github.com/leorossi/node-package-config",
"devDependencies": {
"should": "^4.4.2"
}
"name": "package-config",
"version": "5.0.0",
"description": "Get namespaced config from the closest package.json",
"license": "MIT",
"repository": "sindresorhus/package-config",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"json",
"read",
"parse",
"file",
"fs",
"graceful",
"load",
"package",
"config",
"configuration",
"object",
"namespace",
"namespaced"
],
"dependencies": {
"find-up-simple": "^1.0.0",
"load-json-file": "^7.0.1"
},
"devDependencies": {
"ava": "^5.3.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
},
"fixture": {
"foo": true
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc