Socket
Socket
Sign inDemoInstall

microdata-node

Package Overview
Dependencies
0
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

30

lib/index.js
'use strict';
var util = require('util'),
urlUtil = require('url');
var urlUtil = require('url');

@@ -20,2 +19,7 @@ function Item(spec) {

Item.prototype.addProperty = function addProperty(name, value) {
if (!this.properties[name]) this.properties[name] = [];
this.properties[name].push(value);
};
Item.prototype.serialize = function serialize() {

@@ -92,4 +96,4 @@ var item = {

function walkNode(node, parentScope) {
var currentItem = parentScope;
function walkNode(node, parentItem) {
var currentItem = parentItem;
var newItem = null;

@@ -109,8 +113,5 @@

}
} else {
} else if (currentItem) {
var value = newItem || parseValue(node);
if (!currentItem.properties[prop]) {
currentItem.properties[prop] = [];
}
currentItem.properties[prop].push(value);
currentItem.addProperty(prop, value);
}

@@ -124,10 +125,11 @@

var rootScope = new Item({});
walkNode($.root(), rootScope);
walkNode($.root(), null);
return items.map(function (item) {
return item.serialize();
});
return {
items: items.map(function (item) {
return item.serialize();
})
};
}
exports.parse = parse;
{
"name": "microdata-node",
"version": "0.0.4",
"version": "0.0.5",
"description": "Cheerio based microdata parser",

@@ -5,0 +5,0 @@ "main": "lib",

@@ -42,24 +42,26 @@ microdata-node [![Build Status](https://travis-ci.org/Janpot/microdata-node.svg)](https://travis-ci.org/Janpot/microdata-node)

```json
[
{
"type": [ "http://schema.org/Person" ],
"properties": {
"name": [ "John Doe" ],
"jobTitle": [ "graduate research assistant" ],
"affiliation": [ "University of Dreams" ],
"additionalName": [ "Johnny" ],
"url": [ "http://www.johnnyd.com/" ],
"address": [
{
"type": [ "http://schema.org/PostalAddress" ],
"properties": {
"streetAddress": [ "1234 Peach Drive" ],
"addressLocality": [ "Warner Robins" ],
"addressRegion": [ "Georgia" ]
{
"items": [
{
"type": [ "http://schema.org/Person" ],
"properties": {
"name": [ "John Doe" ],
"jobTitle": [ "graduate research assistant" ],
"affiliation": [ "University of Dreams" ],
"additionalName": [ "Johnny" ],
"url": [ "http://www.johnnyd.com/" ],
"address": [
{
"type": [ "http://schema.org/PostalAddress" ],
"properties": {
"streetAddress": [ "1234 Peach Drive" ],
"addressLocality": [ "Warner Robins" ],
"addressRegion": [ "Georgia" ]
}
}
}
]
]
}
}
}
]
]
}
```

@@ -66,0 +68,0 @@

@@ -14,4 +14,4 @@ /* global describe, it */

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 0);
assert.isArray(result.items);
assert.lengthOf(result.items, 0);
});

@@ -22,7 +22,7 @@

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.isObject(result[0]);
assert.isUndefined(result[0].type);
assert.isObject(result[0].properties);
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.isObject(result.items[0]);
assert.isUndefined(result.items[0].type);
assert.isObject(result.items[0].properties);
});

@@ -33,5 +33,5 @@

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.deepEqual(result[0].type, [ 'http://schema.org/Person' ]);
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.deepEqual(result.items[0].type, [ 'http://schema.org/Person' ]);
});

@@ -42,5 +42,5 @@

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.deepEqual(result[0].type, ['http://schema.org/Person']);
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.deepEqual(result.items[0].type, ['http://schema.org/Person']);
});

@@ -56,6 +56,6 @@

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 2);
assert.deepEqual(result[0].type, ['http://schema.org/Person']);
assert.deepEqual(result[1].type, ['http://schema.org/PostalAddress']);
assert.isArray(result.items);
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']);
});

@@ -71,5 +71,5 @@

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.deepEqual(result[0].properties, {
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.deepEqual(result.items[0].properties, {
name: ['Jan'],

@@ -92,10 +92,10 @@ age: ['29']

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.deepEqual(result[0].properties.address1, [{
assert.deepEqual(result.items[0].properties.address1, [{
type: ['http://schema.org/PostalAddress'],
properties: { street: ['street1'] }
}]);
assert.deepEqual(result[0].properties.address2, [{
assert.deepEqual(result.items[0].properties.address2, [{
type: ['http://schema.org/PostalAddress'],

@@ -114,5 +114,5 @@ properties: { street: ['street2'] }

var result = parser.parse($);
assert.isArray(result);
assert.lengthOf(result, 1);
assert.deepEqual(result[0].properties, {
assert.isArray(result.items);
assert.lengthOf(result.items, 1);
assert.deepEqual(result.items[0].properties, {
name: ['Jan', 'Potoms']

@@ -119,0 +119,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