-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,411 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ logs | |
results | ||
|
||
npm-debug.log | ||
node_modules | ||
.DS_Store | ||
coverage | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plist = require 'simple-plist' | ||
|
||
it "Throws an error on improperly formatted plist", => | ||
doIt = -> | ||
plist.readFileSync "#{__dirname}/test-xml1-invalid.plist" | ||
|
||
expect(doIt).toThrow /has errors$/ | ||
|
||
|
||
it "returns an empty object when the file is zero bytes", => | ||
obj = plist.readFileSync "#{__dirname}/test-xml1-invalid-2.plist" | ||
expect(obj).toEqual {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plist = require 'simple-plist' | ||
|
||
describe "String parsing", => | ||
it "can parse a string", => | ||
doc = plist.readFileSync "#{__dirname}/test-binary1.plist" | ||
plistString = plist.stringify doc | ||
parsedDoc = plist.parse(plistString) | ||
expect(parsedDoc).toEqual(doc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plist = require 'simple-plist' | ||
filePath = "#{__dirname}/test-binary1.plist" | ||
|
||
describe 'readFileSync can properly load and read a binary file', => | ||
contents = plist.readFileSync filePath | ||
it "has the proper values", => | ||
expect(contents.Name).toBe "John Doe" | ||
expect(contents['Birth Year']).toBe(1942) | ||
expect(contents['Travel Log']).toEqual( | ||
[ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
) | ||
|
||
|
||
|
||
describe "readFile works asynchronously", => | ||
it "has the proper values", => | ||
contents = plist.readFile filePath, (contents)=> | ||
expect(contents.Name).toBe "John Doe" | ||
expect(contents['Birth Year']).toBe(1942) | ||
expect(contents['Travel Log']).toEqual( | ||
[ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
plist = require 'simple-plist' | ||
filePath = "#{__dirname}/test-xml1.plist" | ||
|
||
describe 'readFileSync can properly load and read a file', => | ||
contents = plist.readFileSync filePath | ||
it "has the proper values", => | ||
expect(contents.Name).toBe "John Doe" | ||
expect(contents['Birth Year']).toBe(1942) | ||
expect(contents['Travel Log']).toEqual( | ||
[ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
) | ||
|
||
|
||
|
||
describe "readFile works asynchronously", => | ||
it "has the proper values", => | ||
contents = plist.readFile filePath, (err, contents)=> | ||
expect(contents.Name).toBe "John Doe" | ||
expect(contents['Birth Year']).toBe(1942) | ||
expect(contents['Travel Log']).toEqual( | ||
[ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
) |
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
🙄<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" | ||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Birth Year</key> | ||
<integer>1942</integer> | ||
<key>Name</key> | ||
<string>John Doe</string> | ||
<key>Travel Log</key> | ||
<array> | ||
<string>Tokyo, Honshu, Japan</string> | ||
<string>Philadelphia, PA</string> | ||
<string>Recife, Pernambuco, Brazil</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" | ||
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Birth Year</key> | ||
<integer>1942</integer> | ||
<key>Name</key> | ||
<string>John Doe</string> | ||
<key>Travel Log</key> | ||
<array> | ||
<string>Tokyo, Honshu, Japan</string> | ||
<string>Philadelphia, PA</string> | ||
<string>Recife, Pernambuco, Brazil</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plist = require 'simple-plist' | ||
filePath = "#{__dirname}/write-test-binary1.plist" | ||
testObj = { | ||
Name: 'John Doe' | ||
"Birth Year": 1942 | ||
"Travel Log": [ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
} | ||
|
||
|
||
describe 'writeBinaryFileSync can properly load and read a file', => | ||
plist.writeBinaryFileSync filePath, testObj | ||
it "has the proper values", => | ||
plist.readFile filePath, (contents)=> | ||
expect(contents).toEqual testObj | ||
|
||
|
||
describe 'writeBinaryFile works asynchronously', => | ||
it "has the proper values", => | ||
plist.writeBinaryFile filePath, testObj, => | ||
plist.readFile filePath, (contents)=> | ||
expect(contents).toEqual testObj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plist = require 'simple-plist' | ||
filePath = "#{__dirname}/write-test-xml1.plist" | ||
testObj = { | ||
Name: 'John Doe' | ||
"Birth Year": 1942 | ||
"Travel Log": [ | ||
'Tokyo, Honshu, Japan' | ||
'Philadelphia, PA' | ||
'Recife, Pernambuco, Brazil' | ||
] | ||
} | ||
|
||
|
||
describe 'writeFileSync can properly load and read a file', => | ||
plist.writeFileSync filePath, testObj | ||
it "has the proper values", => | ||
plist.readFile filePath, (contents)=> | ||
expect(contents).toEqual testObj | ||
|
||
|
||
describe 'writeFile works asynchronously', => | ||
it "has the proper values", => | ||
plist.writeFile filePath, testObj, => | ||
plist.readFile filePath, (contents)=> | ||
expect(contents).toEqual testObj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
{ | ||
"name": "simple-plist", | ||
"author": "Joe Wollard", | ||
"license": "MIT", | ||
"homepage": "https://github.com/wollardj/node-simple-plist.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wollardj/node-simple-plist.git" | ||
}, | ||
"version": "0.1.4", | ||
"description": "A wrapper utility for interacting with plist data.", | ||
"main": "simple-plist.js", | ||
"keywords": [ | ||
"plist", | ||
"binary", | ||
"bplist", | ||
"xml" | ||
], | ||
"dependencies": { | ||
"plist": "1.2.0", | ||
"bplist-parser": "0.0.6", | ||
"bplist-creator": "0.0.4" | ||
} | ||
"name": "simple-plist", | ||
"author": "Joe Wollard", | ||
"license": "MIT", | ||
"homepage": "https://github.com/wollardj/node-simple-plist.git", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wollardj/node-simple-plist.git" | ||
}, | ||
"version": "0.2.0", | ||
"description": "A wrapper utility for interacting with plist data.", | ||
"main": "simple-plist.js", | ||
"keywords": [ | ||
"plist", | ||
"binary", | ||
"bplist", | ||
"xml" | ||
], | ||
"scripts": { | ||
"test": "npm run-script clean && ./node_modules/.bin/coffee -c . && ./node_modules/.bin/jest --coverage", | ||
"clean": "rm -rf *.js __tests__/*.js __tests__/write-test* coverage" | ||
}, | ||
"dependencies": { | ||
"bplist-creator": "0.0.7", | ||
"bplist-parser": "0.1.1", | ||
"plist": "2.0.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "^1.11.1", | ||
"jest": "^16.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
bplistParser = require 'bplist-parser' | ||
bplistCreator = require 'bplist-creator' | ||
plist = require 'plist' | ||
fs = require 'fs' | ||
|
||
# reveal the underlying modules | ||
exports.plist = plist | ||
exports.bplistCreator = bplistCreator | ||
exports.bplistParser = bplistParser | ||
|
||
|
||
# Parses the given file and returns its contents as a native JavaScript object. | ||
exports.readFileSync = (aFile)-> | ||
contents = fs.readFileSync aFile | ||
|
||
if contents.length is 0 | ||
return {} | ||
exports.parse contents, aFile | ||
|
||
|
||
exports.readFile = (aFile, callback)-> | ||
fs.readFile aFile, (err, contents)-> | ||
if err | ||
callback err | ||
else | ||
try | ||
results = exports.parse contents, aFile | ||
callback null, results | ||
catch err | ||
callback err | ||
|
||
|
||
exports.writeFileSync = (aFile, anObject, options)-> | ||
data = plist.build anObject | ||
fs.writeFileSync aFile, data, options | ||
|
||
|
||
exports.writeFile = (aFile, anObject, options, callback)-> | ||
if arguments.length is 3 and typeof options is 'function' | ||
callback = options | ||
options = undefined | ||
data = plist.build anObject | ||
fs.writeFile aFile, data, options, callback | ||
|
||
|
||
exports.writeBinaryFileSync = (aFile, anObject, options)-> | ||
data = bplistCreator anObject | ||
fs.writeFileSync aFile, data, options | ||
|
||
|
||
exports.writeBinaryFile = (aFile, anObject, options, callback)-> | ||
if arguments.length is 3 and typeof options is 'function' | ||
callback = options | ||
options = undefined | ||
|
||
data = bplistCreator anObject | ||
fs.writeFile aFile, data, options, callback | ||
|
||
|
||
exports.stringify = (anObject)-> | ||
plist.build anObject | ||
|
||
|
||
exports.parse = (aStringOrBuffer, aFile)-> | ||
firstByte = aStringOrBuffer[0] | ||
try | ||
if firstByte in [60, '<'] | ||
results = plist.parse aStringOrBuffer.toString() | ||
else if firstByte is 98 | ||
results = bplistParser.parseBuffer(aStringOrBuffer)[0] | ||
else | ||
if aFile? | ||
throw new Error "Unable to determine format for '#{aFile}'" | ||
else | ||
throw new Error "Unable to determine format for plist aStringOrBuffer" | ||
results = {} | ||
catch e | ||
throw new Error "#{aFile} has errors" | ||
|
||
results |
Oops, something went wrong.