# preferences

> Manage CLI application encrypted preferences.

Latest version **2.0.2** (published 2020-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install preferences
pnpm add preferences
yarn add preferences
bun add preferences
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2020-04-07 |
| First published | 2015-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | Stefano Azzolini |
| Maintainers | caffeina.dev, kopiro |
| Keywords | config, cli, preferences, encrypted, secure |

## Links

- npm: https://www.npmjs.com/package/preferences
- Repository: https://github.com/CaffeinaLab/preferences
- Homepage: https://github.com/CaffeinaLab/preferences#readme
- Issues: https://github.com/CaffeinaLab/preferences/issues
- npm.io page: https://npm.io/package/preferences

## Dependencies (1)

- [yaml](https://npm.io/package/yaml.md) ^1.6.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2020-04-07
- 1.0.2 — 2017-11-28
- 1.0.1 — 2017-11-16
- 1.0.0 — 2017-11-10
- 0.2.1 — 2015-09-16
- 0.2.0 — 2015-09-15
- 0.1.6 — 2015-09-15
- 0.1.5 — 2015-09-15
- 0.1.4 — 2015-09-15
- 0.1.3 — 2015-09-15
- 0.1.2 — 2015-09-15
- 0.1.1 — 2015-09-15
- 0.1.0 — 2015-09-15

## README

# Preferences

![NPM version](https://img.shields.io/npm/dm/preferences.svg)
![NPM downloads](https://img.shields.io/npm/dt/preferences.svg)

Node.JS Module for handling **encrypted** user preferences.

Designed for CLI applications.

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

## Installation

[![NPM](https://nodei.co/npm/preferences.png)](https://npmjs.org/package/preferences)

```sh
npm install --save preferences
```

## Usage

```js
var Preferences = require("preferences");

// Init preference file with an unique identifier and an optional default data
var prefs = new Preferences('com.your.app.identifier',{
  account: {
    username: 'MrRobot',
    password: 'fsociety'
  },
  test: {
    cycles: 1
  }
});

// Preferences can be accessed directly
prefs.test.cycles++;

console.log(prefs);
```

Preferences are automatically saved on disk before process exit.

## Options
### Encryption
Encryption uses your private ssh key if founded, otherwise it will automatically use an identifier dependant generated password.

You can override the default key path in the options:

```js
var prefs = new Preferences('com.foo.bar',{}, {
  key: '~/certs/my-custom-key.pem'
});
```

You can disable encryption for plain text preferences by setting encrypt to false.
```js
var prefs = new Preferences('com.foo.bar',{}, {
  encrypt: false
});
```

### Location
The preference file defaults to being saved in ~/.config/preferences/IDENTIFIER.pref. For example, the following would create ```~/.config/preferences/com.foo.bar.pref```.

```js
var prefs = new Preferences('com.foo.bar');
```

### Human Editable
You can use the format option to specify the format for serialization. The supported types are ```json``` and ```yaml```. This option is most useful when disabling encryption as it provides a human editable file.

```js
var prefs = new Preferences('com.foo.bar',{}, {
  encrypt: false,
  file: path.join(path.dirname(process.cwd()), '.foo'),
  format: 'yaml'
});
```

## License

MIT. Copyright (c) 2015 Caffeina.

---
_Source: https://npm.io/package/preferences · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
