Socket
Socket
Sign inDemoInstall

cosmiconfig

Package Overview
Dependencies
9
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.1.0

4

CHANGELOG.md
# Changelog
## 3.1.0
- Added: infer format based on filePath
## 3.0.1

@@ -4,0 +8,0 @@

@@ -8,2 +8,3 @@ //

const parseJson = require('./parseJson');
const path = require('path');

@@ -23,3 +24,4 @@ module.exports = function loadDefinedFile(

let parsedConfig;
switch (options.format) {
switch (options.format || inferFormat(filepath)) {
case 'json':

@@ -55,2 +57,17 @@ parsedConfig = parseJson(content, filepath);

function inferFormat(filepath ) {
switch (path.extname(filepath)) {
case '.js':
return 'js';
case '.json':
return 'json';
// istanbul ignore next
case '.yml':
case '.yaml':
return 'yaml';
default:
return undefined;
}
}
function tryAllParsing(content , filepath ) {

@@ -57,0 +74,0 @@ return tryYaml(content, filepath, () => {

2

package.json
{
"name": "cosmiconfig",
"version": "3.0.1",
"version": "3.1.0",
"description": "Find and load configuration from a package.json property, rc file, or CommonJS module",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -6,12 +6,12 @@ # cosmiconfig

Find and load a configuration object from
- a `package.json` property (anywhere down the file tree)
- a JSON or YAML "rc file" (anywhere down the file tree)
- a `.config.js` CommonJS module (anywhere down the file tree)
- a `package.json` property (anywhere up the directory tree)
- a JSON or YAML "rc file" (anywhere up the directory tree)
- a `.config.js` CommonJS module (anywhere up the directory tree)
For example, if your module's name is "soursocks," cosmiconfig will search out configuration in the following places:
- a `soursocks` property in `package.json` (anywhere down the file tree)
- a `.soursocksrc` file in JSON or YAML format (anywhere down the file tree)
- a `soursocks.config.js` file exporting a JS object (anywhere down the file tree)
- a `soursocks` property in `package.json` (anywhere up the directory tree)
- a `.soursocksrc` file in JSON or YAML format (anywhere up the directory tree)
- a `soursocks.config.js` file exporting a JS object (anywhere up the directory tree)
cosmiconfig continues to search in these places all the way down the file tree until it finds acceptable configuration (or hits the home directory).
cosmiconfig continues to search in these places all the way up the directory tree until it finds acceptable configuration (or hits the home directory).

@@ -59,3 +59,3 @@ Additionally, all of these search locations are configurable: you can customize filenames or turn off any location.

3. A `goldengrahams.config.js` JS file exporting the object (or some other filename defined by `options.js`).
- If none of those searches reveal a configuration object, it moves down one directory and tries again. So the search continues in `./`, `../`, `../../`, `../../../`, etc., checking those three locations in each directory.
- If none of those searches reveal a configuration object, it moves up one directory level and tries again. So the search continues in `./`, `../`, `../../`, `../../../`, etc., checking those three locations in each directory.
- It continues searching until it arrives at your home directory (or some other directory defined by `options.stopDir`).

@@ -186,2 +186,11 @@ - If at any point a parseable configuration is found, the `cosmiconfig()` Promise resolves with its result object.

##### format
Type: `'json' | 'yaml' | 'js'`
The expected file format for the config loaded from `configPath`.
If not specified, cosmiconfig will try to infer the format using the extension name (if it has one).
In the event that the file does not have an extension or the extension is unrecognized, cosmiconfig will try to parse it as a JSON, YAML, or JS file.
### Instance methods (on `explorer`)

@@ -204,5 +213,5 @@

If you provide `searchPath`, cosmiconfig will start its search at `searchPath` and continue to search up the file tree, as documented above.
If you provide `searchPath`, cosmiconfig will start its search at `searchPath` and continue to search up the directory tree, as documented above.
If you provide `configPath` (i.e. you already know where the configuration is that you want to load), cosmiconfig will try to read and parse that file.
If you provide `configPath` (i.e. you already know where the configuration is that you want to load), cosmiconfig will try to read and parse that file. Note that the [`format` option](#format) is applicable for this as well.

@@ -227,3 +236,3 @@ #### `clearFileCache()`

- Built-in support for JSON, YAML, and CommonJS formats.
- Stops at the first configuration found, instead of finding all that can be found down the filetree and merging them automatically.
- Stops at the first configuration found, instead of finding all that can be found up the directory tree and merging them automatically.
- Options.

@@ -230,0 +239,0 @@ - Asynchronous by default (though can be run synchronously).

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc