Socket
Socket
Sign inDemoInstall

microdata-node

Package Overview
Dependencies
4
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.19 to 0.1.0

lib/microdataDom.js

78

lib/toJsonld.js
'use strict';
var urlUtil = require('url');
var isAbsoluteUrl = require('is-absolute-url');
var microdataToRdf = require('./microdataToRdf');
var rdfToJsonld = require('./rdfToJsonld');
function toJsonld(microdata, config) {
config = config || {};
var base = config.base || '';
var graph = [];
function propertyToJsonld(values, inheritedType) {
var jsonldValues = values
.map(function (value) {
if (typeof value === 'string') {
if (isAbsoluteUrl(value)) {
return { '@id': value };
} else {
return { '@value': value };
}
} else {
var jsonldValue = itemToJsonld(value, inheritedType);
return jsonldValue;
}
});
return jsonldValues;
}
function itemToJsonld(item, inheritedType) {
var jsonldItem = {};
if (item.id) {
jsonldItem['@id'] = item.id;
}
if (item.type) {
jsonldItem['@type'] = item.type;
}
function resolvePropertyName(property, type) {
if (isAbsoluteUrl(property)) {
return property;
} else if (type) {
type = type.replace(/\#.+$/, '#');
if (/\#$/.test(type)) {
return type + property;
} else {
return urlUtil.resolve(type, property);
}
} else {
return base + '#' + property;
}
}
Object.keys(item.properties)
.forEach(function (property) {
var values = item.properties[property];
if (item.type) {
item.type.forEach(function (type) {
var jsonldProperty = resolvePropertyName(property, type);
jsonldItem[jsonldProperty] = propertyToJsonld(values, type);
});
} else {
var jsonldProperty = resolvePropertyName(property, inheritedType);
jsonldItem[jsonldProperty] = propertyToJsonld(values, inheritedType);
}
});
return jsonldItem;
}
microdata.items.forEach(function (item) {
var jsonldItem = itemToJsonld(item);
graph.push(jsonldItem);
});
return graph;
function toJsonld(microdataHtml, config) {
return rdfToJsonld(microdataToRdf(microdataHtml, config), config);
}
module.exports = toJsonld;
{
"name": "microdata-node",
"version": "0.0.19",
"version": "0.1.0",
"description": "Cheerio based microdata parser",

@@ -10,3 +10,6 @@ "main": "lib",

"mocha-watch": "mocha -w ./test",
"lint": "jshint --reporter node_modules/jshint-stylish/stylish.js ."
"lint": "jshint --reporter node_modules/jshint-stylish/stylish.js .",
"code-style": "jscs .",
"download-tests": "node ./scripts/download-tests.js",
"download-nt-tests": "rm -rf ./test/nt && mkdir ./test/nt && curl http://www.w3.org/2013/N-TriplesTests/TESTS.tar.gz | tar xz -C ./test/nt"
},

@@ -30,2 +33,3 @@ "repository": {

"cheerio": "^0.18.0",
"jscs": "^1.9.0",
"jshint": "^2.5.10",

@@ -35,2 +39,3 @@ "jshint-stylish": "^1.0.0",

"mocha": "^2.0.1",
"n3": "^0.3.6",
"request": "^2.51.0"

@@ -40,4 +45,6 @@ },

"array-unique": "^0.1.1",
"domutils": "^1.5.0",
"es6-map": "^0.1.1",
"is-absolute-url": "^1.0.0"
}
}

@@ -72,3 +72,3 @@ /* global describe, it */

assert.lengthOf(result.items, 1);
assert.deepEqual(result.items[0].type, ['http://schema.org/Person']);
assert.deepEqual(result.items[0].type, [ 'http://schema.org/Person' ]);
});

@@ -86,4 +86,4 @@

assert.lengthOf(result.items, 2);
assert.deepEqual(result.items[0].type, ['http://schema.org/Person']);
assert.deepEqual(result.items[1].type, ['http://schema.org/PostalAddress']);
assert.deepEqual(result.items[0].type, [ 'http://schema.org/Person' ]);
assert.deepEqual(result.items[1].type, [ 'http://schema.org/PostalAddress' ]);
});

@@ -102,4 +102,4 @@

assert.deepEqual(result.items[0].properties, {
name: ['Jan'],
age: ['29']
name: [ 'Jan' ],
age: [ '29' ]
});

@@ -126,8 +126,8 @@ });

address1: [{
type: ['http://schema.org/PostalAddress'],
properties: { street: ['street1'] }
type: [ 'http://schema.org/PostalAddress' ],
properties: { street: [ 'street1' ] }
}],
address2: [{
type: ['http://schema.org/PostalAddress'],
properties: { street: ['street2'] }
type: [ 'http://schema.org/PostalAddress' ],
properties: { street: [ 'street2' ] }
}]

@@ -148,3 +148,3 @@ });

assert.deepEqual(result.items[0].properties, {
name: ['Jan', 'Potoms']
name: [ 'Jan', 'Potoms' ]
});

@@ -175,4 +175,4 @@ });

assert.deepEqual(result.items[0].properties, {
name: ['Jan'],
additionalName: ['Jan']
name: [ 'Jan' ],
additionalName: [ 'Jan' ]
});

@@ -191,3 +191,3 @@ });

assert.deepEqual(result.items[0].properties, {
name: ['Jan']
name: [ 'Jan' ]
});

@@ -208,3 +208,3 @@ });

assert.deepEqual(result.items[0].properties, {
name: ['Jan']
name: [ 'Jan' ]
});

@@ -211,0 +211,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc