Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rdf-serializer-jsonld-ext

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdf-serializer-jsonld-ext - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

41

lib/SerializerStream.js
const jsonld = require('jsonld')
const Promise = require('bluebird')
const Readable = require('readable-stream')

@@ -40,13 +41,34 @@ const SerializerStream = require('rdf-serializer-jsonld/lib/SerializerStream')

Promise.resolve().then(() => {
if (this.options.compact) {
return jsonld.promises().compact(data, this.options.context)
if (this.options.process) {
return Promise.reduce(this.options.process, (result, step) => {
return this.transform(result, step)
}, data)
} else {
return this.transform(data, this.options)
}
}).then((data) => {
this.push(data)
this.push(null)
}).catch((err) => {
this.emit('error', err)
})
}
if (this.options.frame) {
return jsonld.promises().frame(data, this.options.context)
transform (data, options) {
return Promise.resolve().then(() => {
if (options.compact) {
return jsonld.promises().compact(data, options.context || {})
}
if (options.flatten) {
return jsonld.promises().flatten(data, options.context || {})
}
if (options.frame) {
return jsonld.promises().frame(data, options.context || {})
}
return data
}).then((data) => {
if (this.options.skipContext) {
if (options.skipContext) {
if (data['@context']) {

@@ -57,3 +79,3 @@ delete data['@context']

if (this.options.skipGraphProperty) {
if (options.skipGraphProperty) {
if (data['@graph'] && data['@graph'].length === 1) {

@@ -72,8 +94,3 @@ const entry = data['@graph'][0]

}).then((data) => {
return this.options.outputFormat === 'string' ? JSON.stringify(data) : data
}).then((data) => {
this.push(data)
this.push(null)
}).catch((err) => {
this.emit('error', err)
return options.outputFormat === 'string' ? JSON.stringify(data) : data
})

@@ -80,0 +97,0 @@ }

{
"name": "rdf-serializer-jsonld-ext",
"version": "1.2.0",
"version": "1.3.0",
"description": "JSON-LD serializer that implements the RDFJS Sink Interfaces and supports different output styles",

@@ -28,2 +28,3 @@ "main": "index.js",

"dependencies": {
"bluebird": "^3.5.0",
"jsonld": "^0.4.12",

@@ -30,0 +31,0 @@ "rdf-serializer-jsonld": "^1.0.0",

@@ -9,2 +9,18 @@ /* global describe, it */

function quadsToReadable (quads) {
const readable = new Readable()
readable._readableState.objectMode = true
readable._read = () => {
quads.forEach((quad) => {
readable.push(quad)
})
readable.push(null)
}
return readable
}
describe('rdf-serializer-jsonld-ext', () => {

@@ -27,11 +43,3 @@ sinkTest(JsonLdSerializerExt, {readable: true})

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
input.push(quad)
input.push(null)
}
const input = quadsToReadable([quad])
const serializer = new JsonLdSerializerExt({outputFormat: 'string'})

@@ -70,11 +78,3 @@ const stream = serializer.import(input)

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
input.push(quad)
input.push(null)
}
const input = quadsToReadable([quad])
const serializer = new JsonLdSerializerExt({compact: true, context: context})

@@ -143,14 +143,3 @@ const stream = serializer.import(input)

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
quads.forEach((quad) => {
input.push(quad)
})
input.push(null)
}
const input = quadsToReadable(quads)
const serializer = new JsonLdSerializerExt({frame: true, context: context})

@@ -217,14 +206,3 @@ const stream = serializer.import(input)

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
quads.forEach((quad) => {
input.push(quad)
})
input.push(null)
}
const input = quadsToReadable(quads)
const serializer = new JsonLdSerializerExt({frame: true, context: context, skipGraphProperty: true})

@@ -294,14 +272,3 @@ const stream = serializer.import(input)

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
quads.forEach((quad) => {
input.push(quad)
})
input.push(null)
}
const input = quadsToReadable(quads)
const serializer = new JsonLdSerializerExt({frame: true, context: context, skipGraphProperty: true})

@@ -352,14 +319,3 @@ const stream = serializer.import(input)

const input = new Readable()
input._readableState.objectMode = true
input._read = () => {
quads.forEach((quad) => {
input.push(quad)
})
input.push(null)
}
const input = quadsToReadable(quads)
const serializer = new JsonLdSerializerExt({frame: true, context: context, skipContext: true})

@@ -398,16 +354,50 @@ const stream = serializer.import(input)

const input = new Readable()
const input = quadsToReadable([quad])
const serializer = new JsonLdSerializerExt({compact: true})
const stream = serializer.import(input)
input._readableState.objectMode = true
input.emit('prefix', 'ex', rdf.namedNode('http://example.org/'))
input._read = () => {
input.push(quad)
input.push(null)
let result
stream.on('data', (data) => {
result = data
})
return rdf.waitFor(stream).then(() => {
assert.deepEqual(result, jsonld)
})
})
it('should support multiple processing steps', () => {
const s0 = rdf.namedNode('http://example.org/subject')
const quads = [
rdf.quad(
s0,
rdf.namedNode('http://example.org/property0'),
rdf.literal('value0')
),
rdf.quad(
s0,
rdf.namedNode('http://example.org/property1'),
rdf.literal('value1')
)
]
const jsonld = {
'@id': 'http://example.org/subject',
'http://example.org/property0': 'value0',
'http://example.org/property1': 'value1'
}
const serializer = new JsonLdSerializerExt({compact: true})
const input = quadsToReadable(quads)
const serializer = new JsonLdSerializerExt({
process: [
{flatten: true},
{compact: true}
]
})
const stream = serializer.import(input)
input.emit('prefix', 'ex', rdf.namedNode('http://example.org/'))
let result

@@ -414,0 +404,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc