Giter Site home page Giter Site logo

cassels / dotpref Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 1.94 MB

Manage CLI application encrypted preferences in a stateful way.

License: MIT License

JavaScript 1.87% TypeScript 98.13%
pref prefs preferences dotpref conf config configuration store storage settings

dotpref's Introduction

.pref

Perfect for CLI application user preferences

Out of the box πŸ“¦β€΅οΈ easy application encrypted preferences πŸ‘

npm version npm license npm downloads Snyk Vulnerabilities for GitHub Repo Libraries.io dependency status for latest release GitHub commit activity code style: prettier


Highlights

  • No configuration needed βŒβš™οΈ
  • Everything is configurable βœ…βš™οΈ
  • Human-readable πŸ€“ or encrypted πŸ”

Install

npm

$ npm install --save dotpref

yarn

$ yarn add dotpref

Usage

Quick start

Out of the box simple key/value store.

import Pref from 'dotpref';

Pref.set('foo', 'bar');
console.log(Pref.get('foo'));
//=> 'bar'

Pref.set('foo', { bar: 'baz' });
console.log(Pref.get('foo'));
//=> '{ bar: "baz" } '

API

Pref

The default export of the dotpref module is a singleton instance with a default configuration.

import Pref from 'dotpref';

createPref

Creates a custom instance of dotpref with custom configuration. This method can be used if you need multiple configurations.

import { createPref } from 'dotpref';

Instance

.get

Type: (key: string) => string

Get the value assigned to key in the state.

.set

Type: (key: string, value: string) => void

Set the value of key in the state. The value must serializable by the instance's serializer. For example, using the default serializer (JSON), setting a value of type undefined, function, or symbol will result in a TypeError.

.reset

Type: (key: string) => void

Reset the value assigned to key to the default state.

.write

Type: () => void

Explicitly write to disk.

.read

Type: () => void

Explicitly read from disk to state.

.filePath

Type: readonly string

Readonly absolute path to the preference file stored on disk. This property will exist even if the preference file does not.

getDefaultCrypto

Options

defaults

Type: state

An object specifying the default values of the preference state. If preferences are found, they will override the defaults in the state. If no preferences are found, defaults will be used – state will not be written to disk upon creation. Default: {}.

name

Type: string

The name of your project. This value will be used to build the filePath of the preference file stored on disk. Default: the name property of your package.json.

filename

Type: string

The filename of the preference file stored on disk. Default: config.pref

dirPath

Type: string

Absolute path determining where the preferences should be stored on disk. Default: <system config>/<name> where <system config> is the User's default system config path and <name> is the name property configuration property;

serializer

Type: state => string

A function that specifies how the state should be serialized when written to disk. Default: JSON.stringify.

deserializer

Type: string => state

The reverse of serializer. A function that specifies how the state should be deserialized when read from disk. Default: JSON.parse.

encoder

Type: string => string

A function that specifies how the state should be encrypted. Default: getDefaultCrypto.encrypt.

decoder

Type: string => string

A function that specifies how the state should be decrypted. Default: getDefaultCrypto.decrypt.

setter

Type: (state, key, value) => void

A function that takes the existing state, the key, and the value and returns a new state to be saved to disk. The state will be saved to disk if the equality function returns false. Default: (state, key, value) => { ...state, [key]: value }.

getter

Type: (state, key) => value

Reverse of setter. A function that takes the existing state and the key and returns the value. Default: (state, key) => state[key].

equality

Type: boolean | (state, newState) => boolean

Determines the equality of the old state and the new state. This method is used to determine if the state has changed since the last write. If set to true the state will write to disk on every set. When set to false the state will never write to disk on set and therefore must explicitly be written via write.

Config Paths

For each OS below <home> is calculated using NodeJS' os.homedir().

  • macOS: <home>/Library/Preferences/<name>
  • Windows: <home>/AppData/Roaming/<name>/Config
  • Linux: <home>/.config/<name> or $XDG_CONFIG_HOME/<name>

dotpref's People

Contributors

cassels avatar dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

dotpref's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error: expecting end of expression or separator near "grou

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/onetime Unavailable
npm @types/pkg-up Unavailable
npm mem Unavailable
npm pkg-up Unavailable

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/upload-artifact v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/download-artifact v3
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • mem ^8.1.1
  • pkg-up ^3.1.0
  • write-file-atomic ^3.0.3
  • @types/jest ^28.1.8
  • @types/node ^16.11.68
  • @types/onetime ^4.0.0
  • @types/pkg-up ^3.1.0
  • @types/write-file-atomic ^3.0.3
  • @typescript-eslint/eslint-plugin ^5.41.0
  • @typescript-eslint/parser ^5.41.0
  • eslint ^8.26.0
  • eslint-config-prettier ^8.5.0
  • eslint-plugin-prettier ^4.2.1
  • jest ^28.1.3
  • prettier ^2.7.1
  • semantic-release 18.0.1
  • ts-jest ^28.0.8
  • typescript ^4.8.4

  • Check this box to trigger a request for Renovate to run again on this repository

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The release 1.0.0 on branch master cannot be published as it is out of range.

Based on the releases published on other branches, only versions within the range >=1.0.0 <1.0.0 can be published from branch master.

The following commits are responsible for the invalid release:

  • Update README.md (98d7d24)
  • feat: tidy up based on initial feedback (fa1ce91)
  • fix: update tsconfig and package.json to fix published files (4a0f1f8)
  • fix: include and exclude the correct files for publishing to npm (2b9c018)
  • chore: remove unused code and dry-run tag (56e3567)
  • chore: prepare for initial release (0366301)
  • Create LICENSE (613913f)
  • chore: correct test.yml syntax (457daff)
  • chore: update build, test, and release CI (88cb748)
  • Update ci.yml (aeba692)
  • Update ci.yml (2023991)
  • Update ci.yml (7b6ffca)
  • Update ci.yml (eca7e4f)
  • Update cd.yml (11c51aa)
  • chore: update cd file (1338488)
  • chore: add cd file (b86c8c4)
  • chore: add ci file (48c2406)
  • chore: adding semantic release (8216d29)
  • feat: adding code (f0cc660)
  • chore: initial commit (9b617a0)

Those commits should be moved to a valid branch with git merge or git cherry-pick and removed from branch master with git revert or git reset.

A valid branch could be master or next.

See the workflow configuration documentation for more details.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

List all values

Hey πŸ‘‹

I like this module a lot, it's nice and quick to use for scripts :)

It would be nice if it was possible to list all values stored. Is that something you would
accept a PR for?

Best,
Finn

Migrate to Pure ESM

Removing the support for NodeJS v10 and only supporting NodeJS v12 enables native ESM support.

2 of 3 dependencies for dotpref have migrated to pure ESM modules meaning dotpref cannot import them in its current form. Furthermore, semantic-release v19 includes ESM dependencies that yarn trips over resulting in pinning semantic-release to v18.

Currently, Jest support for ESM is experimental but even then, I couldn't get jest@27, ts-jest@27, and [email protected] to play nicely together using an ESM build. I'll revisit after jest@28 is released and try again.

Update June 22: jest@28 still only has experimental support for ESM, and I still can't get it working.

Remove support for NodeJS v10.x

NodeJS v10.x is now EOL and supporting it is becoming harder.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.