Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncronous API #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Introduction

node-vcard parses vCard data into nice JSON. It can read files from
disk and then parse them with vCard.parseFile(), or the vCard data
can be passed to it for direct parsing with vCard.parse().
can be passed to it for direct parsing with vCard.parsevCard().

This module only does basic validation of the files, so if you have
NICKNAME field (added in version 3.0) in a 2.1 file and this causes
Expand All @@ -26,16 +26,16 @@ basically you do:

var util = require('util');
var vCard = require('vcard');
var card = new vCard();

/* Use readFile() if the file is on disk. */
card.readFile("path/to/file.vcf", function(err, json) {
console.log(util.inspect(json));
});
var json = vCard.readFile("path/to/file.vcf");
console.log(util.inspect(json));

/* Use readData() otherwise. */
card.readData(String_with_vCard_data, function(err. json) {
console.log(util.inspect(json));
}
var json = vCard.readData(String_with_vCard_data)
console.log(util.inspect(json));


Running the Unit Tests
----------------------

Expand Down
11 changes: 2 additions & 9 deletions bin/vcard-to-json.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ var util = require('util');
var vCard = require('../vcard');

var file = process.argv[2] || "tests/vcard-4.0.vcf";
var card = new vCard();

card.readFile(file, function(err, json){
if (err) {
console.error(err);
}
if (json) {
console.log(util.inspect(json));
}
});
var json = vCard.readFile(file);
console.log(util.inspect(json));
26 changes: 5 additions & 21 deletions spec/vcard-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ var vCard,
vCardString,
assert = require('assert-plus'),
fs = require('fs'),
VCard = require('../vcard');

beforeEach(function(){
vCard = new VCard();
});
vCard = require('../vcard');

testAllCardsInFolder = function (folderPath) {
if (!fs.existsSync(folderPath)) {
Expand All @@ -19,32 +15,20 @@ testAllCardsInFolder = function (folderPath) {
return path.match(/.vcf$/)
}).forEach(function (path) {
describe(path, function(){
var vCardString = fs.readFileSync(folderPath + path, {encoding: 'ascii'})
var vCardString = fs.readFileSync(folderPath + path, {encoding: 'ascii'});

it('is loaded into memory', function () {
assert.string(vCardString);
})
it('is parsed', function(done){
vCard.readData(vCardString, function (err, json) {
assert.equal(null, err)
done()
})
var json = vCard.readData(vCardString);
done()
})
})

})
}

describe('Setup', function () {
it('VCard is a constructor function.', function(){
assert.func(VCard);
});

});
describe('VCard', function(){

testAllCardsInFolder('./spec/');
testAllCardsInFolder('./spec/private-vcards/');



});
Loading