A wrapper utility for interacting with plist data.
npm install @webnativellc/simple-plistsimple-plist

A simple API for interacting with binary and plain text
plist data.
Note: This is a fork of the original but with fixes for typescript issues reported in 2021
``sh
npm install @webnativellc/simple-plist
`
Starting with version 1.4.0, you can also import simple-plist into your
deno applications through esm.sh.
`typescript`
import plist from "https://esm.sh/simple-plist@1.4.0";
`js
import * as plist from "simple-plist";
let data;
// read
data = plist.readFileSync("/path/to/some.plist");
// write xml
plist.writeFileSync("/path/to/plaintext.plist", data);
// write binary
plist.writeBinaryFileSync("/path/to/binary.plist", data);
`
> Note: all of the async examples can optionally be converted to promises using
> node's util.promisify.
`js
import * as plist from "simple-plist";
let data;
function callback(err, contents) {
if (err) throw err;
data = contents;
}
// read
plist.readFile("/path/to/some.plist", callback);
// write xml
plist.writeFile("/path/to/plaintext.plist", data, callback);
// write binary
plist.writeBinaryFile("/path/to/binary.plist", data, callback);
`
`js
const plist = require("simple-plist");
// Convert an object to a plist xml string
plist.stringify({ name: "Joe", answer: 42 });
/*
*/
`
`js
import * as plist from "simple-plist";
const xml =
;
plist.parse(xml);
// { "name": "Joe" }
`
All functions have typescript signatures, but there are a few handy generics
that are worth pointing out. Those generics belong to parse, readFile,readFileSync
and . Here's an example:
`tsx
import { parse, readFile, readFileSync } from "simple-plist";
type Profile = {
name: string;
answer: number;
};
const xml =
;
// typed string parsing
const { answer } = parse
// answer = 42;
// typed file loading
const { name } = readFileSync
``