npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dotpref

v2.0.4

Published

Perfect for CLI application user preferences.

Downloads

24

Readme

.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>