simple-plist

A simple API for interacting with binary and plain text
plist data.
Installation
npm install simple-plist
yarn add simple-plist
Synchronous API
const plist = require("simple-plist");
let data;
data = plist.readFileSync("/path/to/some.plist");
plist.writeFileSync("/path/to/plaintext.plist", data);
plist.writeBinaryFileSync("/path/to/binary.plist", data);
Asynchronous API
Note: all of the async examples can optionally be converted to promises using
node's util.promisify.
const plist = require("simple-plist");
let data;
function callback(err, contents) {
if (err) throw err;
data = contents;
}
plist.readFile("/path/to/some.plist", callback);
plist.writeFile("/path/to/plaintext.plist", data, callback);
plist.writeBinaryFile("/path/to/binary.plist", data, callback);
In Memory
plist.stringify()
const plist = require("simple-plist");
plist.stringify({ name: "Joe", answer: 42 });
plist.parse()
const plist = require("simple-plist");
const xml = `<plist>
<dict>
<key>name</key>
<string>Joe</string>
</dict>
</plist>`;
plist.parse(xml);
TypeScript Support
All functions have typescript signatures, but there are a few handy generics
that are worth pointing out. Those generics belong to parse, readFile,
and readFileSync. Here's an example:
import { parse, readFile, readFileSync } from "simple-plist";
type Profile = {
name: string;
answer: number;
};
const xml = `<plist>
<dict>
<key>name</key>
<string>Joe</string>
<key>answer</key>
<integer>42</integer>
</dict>
</plist>`;
const { answer } = parse<Profile>(xml);
const { name } = readFileSync<Profile>("/path/to/profile.plist");