Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cf-prefs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-prefs - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

8

index.d.ts
// Type definitions for cf-prefs
// Project: cf-prefs
export function getPreferenceValue(key: string, type: 'string'): string | undefined;
export function getPreferenceValue(key: string, type: 'string', defaultValue: string): string;
export function getPreferenceValue(key: string, type: 'integer'): number | undefined;
export function getPreferenceValue(key: string, type: 'integer', defaultValue: number): number;
export function getPreferenceValue(key: string, type: 'boolean'): boolean | undefined;
export function getPreferenceValue(key: string, type: 'boolean', defaultValue: boolean): boolean;
export type CFPrefValue = boolean | number | string | Array<CFPrefValue> | Record<string, CFPrefValue> | undefined;
export function getPreferenceValue(key: string): CFPrefValue;
export function isPreferenceForced(key: string): boolean;
const preferences = require('bindings')('cf-prefs.node');
function maybeWithDefault(value, defaultValue) {
if (value === undefined && defaultValue !== undefined) {
return defaultValue;
}
return value;
}
function getPreferenceValue(key, type, defaultValue) {
switch (type) {
case 'string':
return maybeWithDefault(preferences.getString(key), defaultValue);
case 'integer':
return maybeWithDefault(preferences.getInteger(key), defaultValue);
case 'boolean':
return maybeWithDefault(preferences.getBoolean(key), defaultValue);
default:
throw new Error(`Unsupported preference type "${type}"`);
}
}
module.exports = {
getPreferenceValue,
getPreferenceValue: preferences.getValue,
isPreferenceForced: preferences.isPreferenceForced,
};
{
"name": "cf-prefs",
"version": "1.0.0",
"version": "2.0.0",
"description": "A native node module to access managed app preferences on macOS",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,12 +14,9 @@ [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)

## `prefs.getPreferenceValue(key, type)`
## `prefs.getPreferenceValue(key)`
* `key` String - The preference key to fetch the value of, has to be a valid UTF-8 string.
* `type` String - The data-type of the preference you are fetching. Can be one of `string`, `integer` or `boolean`.
* `defaultValue` String | Integer | Boolean (Optional) - If no value is present this value will be returned instead, if no default value is provided this method may return `undefined`.
Returns `String` | `Integer` | `Boolean` | `undefined` - Depending on the requested type, see [the type definitions](./index.d.ts) for a more accurate mapping.
Returns `String` | `Integer` | `Boolean` | `Object` | `Array` | `undefined`
**Notes:**
* If the preference is available but in a different type you will not receive an error, you will receive `undefined`.
* If the preference is not available you will receive `undefined`.

@@ -29,3 +26,3 @@

```js
console.log('Preference Value:', prefs.getPreferenceValue('MyAppsCoolPreference', 'string', 'this-is-the-default'))
console.log('My Preference Value:', prefs.getPreferenceValue('MyAppsCoolPreference'))
```

@@ -32,0 +29,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc