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

conf

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conf - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

47

index.d.ts

@@ -128,2 +128,40 @@ /// <reference types="node"/>

readonly projectSuffix?: string;
/**
Access nested properties by dot notation.
@default true
@example
```
const config = new Conf();
config.set({
foo: {
bar: {
foobar: 'πŸ¦„'
}
}
});
console.log(config.get('foo.bar.foobar'));
//=> 'πŸ¦„'
```
Alternatively, you can set this option to `false` so the whole string would be treated as one key.
@example
```
const config = new Conf({accessPropertiesByDotNotation: false});
config.set({
`foo.bar.foobar`: 'πŸ¦„'
});
console.log(config.get('foo.bar.foobar'));
//=> 'πŸ¦„'
```
*/
readonly accessPropertiesByDotNotation?: boolean;
}

@@ -216,2 +254,11 @@ }

/**
Watches the whole config object, calling `callback` on any changes.
@param callback - A callback function that is called on any changes. When a `key` is first set `oldValue` will be `undefined`, and when a key is deleted `newValue` will be `undefined`.
*/
onDidAnyChange(
callback: (oldValue: {[key: string]: T} | undefined, newValue: {[key: string]: T} | undefined) => void
): () => void;
[Symbol.iterator](): IterableIterator<[string, T]>;

@@ -218,0 +265,0 @@ }

46

index.js

@@ -45,2 +45,3 @@ /* eslint-disable node/no-deprecated-api */

deserialize: JSON.parse,
accessPropertiesByDotNotation: true,
...options

@@ -116,3 +117,7 @@ };

get(key, defaultValue) {
return dotProp.get(this.store, key, defaultValue);
if (this._options.accessPropertiesByDotNotation) {
return dotProp.get(this.store, key, defaultValue);
}
return key in this.store ? this.store[key] : defaultValue;
}

@@ -133,3 +138,7 @@

checkValueType(key, value);
dotProp.set(store, key, value);
if (this._options.accessPropertiesByDotNotation) {
dotProp.set(store, key, value);
} else {
store[key] = value;
}
};

@@ -150,3 +159,7 @@

has(key) {
return dotProp.has(this.store, key);
if (this._options.accessPropertiesByDotNotation) {
return dotProp.has(this.store, key);
}
return key in this.store;
}

@@ -156,3 +169,8 @@

const {store} = this;
dotProp.delete(store, key);
if (this._options.accessPropertiesByDotNotation) {
dotProp.delete(store, key);
} else {
delete store[key];
}
this.store = store;

@@ -174,7 +192,23 @@ }

let currentValue = this.get(key);
const getter = () => this.get(key);
return this.handleChange(getter, callback);
}
onDidAnyChange(callback) {
if (typeof callback !== 'function') {
throw new TypeError(`Expected \`callback\` to be of type \`function\`, got ${typeof callback}`);
}
const getter = () => this.store;
return this.handleChange(getter, callback);
}
handleChange(getter, callback) {
let currentValue = getter();
const onChange = () => {
const oldValue = currentValue;
const newValue = this.get(key);
const newValue = getter();

@@ -181,0 +215,0 @@ try {

10

package.json
{
"name": "conf",
"version": "4.0.2",
"version": "4.1.0",
"description": "Simple config handling for your app or module",

@@ -48,13 +48,13 @@ "license": "MIT",

"pkg-up": "^3.0.1",
"write-file-atomic": "^2.4.2"
"write-file-atomic": "^3.0.0"
},
"devDependencies": {
"@types/node": "^11.13.4",
"@types/node": "^12.0.4",
"ava": "^1.4.1",
"clear-module": "^3.2.0",
"del": "^4.1.0",
"tempy": "^0.2.1",
"tsd": "^0.7.2",
"tempy": "^0.3.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
}
}

@@ -16,7 +16,3 @@ # conf [![Build Status](https://travis-ci.org/sindresorhus/conf.svg?branch=master)](https://travis-ci.org/sindresorhus/conf)

<a href="https://www.patreon.com/sindresorhus">
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
</a>
## Usage

@@ -192,2 +188,37 @@

#### accessPropertiesByDotNotation
Type: `boolean`<br>
Default: `true`
Accessing nested properties by dot notation. For example:
```js
const config = new Conf();
config.set({
foo: {
bar: {
foobar: 'πŸ¦„'
}
}
});
console.log(config.get('foo.bar.foobar'));
//=> 'πŸ¦„'
```
Alternatively, you can set this option to `false` so the whole string would be treated as one key.
```js
const config = new Conf({accessPropertiesByDotNotation: false});
config.set({
`foo.bar.foobar`: 'πŸ¦„'
});
console.log(config.get('foo.bar.foobar'));
//=> 'πŸ¦„'
```
### Instance

@@ -231,2 +262,8 @@

#### .onDidAnyChange(callback)
`callback`: `(newValue, oldValue) => {}`
Watches the whole config object, calling `callback` on any changes. `oldValue` and `newValue` will be the config object before and after the change, respectively. You must compare `oldValue` to `newValue` to find out what changed.
#### .size

@@ -233,0 +270,0 @@

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