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

airdcpp-extension-settings

v1.2.1

Published

Settings management library for AirDC++ JavaScript extensions

Downloads

2,629

Readme

airdcpp-extension-settings-js Travis npm package

Settings management module for AirDC++ JavaScript extensions.

See the example extensions and the airdcpp-create-extension starter project for actual usage examples.

Features

  • Keeping the config data in sync with the API
  • Loading and saving of settings on disk
  • Versioning and data migrations

Usage

Constructor

SettingsManager(socket, options)

Arguments

socket (object, required)

Instance of airdcpp-apisocket used by the extension.

options (object, required)

| Name | Type | Required | Description | :--- | :--- | :--- | :--- | | extensionName | string | ✓ | Name of the extension as it's registered in the application | | configFile | string | ✓ | Full path of the config file that should be used for storing the settings | | configVersion | number | ✓ | Config data version (positive integer). See the load method for information about possible migration handling. | | definitions | array[object] | ✓ | Setting definitions (see AirDC++ Web API docs for more information)|

load

load(dataMigrationCallback)

Loads possible previously saved settings and registers them with the API.

Arguments

dataMigrationCallback (function, optional)

Function that will handle possible settings migration from older version formats. If no callback is specified, loaded settings will be used regardless of their version.

The function will be called only if the loaded settings version doesn't match with the current one. Errors should be thrown if settings could not be loaded.

Usage example

// Settings migration callback
const migrate = (loadedConfigVersion, loadedData) => {
  if (loadedConfigVersion <= 1) {
    throw `Migration for settings version ${loadedConfigVersion} is not supported`;
  }

  if (loadedConfigVersion === 2) {
    // Perform the required conversions
    return Object.keys(loadedData).reduce((reduced, key) => {
      if (key === 'message_type' && loadedData[key] === 'private') {
        // The value 'private' has been renamed to 'private_chat'
        reduced[key] = 'private_chat';
      } else {
        reduced[key] = loadedData[key];
      }

      return reduced;
    }, {})
  }

  // Return as it is
  return loadedData;
};

// Load
await settings.load(migrate);

Return value

Promise that will return after all tasks have been completed.

getValue

getValue(key)

Returns the current setting value.

Usage example

const showSpam = settings.getValue('show_spam');

setValue

setValue(key, value)

Update value of the setting.

Return value

Promise that will be resolved after the value has been updated in the API.

Usage example

try {
  await settings.setValue('show_spam', false);
} catch (err) {
  socket.logger.error(`Failed to update settings value: ${err.message}`);
}

onValuesUpdated

onValuesUpdated(callback)

Set listener for updated setting values.

The callback function will receive the updated settings value object (settingKey -> newValue) an argument (it won't contain unchanged values). The listener will also be fired during initial loading with all loaded settings.

Usage example

settings.onValuesUpdated = updatedValues => {
	if (updatedValues.hasOwnProperty('search_interval')) {
		resetSearchInterval();
	}
};