simple-plist utility

1.3.1 · active · verified Sun Apr 19

simple-plist is a wrapper utility for interacting with Apple Property List (plist) data, supporting both binary and XML formats. The current stable version is 1.3.1. While its release cadence is not rapid, the package demonstrates active maintenance, as evidenced by the recent v1.3.0 rewrite into TypeScript to provide strong typing. It offers a straightforward API for reading and writing plist files synchronously and asynchronously, as well as in-memory parsing and stringification. This package serves as a convenient abstraction over lower-level plist parsing libraries, making it easier to manage `.plist` files commonly found in macOS and iOS environments, without requiring direct interaction with the underlying `plist` or `bplist` packages.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to write a JavaScript object to a plist file and then read it back, using synchronous file operations and TypeScript types.

import { writeFileSync, readFileSync } from 'simple-plist';
import * as path from 'path';
import * as fs from 'fs';

const tempFilePath = path.join(process.cwd(), 'temp.plist');

type AppConfig = {
  appName: string;
  version: string;
  debugMode: boolean;
  settings: { theme: string; language: string };
};

const config: AppConfig = {
  appName: 'MyAwesomeApp',
  version: '1.0.0',
  debugMode: true,
  settings: { theme: 'dark', language: 'en-US' },
};

try {
  // Write the object to an XML plist file
  writeFileSync(tempFilePath, config);
  console.log('Plist file written successfully:', tempFilePath);

  // Read the plist file back into an object
  const readConfig = readFileSync(tempFilePath) as AppConfig;
  console.log('Plist file read successfully:', readConfig);
  console.log('App Name:', readConfig.appName);
  console.log('Version:', readConfig.version);
} catch (error) {
  console.error('An error occurred:', error);
} finally {
  // Clean up the temporary file
  if (fs.existsSync(tempFilePath)) {
    fs.unlinkSync(tempFilePath);
    console.log('Temporary plist file cleaned up.');
  }
}

view raw JSON →