Skip to content

Commit 247db85

Browse files
authored
Merge pull request #52 from mcollina/fix/del_parse
Del should accept strings
2 parents 1bdc0a8 + 189d228 commit 247db85

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ function levelgraphJSONLD(db, jsonldOpts) {
215215
graphdb.jsonld.del = function(obj, options, callback) {
216216
var blanks = {};
217217

218+
if (typeof obj === 'string') {
219+
try {
220+
obj = JSON.parse(obj);
221+
} catch (e) {
222+
// Handle case where we're trying to delete by passing an IRI
223+
if (!N3Util.isIRI(obj)) {
224+
throw e
225+
}
226+
}
227+
}
228+
218229
if (typeof options === 'function') {
219230
callback = options;
220231
options = {};

test/del_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,20 @@ describe('jsonld.del', function() {
125125
});
126126
});
127127
});
128+
129+
it('should del obj passed as stringified JSON', function(done) {
130+
var jld = {"@context": { "@vocab": "https://schema.org/"}, "name": "BigBlueHat"};
131+
132+
db.jsonld.put(JSON.stringify(jld), {preserve:true}, function() {
133+
db.jsonld.del(JSON.stringify(jld), {preserve:true}, function(err) {
134+
expect(err).to.not.exist;
135+
db.get({}, function(err, triples) {
136+
// getting the full db
137+
expect(triples).to.have.length(1);
138+
done();
139+
});
140+
});
141+
});
142+
});
143+
128144
});

0 commit comments

Comments
 (0)