preferences
Manage CLI application encrypted preferences.
Last updated 3 months ago by kopiro .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install preferences 
SYNC missed versions from official npm registry.

Preferences

NPM version NPM downloads

Node.JS Module for handling encrypted user preferences.

Designed for CLI applications.

js-standard-style

Installation

NPM

npm install --save preferences

Usage

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:

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.

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.

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.

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.

Current Tags

  • 2.0.2                                ...           latest (3 months ago)

13 Versions

  • 2.0.2                                ...           3 months ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 1
This Week 10
This Month 106
Last Day 9
Last Week 52
Last Month 122
Dependencies (1)
Dev Dependencies (0)
None
Dependents (197)

Copyright 2014 - 2017 © taobao.org |