### Install and Use plist.js in Node.js Source: https://github.com/tootallnate/plist.js/blob/master/README.md Installs the plist.js module using npm and demonstrates how to require it to use its parsing and building functionalities within a Node.js application. ```bash npm install --save plist ``` ```javascript var plist = require('plist'); // now use the `parse()` and `build()` functions var val = plist.parse('Hello World!'); console.log(val); // "Hello World!" ``` -------------------------------- ### Install plist.js using npm Source: https://context7.com/tootallnate/plist.js/llms.txt This command installs the plist.js library as a project dependency using npm. It is the standard way to add this library to your Node.js project. ```bash npm install --save plist ``` -------------------------------- ### Parse plist XML to JavaScript Object with plist.js Source: https://context7.com/tootallnate/plist.js/llms.txt The `plist.parse()` function takes a plist XML string as input and returns the corresponding JavaScript object. It supports all standard plist data types and throws an error for malformed XML. Examples demonstrate parsing simple strings, files, and complex structures with various data types. ```javascript var plist = require('plist'); var fs = require('fs'); // Parse a simple plist string var result = plist.parse('Hello World!'); console.log(result); // Output: "Hello World!" // Parse a plist file from disk var xml = fs.readFileSync('Info.plist', 'utf8'); var obj = plist.parse(xml); console.log(JSON.stringify(obj, null, 2)); // Parse a complete plist with various data types var complexXml = ` CFBundleName MyApp CFBundleVersion 1.0.0 LSRequiresIPhoneOS EnableFeature MaxRetries 3 Threshold 0.75 ReleaseDate 2023-07-06T00:00:00Z SupportedDevices iPhone iPad Plugins Camera CDVCamera File CDVFile `; var config = plist.parse(complexXml); console.log(config); // Output: // { // CFBundleName: 'MyApp', // CFBundleVersion: '1.0.0', // LSRequiresIPhoneOS: true, // EnableFeature: false, // MaxRetries: 3, // Threshold: 0.75, // ReleaseDate: Date object, // SupportedDevices: ['iPhone', 'iPad'], // Plugins: { Camera: 'CDVCamera', File: 'CDVFile' } // } ``` -------------------------------- ### Include and Use plist.js in a Browser Source: https://github.com/tootallnate/plist.js/blob/master/README.md Shows how to include the plist.js library via a script tag in an HTML file and then utilize its parse and build functions directly in the browser's JavaScript environment. ```html ``` -------------------------------- ### Build Plist XML from JavaScript Object Source: https://github.com/tootallnate/plist.js/blob/master/README.md Demonstrates building a plist XML document from a JavaScript object. The plist.build() function converts the provided JavaScript object into a string that conforms to the plist DTD. ```javascript 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)); // // // // metadata // // bundle-identifier // com.company.app // bundle-version // 0.1.1 // kind // software // title // AppName // // ``` -------------------------------- ### Parse Plist from Filename in Node.js Source: https://github.com/tootallnate/plist.js/blob/master/README.md Demonstrates parsing a plist file from the local filesystem in a Node.js environment. It reads the file content using the 'fs' module and then parses it into a JavaScript object using plist.parse(). ```javascript var fs = require('fs'); var plist = require('plist'); var obj = plist.parse(fs.readFileSync('myPlist.plist', 'utf8')); console.log(JSON.stringify(obj)); ``` -------------------------------- ### Convert Plist Data Types in JavaScript Source: https://context7.com/tootallnate/plist.js/llms.txt Demonstrates the bidirectional conversion of various plist data types (string, integer, real, BigInt, boolean, date, data, null, array, dictionary) between XML and JavaScript using the plist.js library. This covers parsing XML to JavaScript objects and building XML from JavaScript values. ```javascript var plist = require('plist'); // String type var strXml = plist.build('Hello'); var strParsed = plist.parse('Hello'); // strParsed === 'Hello' // Integer type (whole numbers) var intXml = plist.build(42); var intParsed = plist.parse('42'); // intParsed === 42 // Real type (floating point) var realXml = plist.build(3.14); var realParsed = plist.parse('3.14'); // realParsed === 3.14 // BigInt support for large integers var bigIntXml = plist.build(BigInt('9007199254740991')); // Produces: 9007199254740991 // Boolean types var trueXml = plist.build(true); // var falseXml = plist.build(false); // var boolParsed = plist.parse(''); // boolParsed === true // Date type (ISO 8601 format) var date = new Date('2023-07-06T12:30:00Z'); var dateXml = plist.build(date); // Produces: 2023-07-06T12:30:00Z var dateParsed = plist.parse('2023-07-06T12:30:00Z'); // dateParsed instanceof Date === true // Data type (base64 encoded binary) var buffer = Buffer.from('Hello World'); var dataXml = plist.build(buffer); // Produces: SGVsbG8gV29ybGQ= var dataParsed = plist.parse('SGVsbG8gV29ybGQ='); // Buffer.isBuffer(dataParsed) === true // dataParsed.toString() === 'Hello World' // Null type var nullXml = plist.build(null); // Produces: var nullParsed = plist.parse(''); // nullParsed === null // Array type var arr = [1, 'two', true]; var arrXml = plist.build(arr); var arrParsed = plist.parse('1two'); // arrParsed deep equals [1, 'two', true] // Dictionary type (object) var dict = { name: 'App', version: 1 }; var dictXml = plist.build(dict); var dictParsed = plist.parse('nameAppversion1'); // dictParsed deep equals { name: 'App', version: 1 } ``` -------------------------------- ### Parse Plist from String Payload Source: https://github.com/tootallnate/plist.js/blob/master/README.md Illustrates parsing a plist structure directly from an XML string. The plist.parse() function takes the XML string as input and returns a JavaScript object representation of the plist content. ```javascript var plist = require('plist'); var xml = '' + '' + '' + 'metadata' + '' + 'bundle-identifier' + 'com.company.app' + 'bundle-version' + '0.1.1' + 'kind' + 'software' + 'title' + 'AppName' + '' + ''; console.log(plist.parse(xml)); // [ // "metadata", // { // "bundle-identifier": "com.company.app", // "bundle-version": "0.1.1", // "kind": "software", // "title": "AppName" // } // ] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.