Socket
Socket
Sign inDemoInstall

plist

Package Overview
Dependencies
3
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    plist

Apple's property list parser/builder for Node.js and browsers


Version published
Weekly downloads
2.4M
increased by2.87%
Maintainers
2
Install size
1.14 MB
Created
Weekly downloads
 

Package description

What is plist?

The plist npm package is a library for Node.js that allows users to parse and build XML Property List (plist) data. Property lists are a structured file format used primarily by macOS and iOS for storing serialized objects. The plist package provides functionality to convert between plist files and JavaScript objects, making it useful for tasks such as configuration management, data serialization, and interacting with Apple ecosystem data formats.

What are plist's main functionalities?

Parsing plist files

This feature allows you to read and parse plist files into JavaScript objects. The code sample demonstrates how to read a plist file asynchronously and parse its content.

const plist = require('plist');
const fs = require('fs');

fs.readFile('example.plist', 'utf8', function(err, data) {
  if (err) throw err;
  const parsedData = plist.parse(data);
  console.log(parsedData);
});

Building plist files

This feature allows you to create plist files from JavaScript objects. The code sample shows how to convert an object into plist format and then write it to a file.

const plist = require('plist');
const fs = require('fs');

const obj = {
  key1: 'value1',
  key2: 'value2'
};

const plistContent = plist.build(obj);

fs.writeFile('example.plist', plistContent, function(err) {
  if (err) throw err;
  console.log('Plist file has been saved!');
});

Other packages similar to plist

Readme

Source

plist.js

Apple's Property list parser/builder for Node.js and browsers

ci

Provides facilities for reading and writing Plist (property list) files. These are often used in programming OS X and iOS applications, as well as the iTunes configuration XML file.

Plist files represent stored programming "object"s. They are very similar to JSON. A valid Plist file is representable as a native JavaScript Object and vice-versa.

Usage

Node.js

Install using npm:

$ npm install --save plist

Then require() the plist module in your file:

var plist = require('plist');

// now use the `parse()` and `build()` functions
var val = plist.parse('<plist><string>Hello World!</string></plist>');
console.log(val);  // "Hello World!"

Browser

Include the dist/plist.js in a <script> tag in your HTML file:

<script src="plist.js"></script>
<script>
  // now use the `parse()` and `build()` functions
  var val = plist.parse('<plist><string>Hello World!</string></plist>');
  console.log(val);  // "Hello World!"
</script>

API

Parsing

Parsing a plist from filename:

var fs = require('fs');
var plist = require('plist');

var obj = plist.parse(fs.readFileSync('myPlist.plist', 'utf8'));
console.log(JSON.stringify(obj));

Parsing a plist from string payload:

var plist = require('plist');

var xml =
  '<?xml version="1.0" encoding="UTF-8"?>' +
  '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' +
  '<plist version="1.0">' +
    '<key>metadata</key>' +
    '<dict>' +
      '<key>bundle-identifier</key>' +
      '<string>com.company.app</string>' +
      '<key>bundle-version</key>' +
      '<string>0.1.1</string>' +
      '<key>kind</key>' +
      '<string>software</string>' +
      '<key>title</key>' +
      '<string>AppName</string>' +
    '</dict>' +
  '</plist>';

console.log(plist.parse(xml));

// [
//   "metadata",
//   {
//     "bundle-identifier": "com.company.app",
//     "bundle-version": "0.1.1",
//     "kind": "software",
//     "title": "AppName"
//   }
// ]

Building

Given an existing JavaScript Object, you can turn it into an XML document that complies with the plist DTD:

var plist = require('plist');

var json = [
  "metadata",
  {
    "bundle-identifier": "com.company.app",
    "bundle-version": "0.1.1",
    "kind": "software",
    "title": "AppName"
  }
];

console.log(plist.build(json));

// <?xml version="1.0" encoding="UTF-8"?>
// <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
// <plist version="1.0">
//   <key>metadata</key>
//   <dict>
//     <key>bundle-identifier</key>
//     <string>com.company.app</string>
//     <key>bundle-version</key>
//     <string>0.1.1</string>
//     <key>kind</key>
//     <string>software</string>
//     <key>title</key>
//     <string>AppName</string>
//   </dict>
// </plist>

Cross Platform Testing Credits

Much thanks to Sauce Labs for providing free resources that enable cross-browser testing on this project!

Testing Powered By SauceLabs

License

(The MIT License)

Keywords

FAQs

Last updated on 06 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc