microdata-node
Advanced tools
Comparing version 0.2.1 to 1.0.0
@@ -8,8 +8,7 @@ 'use strict'; | ||
function removeHashFragment(url) { | ||
return url.replace(/#[^#\/?]$/, ''); | ||
function removeHashFragment (url) { | ||
return url.replace(/#[^#/?]$/, ''); | ||
} | ||
function normalizeConfig(config) { | ||
function normalizeConfig (config) { | ||
config = extend({ | ||
@@ -22,3 +21,3 @@ base: '', | ||
}, config); | ||
config.base = removeHashFragment(config.base); | ||
@@ -28,3 +27,3 @@ return config; | ||
function toJsonld(microdataHtml, config) { | ||
function toJsonld (microdataHtml, config) { | ||
config = normalizeConfig(config); | ||
@@ -34,3 +33,3 @@ return rdfToJsonld(microdataToRdf(microdataHtml, config), config); | ||
function toJson(microdataHtml, config) { | ||
function toJson (microdataHtml, config) { | ||
config = normalizeConfig(config); | ||
@@ -37,0 +36,0 @@ return rdfToJson(microdataToRdf(microdataHtml, config), config); |
'use strict'; | ||
function Item(spec) { | ||
function Item (spec) { | ||
if (spec.type && spec.type.length > 0) { | ||
@@ -22,3 +22,3 @@ this.type = spec.type; | ||
// adds a property to this item | ||
Item.prototype.addProperty = function addProperty(name, value) { | ||
Item.prototype.addProperty = function addProperty (name, value) { | ||
if (!this.properties[name]) this.properties[name] = []; | ||
@@ -29,3 +29,3 @@ this.properties[name].push(value); | ||
// adds a set of properties with the same value to this item | ||
Item.prototype.addProperties = function addProperties(names, value) { | ||
Item.prototype.addProperties = function addProperties (names, value) { | ||
names.forEach(function (name) { | ||
@@ -37,3 +37,3 @@ this.addProperty(name, value); | ||
// checks whether this item has been visited before or is a descendant of such item | ||
Item.prototype.hasMemoryOf = function hasMemoryOf(node) { | ||
Item.prototype.hasMemoryOf = function hasMemoryOf (node) { | ||
if (this.node === node) { | ||
@@ -49,3 +49,3 @@ return true; | ||
// serializes this item in a plain javascript object | ||
Item.prototype.serialize = function serialize() { | ||
Item.prototype.serialize = function serialize () { | ||
var item = {}; | ||
@@ -52,0 +52,0 @@ |
@@ -18,8 +18,7 @@ 'use strict'; | ||
function splitUnique(string) { | ||
function splitUnique (string) { | ||
return unique(string.trim().split(/\s+/)); | ||
} | ||
function walk(nodes, visit) { | ||
function walk (nodes, visit) { | ||
nodes.forEach(function (node) { | ||
@@ -33,3 +32,3 @@ visit(node); | ||
function mapIds(dom) { | ||
function mapIds (dom) { | ||
var idMap = {}; | ||
@@ -58,6 +57,6 @@ walk(dom, function (node) { | ||
var strict = config.strict; | ||
var idMap = mapIds(dom); | ||
function _getItems(nodes, isTopLevel) { | ||
function _getItems (nodes, isTopLevel) { | ||
var items = []; | ||
@@ -81,10 +80,10 @@ nodes.forEach(function (node) { | ||
function getItems() { | ||
function getItems () { | ||
return _getItems(dom, true); | ||
} | ||
function getProperties(root) { | ||
var results = [], | ||
memory = [], | ||
pending = []; | ||
function getProperties (root) { | ||
var results = []; | ||
var memory = []; | ||
var pending = []; | ||
@@ -124,11 +123,11 @@ memory.push(root); | ||
function isItem(element) { | ||
function isItem (element) { | ||
return DOM.hasAttrib(element, 'itemscope'); | ||
} | ||
function isProperty(element) { | ||
function isProperty (element) { | ||
return DOM.hasAttrib(element, 'itemprop'); | ||
} | ||
function getItemId(item) { | ||
function getItemId (item) { | ||
var id = DOM.getAttributeValue(item, 'itemid'); | ||
@@ -143,3 +142,3 @@ if (id) { | ||
function getItemType(item) { | ||
function getItemType (item) { | ||
var itemType = DOM.getAttributeValue(item, 'itemtype'); | ||
@@ -151,3 +150,3 @@ var types = (itemType ? splitUnique(itemType) : []) | ||
function getPropertyNames(element) { | ||
function getPropertyNames (element) { | ||
var itemProp = DOM.getAttributeValue(element, 'itemprop'); | ||
@@ -159,3 +158,3 @@ return itemProp ? splitUnique(itemProp) : []; | ||
var hrefProperty = ['a', 'area', 'link']; | ||
function isName(element, names) { | ||
function isName (element, names) { | ||
var tagname = DOM.getName(element); | ||
@@ -165,3 +164,3 @@ return names.indexOf(tagname) >= 0; | ||
function resolveUrlProperty(value) { | ||
function resolveUrlProperty (value) { | ||
if (!value) return { value: '' }; | ||
@@ -173,7 +172,7 @@ return { | ||
function resolveProperty(value) { | ||
function resolveProperty (value) { | ||
return { value: value || '' }; | ||
} | ||
function resolveNumberProperty(value) { | ||
function resolveNumberProperty (value) { | ||
var number = Number(value); | ||
@@ -188,4 +187,3 @@ if (isNaN(number)) return { value: value || '' }; | ||
function resolveDateProperty(value) { | ||
function resolveDateProperty (value) { | ||
value = value || ''; | ||
@@ -195,13 +193,13 @@ var result = { | ||
}; | ||
if (/^\d{4}\-\d{2}\-\d{2}$/.test(value)) { | ||
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) { | ||
result.type = XSD__DATE; | ||
} else if (/^\d{2}\:\d{2}(?:\:\d{2}(?:\.\d+)?)?(?:[AZ]|[\+\-]\d{2}(?:\:\d{2})?)?$/.test(value)) { | ||
} else if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:[AZ]|[+-]\d{2}(?::\d{2})?)?$/.test(value)) { | ||
result.type = XSD__TIME; | ||
} else if (/^\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}(?:\:\d{2}(?:\.\d+)?)?(?:[AZ]|[\+\-]\d{2}(?:\:\d{2})?)?$/.test(value)) { | ||
} else if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:[AZ]|[+-]\d{2}(?::\d{2})?)?$/.test(value)) { | ||
result.type = XSD__DATE_TIME; | ||
} else if (/^\d{4}\-\d{2}$/.test(value)) { | ||
} else if (/^\d{4}-\d{2}$/.test(value)) { | ||
result.type = XSD__G_YEAR_MONTH; | ||
} else if (/^\d+$/.test(value)) { | ||
result.type = XSD__G_YEAR; | ||
} else if (/^\-?P(?:(?:\d+Y)?(?:\d+M)?(?:\d+D)?)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?$/.test(value)) { | ||
} else if (/^-?P(?:(?:\d+Y)?(?:\d+M)?(?:\d+D)?)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?$/.test(value)) { | ||
result.type = XSD__DURATION; | ||
@@ -212,5 +210,8 @@ } | ||
function getItemValue(element) { | ||
function getItemValue (element) { | ||
if (!isProperty(element)) return null; | ||
if (isItem(element)) return element; | ||
if (DOM.hasAttrib(element, 'content')) { | ||
return resolveProperty(DOM.getAttributeValue(element, 'content')); | ||
} | ||
if (isName(element, srcProperty)) { | ||
@@ -222,5 +223,2 @@ return resolveUrlProperty(DOM.getAttributeValue(element, 'src')); | ||
} | ||
if (isName(element, [ 'meta' ])) { | ||
return resolveProperty(DOM.getAttributeValue(element, 'content')); | ||
} | ||
if (isName(element, [ 'object' ])) { | ||
@@ -239,6 +237,2 @@ return resolveUrlProperty(DOM.getAttributeValue(element, 'data')); | ||
} | ||
// non-strict mode begins here | ||
if (DOM.hasAttrib(element, 'content')) { | ||
return resolveProperty(DOM.getAttributeValue(element, 'content')); | ||
} | ||
@@ -259,2 +253,1 @@ return resolveProperty(''); | ||
}; | ||
@@ -9,5 +9,5 @@ 'use strict'; | ||
function microdataToRdf(html, config) { | ||
function microdataToRdf (html, config) { | ||
config = config || {}; | ||
var registry = config.registry; | ||
@@ -21,3 +21,3 @@ | ||
function generateBlankNode() { | ||
function generateBlankNode () { | ||
var blank = '_:' + nextId; | ||
@@ -28,3 +28,3 @@ nextId += 1; | ||
function getVocab(type) { | ||
function getVocab (type) { | ||
if (!type) return null; | ||
@@ -36,10 +36,10 @@ var registryVocab = Object.keys(registry).filter(function (prefix) { | ||
return registryVocab || type.replace(/[^#\/]*$/, ''); | ||
return registryVocab || type.replace(/[^#/]*$/, ''); | ||
} | ||
function generatePredicateUri(name, ctx) { | ||
function generatePredicateUri (name, ctx) { | ||
if (isAbsoluteUrl(name)) return name; | ||
var fragment = encodeURIComponent(name); | ||
if (!ctx.currentType) return config.base + '#' + fragment; | ||
if (/[#\/]$/.test(ctx.currentVocab)) return ctx.currentVocab + fragment; | ||
if (/[#/]$/.test(ctx.currentVocab)) return ctx.currentVocab + fragment; | ||
return ctx.currentVocab + '#' + fragment; | ||
@@ -50,3 +50,3 @@ } | ||
function getEquivalents(name, ctx) { | ||
function getEquivalents (name, ctx) { | ||
if (!registry[ctx.currentVocab]) return []; | ||
@@ -67,4 +67,3 @@ var properties = registry[ctx.currentVocab].properties; | ||
function generateTriples(item, ctx) { | ||
function generateTriples (item, ctx) { | ||
var subject = ctx.memory.get(item) || dom.getItemId(item) || generateBlankNode(); | ||
@@ -103,5 +102,3 @@ ctx.memory.set(item, subject); | ||
dom.getProperties(item).forEach(function (element) { | ||
dom.getPropertyNames(element).forEach(function (name) { | ||
var predicate = generatePredicateUri(name, newCtx); | ||
@@ -131,5 +128,3 @@ var value = null; | ||
}); | ||
}); | ||
}); | ||
@@ -153,5 +148,4 @@ | ||
return triples; | ||
} | ||
module.exports = microdataToRdf; |
@@ -10,3 +10,3 @@ 'use strict'; | ||
// splits a string on whitespaces and removes duplicate values | ||
function splitUnique(string) { | ||
function splitUnique (string) { | ||
string = string && string.trim(); | ||
@@ -20,4 +20,3 @@ if (string) { | ||
function parse($, $nodes, config) { | ||
function parse ($, $nodes, config) { | ||
config = config || {}; | ||
@@ -35,3 +34,3 @@ var items = []; | ||
// currentItem, if provided, contains the current microdata context | ||
function walkNodes($nodes, currentItem) { | ||
function walkNodes ($nodes, currentItem) { | ||
$nodes.each(function (i, node) { | ||
@@ -62,3 +61,3 @@ var $node = $(node); | ||
// parses a microdata item out of an itemscope DOM node | ||
function parseItem(node, currentItem) { | ||
function parseItem (node, currentItem) { | ||
// REMARK: note the raw dom node instead of $node to guarantee uniqueness | ||
@@ -86,7 +85,7 @@ if (currentItem && currentItem.hasMemoryOf(node)) { | ||
var refsSelector = refs | ||
.map(function makeIdSelector(id) { | ||
.map(function makeIdSelector (id) { | ||
return '#' + id; | ||
}) | ||
.join(','); | ||
walkNodes($(refsSelector), item); | ||
@@ -99,9 +98,9 @@ } | ||
// extracts and normalizes an attribute value of a node | ||
function resolveAttribute($node, attr) { | ||
function resolveAttribute ($node, attr) { | ||
var value = $node.attr(attr); | ||
return value && value.trim() || ''; | ||
return (value && value.trim()) || ''; | ||
} | ||
// extracts, and normalizes a url attribute value of a node | ||
function resolveUrlAttribute($node, attr) { | ||
function resolveUrlAttribute ($node, attr) { | ||
var url = $node.attr(attr); | ||
@@ -117,3 +116,3 @@ if (url === undefined) return ''; | ||
// extracts the property value out of an itemprop DOM node | ||
function parsePropertyValue(node) { | ||
function parsePropertyValue (node) { | ||
var $node = $(node); | ||
@@ -151,2 +150,1 @@ | ||
module.exports = util.deprecate(parse, 'parse() is deprecated, use toJson()'); | ||
@@ -5,8 +5,7 @@ 'use strict'; | ||
function isBlank(id) { | ||
function isBlank (id) { | ||
return id.indexOf('_:') === 0; | ||
} | ||
function resolveProperty(name, types, base) { | ||
function resolveProperty (name, types, base) { | ||
types = types || []; | ||
@@ -16,3 +15,3 @@ return types | ||
return type | ||
.replace(/[^#\/]*$/, ''); | ||
.replace(/[^#/]*$/, ''); | ||
}) | ||
@@ -29,3 +28,3 @@ .concat([ base + '#' ]) | ||
function removeCircular(items, ancestors) { | ||
function removeCircular (items, ancestors) { | ||
ancestors = ancestors || []; | ||
@@ -56,3 +55,3 @@ items.forEach(function (item) { | ||
function rdfToJson(triples, config) { | ||
function rdfToJson (triples, config) { | ||
var itemMap = triples.reduce(function (itemMap, triple) { | ||
@@ -105,3 +104,2 @@ var id = triple.subject; | ||
} | ||
}); | ||
@@ -108,0 +106,0 @@ |
@@ -15,3 +15,3 @@ 'use strict'; | ||
function equivalentObjects(objA, objB) { | ||
function equivalentObjects (objA, objB) { | ||
var keysA = Object.keys(objA); | ||
@@ -34,3 +34,3 @@ var keysB = Object.keys(objB); | ||
function rdfObjectToJsonldObject(object, useNativeTypes) { | ||
function rdfObjectToJsonldObject (object, useNativeTypes) { | ||
if (object.id) { | ||
@@ -68,3 +68,3 @@ return { '@id': object.id }; | ||
function isWellFormedListNode(node) { | ||
function isWellFormedListNode (node) { | ||
if (!node.usages || node.usages.length !== 1) { | ||
@@ -85,3 +85,3 @@ return false; | ||
function getGraphs(triples) { | ||
function getGraphs (triples) { | ||
return triples.reduce(function (graphs, triple) { | ||
@@ -96,3 +96,3 @@ var name = triple.graph || ''; | ||
// http://www.w3.org/TR/json-ld-api/#serialize-rdf-as-json-ld-algorithm | ||
function rdfToJsonld(triples, config) { | ||
function rdfToJsonld (triples, config) { | ||
var useRdfType = config.useRdfType; | ||
@@ -99,0 +99,0 @@ var useNativeTypes = config.useNativeTypes; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
function formatId(id) { | ||
function formatId (id) { | ||
if (/^_:/.test(id)) { | ||
@@ -13,3 +13,3 @@ return id; | ||
function formatValue(object) { | ||
function formatValue (object) { | ||
if (object.id) { | ||
@@ -20,3 +20,3 @@ return formatId(object.id); | ||
var value = String(object.value) | ||
.replace(/"/gm, '\\\"') | ||
.replace(/"/gm, '\\"') | ||
.replace(/\n/gm, '\\n'); | ||
@@ -31,3 +31,3 @@ if (object.type && object.type !== 'http://www.w3.org/2001/XMLSchema#string') { | ||
function tripleToNquad(triple) { | ||
function tripleToNquad (triple) { | ||
return util.format('%s %s %s.', | ||
@@ -40,3 +40,3 @@ formatId(triple.subject), | ||
function toNquads(triples) { | ||
function toNquads (triples) { | ||
return triples | ||
@@ -43,0 +43,0 @@ .map(tripleToNquad) |
'use strict'; | ||
function tokenize(string) { | ||
function combine(/* patterns */) { | ||
function tokenize (string) { | ||
function combine (/* patterns */) { | ||
var regexStr = Array.prototype.slice.call(arguments, 0) | ||
@@ -29,3 +28,3 @@ .map(function (pattern) { | ||
var BOOL_FALSE = /false/; | ||
var PN_LOCAL_ESC = /\\[-_~.!$&'()*+,;=\/?#@%]/; | ||
var PN_LOCAL_ESC = /\\[-_~.!$&'()*+,;=/?#@%]/; | ||
var HEX = /[0-9A-Fa-f]/; | ||
@@ -45,3 +44,5 @@ var PERCENT = combine(/%/, HEX, HEX); | ||
var STRING_LITERAL_LONG_SINGLE_QUOTE = combine(/'''/, '(?:(?:', /'|''/, ')?', '(?:', /[^'\\]/, '|', ECHAR, '|', UCHAR, '))*', /'''/); | ||
// eslint-disable-next-line no-control-regex | ||
var STRING_LITERAL_SINGLE_QUOTE = combine(/'/, '(?:', /[^\x22\x5C\x0A\x0D]/, '|', ECHAR, '|', UCHAR, ')*', /'/); | ||
// eslint-disable-next-line no-control-regex | ||
var STRING_LITERAL_QUOTE = combine(/"/, '(?:', /[^\x22\x5C\x0A\x0D]/, '|', ECHAR, '|', UCHAR, ')*', /"/); | ||
@@ -56,4 +57,5 @@ var EXPONENT = /[eE][+-]?[0-9]+/; | ||
var PNAME_LN = combine(PNAME_NS, PN_LOCAL); | ||
var IRIREF = combine(/</,'(', /[^\x00-\x20<>"{}|^`\\]/,')*',/>/); | ||
// eslint-disable-next-line no-control-regex | ||
var IRIREF = combine(/</, '(', /[^\x00-\x20<>"{}|^`\\]/, ')*', />/); | ||
var terminalBaseRe = { | ||
@@ -100,3 +102,2 @@ OPEN_BRACE: OPEN_BRACE, | ||
var terminalRe = Object.keys(terminalBaseRe) | ||
@@ -109,3 +110,3 @@ .reduce(function (terminalRe, name) { | ||
function longestMatch(string) { | ||
function longestMatch (string) { | ||
return Object.keys(terminalRe) | ||
@@ -140,12 +141,1 @@ .reduce(function (longestToken, name) { | ||
module.exports = tokenize; | ||
{ | ||
"name": "microdata-node", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"description": "Microdata to json and json-ld parser", | ||
@@ -9,5 +9,4 @@ "main": "lib", | ||
"mocha": "mocha ./test", | ||
"mocha-watch": "mocha -w ./test", | ||
"lint": "jshint --reporter node_modules/jshint-stylish/stylish.js .", | ||
"code-style": "jscs .", | ||
"watch:mocha": "npm run mocha -- -w", | ||
"lint": "semistandard --verbose | snazzy", | ||
"download-tests": "node ./scripts/download-tests.js", | ||
@@ -31,19 +30,18 @@ "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" | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"jscs": "^1.9.0", | ||
"jshint": "^2.5.10", | ||
"jshint-stylish": "^1.0.0", | ||
"jsonld": "^0.3.15", | ||
"mocha": "^2.0.1", | ||
"n3": "^0.4.1", | ||
"request": "^2.51.0" | ||
"chai": "^4.1.2", | ||
"jsonld": "^0.4.12", | ||
"mocha": "^4.1.0", | ||
"n3": "^0.11.2", | ||
"request": "^2.51.0", | ||
"semistandard": "^12.0.0", | ||
"snazzy": "^7.0.0" | ||
}, | ||
"dependencies": { | ||
"array-unique": "^0.1.1", | ||
"array-unique": "^0.3.2", | ||
"domutils": "^1.5.1", | ||
"es6-map": "^0.1.1", | ||
"extend": "^2.0.0", | ||
"extend": "^3.0.1", | ||
"htmlparser2": "^3.8.2", | ||
"is-absolute-url": "^1.0.0" | ||
"is-absolute-url": "^2.1.0" | ||
} | ||
} |
@@ -8,6 +8,6 @@ 'use strict'; | ||
var path = require('path'); | ||
var OUTPUT = path.resolve(__dirname, '../test/suite'); | ||
var OUTPUT = path.resolve(__dirname, '../test/w3c-tests'); | ||
var registry = null; | ||
function fetchManifestEntry(manifest) { | ||
function fetchManifestEntry (manifest) { | ||
if (!fs.existsSync(OUTPUT)) fs.mkdirSync(OUTPUT); | ||
@@ -30,7 +30,9 @@ var folderPath = OUTPUT + '/' + manifest.name; | ||
} else { | ||
fs.writeFile(folderPath + '/registry.json', JSON.stringify(registry, null, 2)); | ||
fs.writeFile(folderPath + '/registry.json', JSON.stringify(registry, null, 2), function () { | ||
return null; | ||
}); | ||
} | ||
} | ||
function fetchTests(callback) { | ||
function fetchTests (callback) { | ||
request.get({ | ||
@@ -58,3 +60,3 @@ url: BASE_URL + '/manifest.jsonld', | ||
} | ||
fetchTests(function (err) { | ||
@@ -61,0 +63,0 @@ if (err) return console.log(err.stack); |
@@ -5,7 +5,6 @@ /* global describe, it */ | ||
var assert = require('chai').assert, | ||
parser = require('..'); | ||
var assert = require('chai').assert; | ||
var parser = require('..'); | ||
describe('itemprop', function () { | ||
it('handles <meta> elements', function () { | ||
@@ -50,3 +49,3 @@ var html = | ||
assert.deepEqual(result.items[0].properties, { | ||
audioProp: [ | ||
audioProp: [ | ||
'http://www.example.com/audio', | ||
@@ -56,3 +55,3 @@ '', | ||
], | ||
embedProp: [ | ||
embedProp: [ | ||
'', | ||
@@ -62,3 +61,3 @@ 'http://www.absolute.com/embed', | ||
], | ||
iframeProp: [ | ||
iframeProp: [ | ||
'http://www.example.com/iframe', | ||
@@ -68,3 +67,3 @@ '', | ||
], | ||
imgProp: [ | ||
imgProp: [ | ||
'http://www.absolute.com/img', | ||
@@ -74,3 +73,3 @@ '', | ||
], | ||
sourceProp: [ | ||
sourceProp: [ | ||
'http://www.absolute.com/source', | ||
@@ -80,3 +79,3 @@ 'http://www.example.com/source', | ||
], | ||
trackProp: [ | ||
trackProp: [ | ||
'http://www.absolute.com/track', | ||
@@ -86,3 +85,3 @@ '', | ||
], | ||
videoProp: [ | ||
videoProp: [ | ||
'', | ||
@@ -218,4 +217,4 @@ 'http://www.absolute.com/video', | ||
assert.deepEqual(strictResult.items[0].properties, { | ||
ratingValue: [ '' ], | ||
reviewCount: [ '' ] | ||
ratingValue: [ '4.5' ], | ||
reviewCount: [ '3018' ] | ||
}); | ||
@@ -229,3 +228,2 @@ | ||
}); | ||
}); |
@@ -5,7 +5,6 @@ /* global describe, it */ | ||
var assert = require('chai').assert, | ||
parser = require('..'); | ||
var assert = require('chai').assert; | ||
var parser = require('..'); | ||
describe('itemref', function () { | ||
it('parses itemrefs', function () { | ||
@@ -99,3 +98,2 @@ var html = | ||
}); | ||
}); |
@@ -5,7 +5,6 @@ /* global describe, it */ | ||
var assert = require('chai').assert, | ||
parser = require('..'); | ||
var assert = require('chai').assert; | ||
var parser = require('..'); | ||
describe('parser', function () { | ||
it('finds no data when none defined', function () { | ||
@@ -88,3 +87,3 @@ var html = | ||
it('finds multiple items within an element', function () { | ||
var html = | ||
var html = | ||
'<div>' + | ||
@@ -102,3 +101,3 @@ ' <div itemscope itemtype="http://schema.org/Person">hello</div>' + | ||
it('finds an item with properties', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -118,3 +117,3 @@ ' <div itemprop="name">Jan</div>' + | ||
it('finds an item with childitems', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -132,3 +131,2 @@ ' <div itemprop="address1" itemscope itemtype="http://schema.org/PostalAddress">' + | ||
assert.deepEqual(result.items[0].properties, { | ||
@@ -147,3 +145,3 @@ address1: [{ | ||
it('collates properties', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -162,3 +160,3 @@ ' <div itemprop="name">Jan</div>' + | ||
it('handles empty propertynames', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -174,3 +172,3 @@ ' <div itemprop="">Jan</div>' + | ||
it('handles multiple propertynames', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -189,3 +187,3 @@ ' <div itemprop="name additionalName">Jan</div>' + | ||
it('handles duplicated propertynames', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemtype="http://schema.org/Person">' + | ||
@@ -203,3 +201,3 @@ ' <div itemprop=" name name ">Jan</div>' + | ||
it('finds top level items that are props in non-strict mode', function () { | ||
var html = | ||
var html = | ||
'<div itemscope itemprop="someprop">' + | ||
@@ -220,3 +218,2 @@ ' <div itemprop="name">Jan</div>' + | ||
}); | ||
}); |
@@ -12,7 +12,6 @@ /* global describe, it */ | ||
var fs = require('fs'); | ||
var OUTPUT = __dirname + '/suite'; | ||
var path = require('path'); | ||
var assert = require('chai').assert; | ||
function assertEqualRdf(jsonldExpected, jsonldGot, options, callback) { | ||
function assertEqualRdf (jsonldExpected, jsonldGot, options, callback) { | ||
var opts = { | ||
@@ -40,8 +39,6 @@ base: options.base, | ||
function runOne(testFolder, it) { | ||
var folderPath = OUTPUT + '/' + testFolder; | ||
function runOne (folderPath, it) { | ||
var manifest = JSON.parse(fs.readFileSync(folderPath + '/manifest.json')); | ||
it(manifest.name + ': ' + manifest.comment, function (done) { | ||
var htmlPath = folderPath + '/action.html'; | ||
@@ -53,3 +50,2 @@ var html = fs.readFileSync(htmlPath); | ||
if (manifest['@type'].indexOf('rdft:TestMicrodataEval') >= 0) { | ||
var jsonldGot = toJsonld(html, { base: base, registry: registry, useRdfType: true, strict: true }); | ||
@@ -64,5 +60,3 @@ var ttl = fs.readFileSync(folderPath + '/result.ttl').toString(); | ||
}); | ||
} else if (manifest['@type'].indexOf('rdft:TestMicrodataNegativeSyntax') >= 0) { | ||
assert.throws(function () { | ||
@@ -72,34 +66,33 @@ toJsonld(html, { base: base, registry: registry, useRdfType: true, strict: true }); | ||
done(); | ||
} else { | ||
done(new Error('unknown test type')); | ||
} | ||
}); | ||
} | ||
function runFolder (parent, only = [], skip = []) { | ||
fs.readdirSync(parent) | ||
.forEach(function (folderName) { | ||
var itFn = it; | ||
if (only.includes(folderName)) { | ||
itFn = it.only; | ||
} else if (skip.includes(folderName)) { | ||
itFn = it.skip; | ||
} | ||
var folder = path.resolve(parent, folderName); | ||
runOne(folder, itFn); | ||
}); | ||
} | ||
describe('suite', function () { | ||
var testFolders = fs.readdirSync(OUTPUT), | ||
only = null, | ||
skip = [ 'Test 0081', 'Test 0082', 'Test 0083', 'Test 0084' ]; | ||
//only = 'Test 0071'; | ||
testFolders.forEach(function (folder) { | ||
var itFn = it; | ||
if (folder === only) { | ||
itFn = it.only; | ||
} else if (skip.indexOf(folder) >= 0) { | ||
itFn = it.skip; | ||
} | ||
runOne(folder, itFn); | ||
}); | ||
runFolder( | ||
path.resolve(__dirname, './w3c-tests'), [ | ||
// 'Test 0001' | ||
], [ | ||
'Test 0081', | ||
'Test 0082', | ||
'Test 0083', | ||
'Test 0084' | ||
] | ||
); | ||
}); | ||
@@ -7,4 +7,3 @@ | ||
function expandPrefixedName(name, prefixes) { | ||
function expandPrefixedName (name, prefixes) { | ||
try { | ||
@@ -17,4 +16,4 @@ return n3.Util.expandPrefixedName(name, prefixes); | ||
function n3Totriples(triples, prefixes) { | ||
function toTripleObject(n3Object) { | ||
function n3Totriples (triples, prefixes) { | ||
function toTripleObject (n3Object) { | ||
var object = {}; | ||
@@ -43,3 +42,3 @@ if (n3.Util.isLiteral(n3Object)) { | ||
function ttlToJsonld(turtle, base, callback) { | ||
function ttlToJsonld (turtle, base, callback) { | ||
var triples = []; | ||
@@ -46,0 +45,0 @@ var parser = n3.Parser({ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
197480
7
3462
0
1
+ Addedarray-unique@0.3.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedis-absolute-url@2.1.0(transitive)
- Removedarray-unique@0.1.1(transitive)
- Removedextend@2.0.2(transitive)
- Removedis-absolute-url@1.0.0(transitive)
Updatedarray-unique@^0.3.2
Updatedextend@^3.0.1
Updatedis-absolute-url@^2.1.0