Package Exports
- simple-plist
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-plist) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-simple-plist
A simple API for interacting with binary and plain text plist data.
Installation
# with yarn
yarn add simple-plist
# or with npm
npm install simple-plist
Reading Data
import Plist from "simple-plist";
async function foo() {
const data = await Plist.read("/path/to/some.plist");
console.log(data);
}
Writing Data
import Plist from "simple-plist";
async function foo() {
const myPlist = { foo: "bar" };
// Write data to xml file
await Plist.write({
file: "/path/to/xml.plist",
input: myPlist,
});
// Write data to binary file
await Plist.write({
binary: true,
file: "/path/to/xml.plist",
input: myPlist,
});
}
In-Memory Conversion
import Plist from "simple-plist";
async function foo() {
// Convert a Javascript object to a plist xml string
const xml = Plist.stringify({ name: "Joe", answer: 42 });
// Convert a plist xml string or a binary plist buffer to a Javascript object
const data = await parse(
"<plist><dict><key>name</key><string>Joe</string></dict></plist>"
);
}
TypeScript Generics
If you're using TypeScript, the parse
and read
methods both support
generics so you don't lose type information. If no type is specified, the
default of PlistValue
will be used.
import Plist from "simple-plist";
interface Settings {
showToolbar?: boolean;
avatar?: string;
}
async function loadSettings() {
return Plist.read<MyDatabase>("/path/to/settings.plist");
}