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.1 to 0.0.2

23

lib/index.js

@@ -11,4 +11,3 @@ 'use strict';

id: spec.id || null,
props: {},
children: []
props: {}
};

@@ -55,17 +54,22 @@

var items = [];
function walkNode(node, parentScope) {
var currentScope = parentScope;
var childScope = null;
var newScope = null;
if (node.attr('itemscope') !== undefined) {
childScope = createScope({
newScope = createScope({
type: node.attr('itemtype'),
id: node.attr('itemid')
});
parentScope.children.push(childScope);
}
var prop = node.attr('itemprop');
if (prop !== undefined) {
var value = childScope || parseValue(node);
if (prop === undefined) {
if (newScope) {
items.push(newScope);
}
} else {
var value = newScope || parseValue(node);
if (currentScope.props[prop] === undefined) {

@@ -81,5 +85,4 @@ currentScope.props[prop] = value;

//console.log(node.children());
node.children().each(function (i, child) {
walkNode($(child), childScope || currentScope);
walkNode($(child), newScope || currentScope);
});

@@ -92,5 +95,5 @@

return rootScope.children;
return items;
}
exports.parse = parse;
{
"name": "microdata-node",
"version": "0.0.1",
"version": "0.0.2",
"description": "Cheerio based microdata parser",

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

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

var cheerio = require('cheerio');
var microdata = require('./lib/index');
var microdata = require('microdata-node');

@@ -56,18 +56,5 @@ var $ = cheerio.load(

"addressRegion": "Georgia"
},
"children": []
}
}
},
"children": [
{
"type": "http://schema.org/PostalAddress",
"id": null,
"props": {
"streetAddress": "1234 Peach Drive",
"addressLocality": "Warner Robins",
"addressRegion": "Georgia"
},
"children": []
}
]
}
}

@@ -81,4 +68,4 @@ ]

parses the provided cheerio object with optiona configuration.
parses the provided cheerio object with optional configuration.
`config.base`: base url to resolve url properties against.

@@ -26,3 +26,2 @@ /* global describe, it */

assert.isObject(result[0].props);
assert.lengthOf(result[0].children, 0);
});

@@ -79,6 +78,6 @@

'<div itemscope itemtype="http://schema.org/Person">' +
'<div itemscope itemtype="http://schema.org/PostalAddress">' +
'<div itemprop="address1" itemscope itemtype="http://schema.org/PostalAddress">' +
'<div itemprop="street">street1</div>' +
'</div>' +
'<div itemscope itemtype="http://schema.org/PostalAddress">' +
'<div itemprop="address2" itemscope itemtype="http://schema.org/PostalAddress">' +
'<div itemprop="street">street2</div>' +

@@ -91,5 +90,13 @@ '</div>' +

assert.lengthOf(result, 1);
assert.lengthOf(result[0].children, 2);
assert.deepEqual(result[0].children[0].props, { street: 'street1' });
assert.deepEqual(result[0].children[1].props, { street: 'street2' });
assert.deepEqual(result[0].props.address1, {
type: 'http://schema.org/PostalAddress',
id: null,
props: { street: 'street1' }
});
assert.deepEqual(result[0].props.address2, {
type: 'http://schema.org/PostalAddress',
id: null,
props: { street: 'street2' }
});
});

@@ -96,0 +103,0 @@

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