plist 1.0.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Parser functions.
3
+ */
4
+
5
+ var parserFunctions = require('./lib/parse');
6
+ Object.keys(parserFunctions).forEach(function (k) { exports[k] = parserFunctions[k]; });
7
+
8
+ /**
9
+ * Builder functions.
10
+ */
11
+
12
+ var builderFunctions = require('./lib/build');
13
+ Object.keys(builderFunctions).forEach(function (k) { exports[k] = builderFunctions[k]; });
package/lib/build.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Module dependencies.
4
3
  */
@@ -92,7 +91,9 @@ function walk_obj(next, next_child) {
92
91
  var tag_type, i, prop;
93
92
  var name = type(next);
94
93
 
95
- if (Array.isArray(next)) {
94
+ if ('Undefined' == name) {
95
+ return;
96
+ } else if (Array.isArray(next)) {
96
97
  next_child = next_child.ele('array');
97
98
  for (i = 0; i < next.length; i++) {
98
99
  walk_obj(next[i], next_child);
@@ -128,7 +129,7 @@ function walk_obj(next, next_child) {
128
129
  } else if ('ArrayBuffer' == name) {
129
130
  next_child.ele('data').raw(base64.fromByteArray(next));
130
131
 
131
- } else if (next.buffer && 'ArrayBuffer' == type(next.buffer)) {
132
+ } else if (next && next.buffer && 'ArrayBuffer' == type(next.buffer)) {
132
133
  // a typed array
133
134
  next_child.ele('data').raw(base64.fromByteArray(new Uint8Array(next.buffer), next_child));
134
135
 
package/lib/parse.js CHANGED
@@ -1,9 +1,7 @@
1
-
2
1
  /**
3
2
  * Module dependencies.
4
3
  */
5
4
 
6
- var deprecate = require('util-deprecate');
7
5
  var DOMParser = require('xmldom').DOMParser;
8
6
 
9
7
  /**
@@ -11,10 +9,6 @@ var DOMParser = require('xmldom').DOMParser;
11
9
  */
12
10
 
13
11
  exports.parse = parse;
14
- exports.parseString = deprecate(parseString, '`parseString()` is deprecated. ' +
15
- 'It\'s not actually async. Use `parse()` instead.');
16
- exports.parseStringSync = deprecate(parseStringSync, '`parseStringSync()` is ' +
17
- 'deprecated. Use `parse()` instead.');
18
12
 
19
13
  /**
20
14
  * We ignore raw text (usually whitespace), <!-- xml comments -->,
@@ -31,6 +25,23 @@ function shouldIgnoreNode (node) {
31
25
  || node.nodeType === 4; // cdata
32
26
  }
33
27
 
28
+ /**
29
+ * Check if the node is empty. Some plist file has such node:
30
+ * <key />
31
+ * this node shoud be ignored.
32
+ *
33
+ * @see https://github.com/TooTallNate/plist.js/issues/66
34
+ * @param {Element} node
35
+ * @returns {Boolean}
36
+ * @api private
37
+ */
38
+ function isEmptyNode(node){
39
+ if(!node.childNodes || node.childNodes.length === 0) {
40
+ return true;
41
+ } else {
42
+ return false;
43
+ }
44
+ }
34
45
 
35
46
  /**
36
47
  * Parses a Plist XML string. Returns an Object.
@@ -54,52 +65,6 @@ function parse (xml) {
54
65
  return plist;
55
66
  }
56
67
 
57
- /**
58
- * Parses a Plist XML string. Returns an Object. Takes a `callback` function.
59
- *
60
- * @param {String} xml - the XML String to decode
61
- * @param {Function} callback - callback function
62
- * @returns {Mixed} the decoded value from the Plist XML
63
- * @api public
64
- * @deprecated not actually async. use parse() instead
65
- */
66
-
67
- function parseString (xml, callback) {
68
- var doc, error, plist;
69
- try {
70
- doc = new DOMParser().parseFromString(xml);
71
- plist = parsePlistXML(doc.documentElement);
72
- } catch(e) {
73
- error = e;
74
- }
75
- callback(error, plist);
76
- }
77
-
78
- /**
79
- * Parses a Plist XML string. Returns an Object.
80
- *
81
- * @param {String} xml - the XML String to decode
82
- * @param {Function} callback - callback function
83
- * @returns {Mixed} the decoded value from the Plist XML
84
- * @api public
85
- * @deprecated use parse() instead
86
- */
87
-
88
- function parseStringSync (xml) {
89
- var doc = new DOMParser().parseFromString(xml);
90
- var plist;
91
- if (doc.documentElement.nodeName !== 'plist') {
92
- throw new Error('malformed document. First element should be <plist>');
93
- }
94
- plist = parsePlistXML(doc.documentElement);
95
-
96
- // if the plist is an array with 1 element, pull it out of the array
97
- if (plist.length == 1) {
98
- plist = plist[0];
99
- }
100
- return plist;
101
- }
102
-
103
68
  /**
104
69
  * Convert an XML based plist document into a JSON representation.
105
70
  *
@@ -155,10 +120,15 @@ function parsePlistXML (node) {
155
120
  // TODO: what should we do with text types? (CDATA sections)
156
121
 
157
122
  } else if (node.nodeName === 'key') {
158
- return node.childNodes[0].nodeValue;
159
-
123
+ if(isEmptyNode(node)) return null;
124
+ res = '';
125
+ if(node.childNodes[0]) {
126
+ res = node.childNodes[0].nodeValue;
127
+ }
128
+ return res;
160
129
  } else if (node.nodeName === 'string') {
161
130
  res = '';
131
+ if(isEmptyNode(node)) return null;
162
132
  for (d=0; d < node.childNodes.length; d++) {
163
133
  res += node.childNodes[d].nodeValue;
164
134
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "plist",
3
3
  "description": "Mac OS X Plist parser/builder for Node.js and browsers",
4
- "version": "1.0.1",
4
+ "version": "2.0.1",
5
5
  "author": "Nathan Rajlich <nathan@tootallnate.net>",
6
6
  "contributors": [
7
7
  "Hans Huebner <hans.huebner@gmail.com>",
@@ -14,6 +14,7 @@
14
14
  "type": "git",
15
15
  "url": "git://github.com/TooTallNate/node-plist.git"
16
16
  },
17
+ "license": "MIT",
17
18
  "keywords": [
18
19
  "apple",
19
20
  "browser",
@@ -22,19 +23,19 @@
22
23
  "parser",
23
24
  "xml"
24
25
  ],
25
- "main": "lib/plist.js",
26
+ "main": "index.js",
26
27
  "dependencies": {
27
- "base64-js": "0.0.6",
28
- "xmlbuilder": "2.2.1",
29
- "xmldom": "0.1.x",
30
- "util-deprecate": "1.0.0"
28
+ "base64-js": "1.1.2",
29
+ "xmlbuilder": "8.2.2",
30
+ "xmldom": "0.1.x"
31
31
  },
32
32
  "devDependencies": {
33
- "mocha": "1.18.2",
34
- "browserify": "3.44.2",
35
- "multiline": "0.3.4"
33
+ "browserify": "13.0.1",
34
+ "mocha": "2.4.5",
35
+ "multiline": "1.0.2",
36
+ "zuul": "3.10.1"
36
37
  },
37
38
  "scripts": {
38
- "test": "mocha -gc --reporter spec --check-leaks test/*.js"
39
+ "test": "make test"
39
40
  }
40
41
  }
package/.zuul.yml DELETED
@@ -1,18 +0,0 @@
1
- ui: mocha-bdd
2
- browsers:
3
- - name: chrome
4
- version: 29..latest
5
- - name: firefox
6
- version: latest
7
- - name: safari
8
- version: latest
9
- - name: ie
10
- version: 10
11
- platform: Windows 2012
12
- - name: ie
13
- version: 9..latest
14
- - name: iphone
15
- version: 6.0..latest
16
- - name: android
17
- version: oldest..latest
18
- version: 5.1
package/lib/node.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Module dependencies.
3
- */
4
-
5
- var fs = require('fs');
6
- var parse = require('./parse');
7
- var deprecate = require('util-deprecate');
8
-
9
- /**
10
- * Module exports.
11
- */
12
-
13
- exports.parseFile = deprecate(parseFile, '`parseFile()` is deprecated. ' +
14
- 'Use `parseString()` instead.');
15
- exports.parseFileSync = deprecate(parseFileSync, '`parseFileSync()` is deprecated. ' +
16
- 'Use `parseStringSync()` instead.');
17
-
18
- /**
19
- * Parses file `filename` as a .plist file.
20
- * Invokes `fn` callback function when done.
21
- *
22
- * @param {String} filename - name of the file to read
23
- * @param {Function} fn - callback function
24
- * @api public
25
- * @deprecated use parseString() instead
26
- */
27
-
28
- function parseFile (filename, fn) {
29
- fs.readFile(filename, { encoding: 'utf8' }, onread);
30
- function onread (err, inxml) {
31
- if (err) return fn(err);
32
- parse.parseString(inxml, fn);
33
- }
34
- }
35
-
36
- /**
37
- * Parses file `filename` as a .plist file.
38
- * Returns a when done.
39
- *
40
- * @param {String} filename - name of the file to read
41
- * @param {Function} fn - callback function
42
- * @api public
43
- * @deprecated use parseStringSync() instead
44
- */
45
-
46
- function parseFileSync (filename) {
47
- var inxml = fs.readFileSync(filename, 'utf8');
48
- return parse.parseStringSync(inxml);
49
- }
package/lib/plist.js DELETED
@@ -1,23 +0,0 @@
1
-
2
- var i;
3
-
4
- /**
5
- * Parser functions.
6
- */
7
-
8
- var parserFunctions = require('./parse');
9
- for (i in parserFunctions) exports[i] = parserFunctions[i];
10
-
11
- /**
12
- * Builder functions.
13
- */
14
-
15
- var builderFunctions = require('./build');
16
- for (i in builderFunctions) exports[i] = builderFunctions[i];
17
-
18
- /**
19
- * Add Node.js-specific functions (they're deprecated…).
20
- */
21
-
22
- var nodeFunctions = require('./node');
23
- for (i in nodeFunctions) exports[i] = nodeFunctions[i];
package/test/build.js DELETED
@@ -1,133 +0,0 @@
1
-
2
- var assert = require('assert');
3
- var build = require('../').build;
4
- var multiline = require('multiline');
5
-
6
- describe('plist', function () {
7
-
8
- describe('build()', function () {
9
-
10
- it('should create a plist XML string from a String', function () {
11
- var xml = build('test');
12
- assert.strictEqual(xml, multiline(function () {/*
13
- <?xml version="1.0" encoding="UTF-8"?>
14
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
15
- <plist version="1.0">
16
- <string>test</string>
17
- </plist>
18
- */}));
19
- });
20
-
21
- it('should create a plist XML integer from a whole Number', function () {
22
- var xml = build(3);
23
- assert.strictEqual(xml, multiline(function () {/*
24
- <?xml version="1.0" encoding="UTF-8"?>
25
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
26
- <plist version="1.0">
27
- <integer>3</integer>
28
- </plist>
29
- */}));
30
- });
31
-
32
- it('should create a plist XML real from a fractional Number', function () {
33
- var xml = build(Math.PI);
34
- assert.strictEqual(xml, multiline(function () {/*
35
- <?xml version="1.0" encoding="UTF-8"?>
36
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
37
- <plist version="1.0">
38
- <real>3.141592653589793</real>
39
- </plist>
40
- */}));
41
- });
42
-
43
- it('should create a plist XML date from a Date', function () {
44
- var xml = build(new Date('2010-02-08T21:41:23Z'));
45
- assert.strictEqual(xml, multiline(function () {/*
46
- <?xml version="1.0" encoding="UTF-8"?>
47
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48
- <plist version="1.0">
49
- <date>2010-02-08T21:41:23Z</date>
50
- </plist>
51
- */}));
52
- });
53
-
54
- it('should create a plist XML date from a Buffer', function () {
55
- var xml = build(new Buffer('☃'));
56
- assert.strictEqual(xml, multiline(function () {/*
57
- <?xml version="1.0" encoding="UTF-8"?>
58
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
59
- <plist version="1.0">
60
- <data>4piD</data>
61
- </plist>
62
- */}));
63
- });
64
-
65
- it('should create a plist XML true from a `true` Boolean', function () {
66
- var xml = build(true);
67
- assert.strictEqual(xml, multiline(function () {/*
68
- <?xml version="1.0" encoding="UTF-8"?>
69
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
70
- <plist version="1.0">
71
- <true/>
72
- </plist>
73
- */}));
74
- });
75
-
76
- it('should create a plist XML false from a `false` Boolean', function () {
77
- var xml = build(false);
78
- assert.strictEqual(xml, multiline(function () {/*
79
- <?xml version="1.0" encoding="UTF-8"?>
80
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
81
- <plist version="1.0">
82
- <false/>
83
- </plist>
84
- */}));
85
- });
86
-
87
- it('should create a plist XML dict from an Object', function () {
88
- var xml = build({ foo: 'bar' });
89
- assert.strictEqual(xml, multiline(function () {/*
90
- <?xml version="1.0" encoding="UTF-8"?>
91
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
92
- <plist version="1.0">
93
- <dict>
94
- <key>foo</key>
95
- <string>bar</string>
96
- </dict>
97
- </plist>
98
- */}));
99
- });
100
-
101
- it('should create a plist XML array from an Array', function () {
102
- var xml = build([ 1, 'foo', false, new Date(1234) ]);
103
- assert.strictEqual(xml, multiline(function () {/*
104
- <?xml version="1.0" encoding="UTF-8"?>
105
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
106
- <plist version="1.0">
107
- <array>
108
- <integer>1</integer>
109
- <string>foo</string>
110
- <false/>
111
- <date>1970-01-01T00:00:01Z</date>
112
- </array>
113
- </plist>
114
- */}));
115
- });
116
-
117
- it('should properly encode an empty string', function () {
118
- var xml = build({ a: '' });
119
- assert.strictEqual(xml, multiline(function () {/*
120
- <?xml version="1.0" encoding="UTF-8"?>
121
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
122
- <plist version="1.0">
123
- <dict>
124
- <key>a</key>
125
- <string></string>
126
- </dict>
127
- </plist>
128
- */}));
129
- });
130
-
131
- });
132
-
133
- });