--- a/playground/jsonld.js Thu Apr 17 19:44:29 2014 -0400
+++ b/playground/jsonld.js Fri May 02 10:58:36 2014 -0400
@@ -4,7 +4,7 @@
* @author Dave Longley
*
* BSD 3-Clause License
- * Copyright (c) 2011-2013 Digital Bazaar, Inc.
+ * Copyright (c) 2011-2014 Digital Bazaar, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -44,11 +44,9 @@
if(typeof global === 'undefined') {
if(typeof window !== 'undefined') {
global = window;
- }
- else if(typeof self !== 'undefined') {
+ } else if(typeof self !== 'undefined') {
global = self;
- }
- else if(typeof $ !== 'undefined') {
+ } else if(typeof $ !== 'undefined') {
global = $;
}
}
@@ -152,8 +150,7 @@
// do compaction
compacted = new Processor().compact(
activeCtx, null, expanded, options);
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
@@ -168,17 +165,15 @@
}
if(options.compactArrays && !options.graph && _isArray(compacted)) {
- // simplify to a single item
if(compacted.length === 1) {
+ // simplify to a single item
compacted = compacted[0];
- }
- // simplify to an empty object
- else if(compacted.length === 0) {
+ } else if(compacted.length === 0) {
+ // simplify to an empty object
compacted = {};
}
- }
- // always use array if graph option is on
- else if(options.graph && _isObject(compacted)) {
+ } else if(options.graph && _isObject(compacted)) {
+ // always use array if graph option is on
compacted = [compacted];
}
@@ -217,8 +212,7 @@
compacted['@context'] = ctx;
}
compacted[kwgraph] = graph;
- }
- else if(_isObject(compacted) && hasContext) {
+ } else if(_isObject(compacted) && hasContext) {
// reorder keys so @context is first
var graph = compacted;
compacted = {'@context': ctx};
@@ -281,8 +275,7 @@
if(typeof remoteDoc.document === 'string') {
remoteDoc.document = JSON.parse(remoteDoc.document);
}
- }
- catch(ex) {
+ } catch(ex) {
return callback(new JsonLdError(
'Could not retrieve a JSON-LD document from the URL. URL ' +
'dereferencing not implemented.', 'jsonld.LoadDocumentError', {
@@ -317,8 +310,7 @@
var expandContext = _clone(options.expandContext);
if(typeof expandContext === 'object' && '@context' in expandContext) {
input.expandContext = expandContext;
- }
- else {
+ } else {
input.expandContext = {'@context': expandContext};
}
}
@@ -354,8 +346,7 @@
if(_isObject(expanded) && ('@graph' in expanded) &&
Object.keys(expanded).length === 1) {
expanded = expanded['@graph'];
- }
- else if(expanded === null) {
+ } else if(expanded === null) {
expanded = [];
}
@@ -363,8 +354,7 @@
if(!_isArray(expanded)) {
expanded = [expanded];
}
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
callback(null, expanded);
@@ -394,8 +384,7 @@
if(typeof options === 'function') {
callback = options;
options = {};
- }
- else if(typeof ctx === 'function') {
+ } else if(typeof ctx === 'function') {
callback = ctx;
ctx = null;
options = {};
@@ -422,8 +411,7 @@
try {
// do flattening
flattened = new Processor().flatten(_input);
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
@@ -502,8 +490,7 @@
if(typeof remoteDoc.document === 'string') {
remoteDoc.document = JSON.parse(remoteDoc.document);
}
- }
- catch(ex) {
+ } catch(ex) {
return callback(new JsonLdError(
'Could not retrieve a JSON-LD document from the URL. URL ' +
'dereferencing not implemented.', 'jsonld.LoadDocumentError', {
@@ -533,20 +520,16 @@
if(remoteFrame.contextUrl) {
if(!ctx) {
ctx = remoteFrame.contextUrl;
- }
- else if(_isArray(ctx)) {
+ } else if(_isArray(ctx)) {
ctx.push(remoteFrame.contextUrl);
- }
- else {
+ } else {
ctx = [ctx, remoteFrame.contextUrl];
}
frame['@context'] = ctx;
- }
- else {
+ } else {
ctx = ctx || {};
}
- }
- else {
+ } else {
ctx = {};
}
@@ -573,8 +556,7 @@
try {
// do framing
framed = new Processor().frame(expanded, expandedFrame, opts);
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
@@ -637,8 +619,7 @@
try {
// flatten the graph
flattened = new Processor().flatten(_input);
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
@@ -685,19 +666,16 @@
if(_isString(obj) && isid) {
subject[k] = obj = top[obj];
recurse(obj);
- }
- else if(_isArray(obj)) {
+ } else if(_isArray(obj)) {
for(var i = 0; i < obj.length; ++i) {
if(_isString(obj[i]) && isid) {
obj[i] = top[obj[i]];
- }
- else if(_isObject(obj[i]) && '@id' in obj[i]) {
+ } else if(_isObject(obj[i]) && '@id' in obj[i]) {
obj[i] = top[obj[i]['@id']];
}
recurse(obj[i]);
}
- }
- else if(_isObject(obj)) {
+ } else if(_isObject(obj)) {
var sid = obj['@id'];
subject[k] = obj = top[sid];
recurse(obj);
@@ -834,8 +812,7 @@
'Unknown input format.',
'jsonld.UnknownFormat', {format: options.format}));
}
- }
- else {
+ } else {
// no-op parser, assume dataset already parsed
rdfParser = function() {
return dataset;
@@ -924,8 +901,7 @@
'Unknown output format.',
'jsonld.UnknownFormat', {format: options.format});
}
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
callback(null, dataset);
@@ -1047,8 +1023,7 @@
jsonld.promisify = function(op) {
try {
var Promise = global.Promise || require('es6-promise').Promise;
- }
- catch(e) {
+ } catch(e) {
throw new Error('Unable to find a Promise implementation.');
}
var args = Array.prototype.slice.call(arguments, 1);
@@ -1056,8 +1031,7 @@
op.apply(null, args.concat(function(err, value) {
if(!err) {
resolve(value);
- }
- else {
+ } else {
reject(err);
}
}));
@@ -1083,8 +1057,7 @@
if(canDefineProperty) {
try {
Object.defineProperty({}, 'x', {});
- }
- catch(e) {
+ } catch(e) {
canDefineProperty = false;
}
}
@@ -1111,8 +1084,7 @@
configurable: true,
value: JsonLdProcessor
});
- }
- else {
+ } else {
global.JsonLdProcessor = JsonLdProcessor;
}
}
@@ -1125,20 +1097,17 @@
jsonld.setImmediate = jsonld.nextTick = function(callback) {
return setImmediate(callback);
};
- }
- else {
+ } else {
jsonld.setImmediate = function(callback) {
setTimeout(callback, 0);
};
jsonld.nextTick = jsonld.setImmediate;
}
-}
-else {
+} else {
jsonld.nextTick = process.nextTick;
if(typeof setImmediate === 'function') {
jsonld.setImmediate = setImmediate;
- }
- else {
+ } else {
jsonld.setImmediate = jsonld.nextTick;
}
}
@@ -1179,11 +1148,9 @@
var rel = result['rel'] || '';
if(_isArray(rval[rel])) {
rval[rel].push(result);
- }
- else if(rel in rval) {
+ } else if(rel in rval) {
rval[rel] = [rval[rel], result];
- }
- else {
+ } else {
rval[rel] = result;
}
}
@@ -1301,6 +1268,10 @@
accepts: {
json: 'application/ld+json, application/json'
},
+ // ensure Accept header is very specific for JSON-LD/JSON
+ headers: {
+ 'Accept': 'application/ld+json, application/json'
+ },
dataType: 'json',
crossDomain: true,
success: function(data, textStatus, jqXHR) {
@@ -1549,7 +1520,6 @@
};
req.open('GET', url, true);
req.setRequestHeader('Accept', 'application/ld+json, application/json');
- req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.send();
};
@@ -1633,8 +1603,7 @@
try {
// process context
ctx = new Processor().processContext(activeCtx, ctx, options);
- }
- catch(ex) {
+ } catch(ex) {
return callback(ex);
}
callback(null, ctx);
@@ -1682,9 +1651,8 @@
break;
}
}
- }
- // avoid matching the set of values with an array value parameter
- else if(!_isArray(value)) {
+ } else if(!_isArray(value)) {
+ // avoid matching the set of values with an array value parameter
rval = jsonld.compareValues(value, val);
}
}
@@ -1721,8 +1689,7 @@
for(var i = 0; i < value.length; ++i) {
jsonld.addValue(subject, property, value[i], options);
}
- }
- else if(property in subject) {
+ } else if(property in subject) {
// check if subject already has value if duplicates not allowed
var hasValue = (!options.allowDuplicate &&
jsonld.hasValue(subject, property, value));
@@ -1737,8 +1704,7 @@
if(!hasValue) {
subject[property].push(value);
}
- }
- else {
+ } else {
// add new value as set or single value
subject[property] = options.propertyIsArray ? [value] : value;
}
@@ -1793,11 +1759,9 @@
if(values.length === 0) {
jsonld.removeProperty(subject, property);
- }
- else if(values.length === 1 && !options.propertyIsArray) {
+ } else if(values.length === 1 && !options.propertyIsArray) {
subject[property] = values[0];
- }
- else {
+ } else {
subject[property] = values;
}
};
@@ -1867,12 +1831,11 @@
if(ctx.mappings[key]) {
var entry = ctx.mappings[key];
- // return whole entry
if(_isUndefined(type)) {
+ // return whole entry
rval = entry;
- }
- // return entry value for type
- else if(type in entry) {
+ } else if(type in entry) {
+ // return entry value for type
rval = entry[type];
}
}
@@ -2047,9 +2010,8 @@
compactedValue = _compactIri(
activeCtx, expandedValue, null,
{vocab: (expandedProperty === '@type')});
- }
- // expanded value must be a @type array
- else {
+ } else {
+ // expanded value must be a @type array
compactedValue = [];
for(var vi = 0; vi < expandedValue.length; ++vi) {
compactedValue.push(_compactIri(
@@ -2160,9 +2122,8 @@
compactedItem[_compactIri(activeCtx, '@index')] =
expandedItem['@index'];
}
- }
- // can't use @list container for more than 1 list
- else if(itemActiveProperty in rval) {
+ } else if(itemActiveProperty in rval) {
+ // can't use @list container for more than 1 list
throw new JsonLdError(
'JSON-LD compact error; property has a "@list" @container ' +
'rule but there is more than a single @list that matches ' +
@@ -2178,8 +2139,7 @@
var mapObject;
if(itemActiveProperty in rval) {
mapObject = rval[itemActiveProperty];
- }
- else {
+ } else {
rval[itemActiveProperty] = mapObject = {};
}
@@ -2192,8 +2152,7 @@
// add compact value to map object using key from expanded value
// based on the container type
jsonld.addValue(mapObject, expandedItem[container], compactedItem);
- }
- else {
+ } else {
// use an array if: compactArrays flag is false,
// @container is @set or @list , value is an empty
// array, or key is @graph
@@ -2269,8 +2228,7 @@
if(e !== null) {
if(_isArray(e)) {
rval = rval.concat(e);
- }
- else {
+ } else {
rval.push(e);
}
}
@@ -2434,12 +2392,11 @@
var container = jsonld.getContextValue(activeCtx, key, '@container');
- // handle language map container (skip if value is not an object)
if(container === '@language' && _isObject(value)) {
+ // handle language map container (skip if value is not an object)
expandedValue = _expandLanguageMap(value);
- }
- // handle index container (skip if value is not an object)
- else if(container === '@index' && _isObject(value)) {
+ } else if(container === '@index' && _isObject(value)) {
+ // handle index container (skip if value is not an object)
expandedValue = (function _expandIndexMap(activeProperty) {
var rval = [];
var keys = Object.keys(value).sort();
@@ -2460,8 +2417,7 @@
}
return rval;
})(key);
- }
- else {
+ } else {
// recurse into @list or @set
var isList = (expandedProperty === '@list');
if(isList || expandedProperty === '@set') {
@@ -2476,8 +2432,7 @@
'Invalid JSON-LD syntax; lists of lists are not permitted.',
'jsonld.SyntaxError', {code: 'list of lists'});
}
- }
- else {
+ } else {
// recursively expand value with key as new active property
expandedValue = self.expand(activeCtx, key, value, options, false);
}
@@ -2559,28 +2514,24 @@
// drop null @values
if(rval['@value'] === null) {
rval = null;
- }
- // if @language is present, @value must be a string
- else if('@language' in rval && !_isString(rval['@value'])) {
+ } else if('@language' in rval && !_isString(rval['@value'])) {
+ // if @language is present, @value must be a string
throw new JsonLdError(
'Invalid JSON-LD syntax; only strings may be language-tagged.',
'jsonld.SyntaxError',
{code: 'invalid language-tagged value', element: rval});
- }
- else if('@type' in rval && (!_isAbsoluteIri(rval['@type']) ||
+ } else if('@type' in rval && (!_isAbsoluteIri(rval['@type']) ||
rval['@type'].indexOf('_:') === 0)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; an element containing "@value" and "@type" ' +
'must have an absolute IRI for the value of "@type".',
'jsonld.SyntaxError', {code: 'invalid typed value', element: rval});
}
- }
- // convert @type to an array
- else if('@type' in rval && !_isArray(rval['@type'])) {
+ } else if('@type' in rval && !_isArray(rval['@type'])) {
+ // convert @type to an array
rval['@type'] = [rval['@type']];
- }
- // handle @set and @list
- else if('@set' in rval || '@list' in rval) {
+ } else if('@set' in rval || '@list' in rval) {
+ // handle @set and @list
if(count > 1 && !(count === 2 && '@index' in rval)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; if an element has the property "@set" ' +
@@ -2594,9 +2545,8 @@
keys = Object.keys(rval);
count = keys.length;
}
- }
- // drop objects with only @language
- else if(count === 1 && '@language' in rval) {
+ } else if(count === 1 && '@language' in rval) {
+ // drop objects with only @language
rval = null;
}
@@ -2642,8 +2592,7 @@
'@id': graphName,
'@graph': []
};
- }
- else if(!('@graph' in subject)) {
+ } else if(!('@graph' in subject)) {
subject['@graph'] = [];
}
var graph = subject['@graph'];
@@ -2719,8 +2668,7 @@
if(graphName !== null) {
if(graphName.indexOf('_:') === 0) {
quad.name = {type: 'blank node', value: graphName};
- }
- else {
+ } else {
quad.name = {type: 'IRI', value: graphName};
}
}
@@ -2733,8 +2681,7 @@
var id = quad[attr].value;
if(id in bnodes) {
bnodes[id].quads.push(quad);
- }
- else {
+ } else {
bnodes[id] = {quads: [quad]};
}
}
@@ -2768,14 +2715,12 @@
if(hash in duplicates) {
duplicates[hash].push(bnode);
nextUnnamed.push(bnode);
- }
- else if(hash in unique) {
+ } else if(hash in unique) {
duplicates[hash] = [unique[hash], bnode];
nextUnnamed.push(unique[hash]);
nextUnnamed.push(bnode);
delete unique[hash];
- }
- else {
+ } else {
unique[hash] = bnode;
}
@@ -2795,12 +2740,11 @@
named = true;
}
- // continue to hash bnodes if a bnode was assigned a name
if(named) {
+ // continue to hash bnodes if a bnode was assigned a name
hashBlankNodes(unnamed);
- }
- // name the duplicate hash bnodes
- else {
+ } else {
+ // name the duplicate hash bnodes
nameDuplicates(duplicates);
}
}
@@ -3162,14 +3106,12 @@
// clear base
if(base === null) {
base = null;
- }
- else if(!_isString(base)) {
+ } else if(!_isString(base)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; the value of "@base" in a ' +
'@context must be a string or null.',
'jsonld.SyntaxError', {code: 'invalid base IRI', context: ctx});
- }
- else if(base !== '' && !_isAbsoluteIri(base)) {
+ } else if(base !== '' && !_isAbsoluteIri(base)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; the value of "@base" in a ' +
'@context must be an absolute IRI or the empty string.',
@@ -3188,20 +3130,17 @@
var value = ctx['@vocab'];
if(value === null) {
delete rval['@vocab'];
- }
- else if(!_isString(value)) {
+ } else if(!_isString(value)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; the value of "@vocab" in a ' +
'@context must be a string or null.',
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
- }
- else if(!_isAbsoluteIri(value)) {
+ } else if(!_isAbsoluteIri(value)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; the value of "@vocab" in a ' +
'@context must be an absolute IRI.',
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
- }
- else {
+ } else {
rval['@vocab'] = value;
}
defined['@vocab'] = true;
@@ -3212,15 +3151,13 @@
var value = ctx['@language'];
if(value === null) {
delete rval['@language'];
- }
- else if(!_isString(value)) {
+ } else if(!_isString(value)) {
throw new JsonLdError(
'Invalid JSON-LD syntax; the value of "@language" in a ' +
'@context must be a string or null.',
'jsonld.SyntaxError',
{code: 'invalid default language', context: ctx});
- }
- else {
+ } else {
rval['@language'] = value.toLowerCase();
}
defined['@language'] = true;
@@ -3286,11 +3223,9 @@
for(var i = 0; i < element.length; ++i) {
element[i] = _labelBlankNodes(namer, element[i]);
}
- }
- else if(_isList(element)) {
+ } else if(_isList(element)) {
element['@list'] = _labelBlankNodes(namer, element['@list']);
- }
- else if(_isObject(element)) {
+ } else if(_isObject(element)) {
// rename blank node
if(_isBlankNode(element)) {
element['@id'] = namer.getName(element['@id']);
@@ -3329,8 +3264,7 @@
var expandedProperty = _expandIri(activeCtx, activeProperty, {vocab: true});
if(expandedProperty === '@id') {
return _expandIri(activeCtx, value, {base: true});
- }
- else if(expandedProperty === '@type') {
+ } else if(expandedProperty === '@type') {
return _expandIri(activeCtx, value, {vocab: true, base: true});
}
@@ -3353,12 +3287,11 @@
var rval = {};
- // other type
if(type !== null) {
+ // other type
rval['@type'] = type;
- }
- // check for language tagging for strings
- else if(_isString(value)) {
+ } else if(_isString(value)) {
+ // check for language tagging for strings
var language = jsonld.getContextValue(
activeCtx, activeProperty, '@language');
if(language !== null) {
@@ -3392,8 +3325,7 @@
var items = node[property];
if(property === '@type') {
property = RDF_TYPE;
- }
- else if(_isKeyword(property)) {
+ } else if(_isKeyword(property)) {
continue;
}
@@ -3428,11 +3360,9 @@
// convert @list to triples
if(_isList(item)) {
_listToRDF(item['@list'], namer, subject, predicate, rval);
- }
- // convert value or node object to triple
- else {
+ } else {
+ // convert value or node object to triple
var object = _objectToRDF(item);
-
// skip null objects (they are relative IRIs)
if(object) {
rval.push({subject: subject, predicate: predicate, object: object});
@@ -3502,28 +3432,23 @@
if(_isBoolean(value)) {
object.value = value.toString();
object.datatype = datatype || XSD_BOOLEAN;
- }
- else if(_isDouble(value) || datatype === XSD_DOUBLE) {
+ } else if(_isDouble(value) || datatype === XSD_DOUBLE) {
// canonical double representation
object.value = value.toExponential(15).replace(/(\d)0*e\+?/, '$1E');
object.datatype = datatype || XSD_DOUBLE;
- }
- else if(_isNumber(value)) {
+ } else if(_isNumber(value)) {
object.value = value.toFixed(0);
object.datatype = datatype || XSD_INTEGER;
- }
- else if('@language' in item) {
+ } else if('@language' in item) {
object.value = value;
object.datatype = datatype || RDF_LANGSTRING;
object.language = item['@language'];
- }
- else {
+ } else {
object.value = value;
object.datatype = datatype || XSD_STRING;
}
- }
- // convert string/node object to RDF
- else {
+ } else {
+ // convert string/node object to RDF
var id = _isObject(item) ? item['@id'] : item;
object.type = (id.indexOf('_:') === 0) ? 'blank node' : 'IRI';
object.value = id;
@@ -3557,8 +3482,7 @@
// add language
if(o['language']) {
rval['@language'] = o.language;
- }
- else {
+ } else {
var type = o.datatype;
if(!type) {
type = XSD_STRING;
@@ -3568,19 +3492,16 @@
if(type === XSD_BOOLEAN) {
if(rval['@value'] === 'true') {
rval['@value'] = true;
- }
- else if(rval['@value'] === 'false') {
+ } else if(rval['@value'] === 'false') {
rval['@value'] = false;
}
- }
- else if(_isNumeric(rval['@value'])) {
+ } else if(_isNumeric(rval['@value'])) {
if(type === XSD_INTEGER) {
var i = parseInt(rval['@value']);
if(i.toFixed(0) === rval['@value']) {
rval['@value'] = i;
}
- }
- else if(type === XSD_DOUBLE) {
+ } else if(type === XSD_DOUBLE) {
rval['@value'] = parseFloat(rval['@value']);
}
}
@@ -3589,8 +3510,7 @@
.indexOf(type) === -1) {
rval['@type'] = type;
}
- }
- else if(type !== XSD_STRING) {
+ } else if(type !== XSD_STRING) {
rval['@type'] = type;
}
}
@@ -3687,8 +3607,7 @@
if(bnode !== null) {
// normal property
direction = 'p';
- }
- else {
+ } else {
bnode = _getAdjacentBlankNodeName(quad.object, id);
if(bnode !== null) {
// reverse property
@@ -3701,11 +3620,9 @@
var name;
if(namer.isNamed(bnode)) {
name = namer.getName(bnode);
- }
- else if(pathNamer.isNamed(bnode)) {
+ } else if(pathNamer.isNamed(bnode)) {
name = pathNamer.getName(bnode);
- }
- else {
+ } else {
name = _hashQuads(bnode, bnodes, namer);
}
@@ -3719,8 +3636,7 @@
// add bnode to hash group
if(groupHash in groups) {
groups[groupHash].push(bnode);
- }
- else {
+ } else {
groups[groupHash] = [bnode];
}
}
@@ -3757,8 +3673,7 @@
// use canonical name if available
if(namer.isNamed(bnode)) {
path += namer.getName(bnode);
- }
- else {
+ } else {
// recurse if bnode isn't named in the path yet
if(!pathNamerCopy.isNamed(bnode)) {
recurse.push(bnode);
@@ -3812,8 +3727,7 @@
// do next permutation
if(permutator.hasNext()) {
jsonld.setImmediate(function() {permutate();});
- }
- else {
+ } else {
// digest chosen path and update namer
md.update(chosenPath);
pathNamer = chosenNamer;
@@ -3994,18 +3908,16 @@
subject, property, {'@id': id},
{propertyIsArray: true, allowDuplicate: false});
_createNodeMap(o, graphs, graph, namer, id);
- }
- // handle @list
- else if(_isList(o)) {
+ } else if(_isList(o)) {
+ // handle @list
var _list = [];
_createNodeMap(o['@list'], graphs, graph, namer, name, _list);
o = {'@list': _list};
jsonld.addValue(
subject, property, o,
{propertyIsArray: true, allowDuplicate: false});
- }
- // handle @value
- else {
+ } else {
+ // handle @value
_createNodeMap(o, graphs, graph, namer, name);
jsonld.addValue(
subject, property, o, {propertyIsArray: true, allowDuplicate: false});
@@ -4071,9 +3983,8 @@
break;
}
}
- }
- // existing embed's parent is an object
- else if(jsonld.hasValue(existing.parent, existing.property, output)) {
+ } else if(jsonld.hasValue(existing.parent, existing.property, output)) {
+ // existing embed's parent is an object
embedOn = true;
}
@@ -4086,8 +3997,7 @@
// not embedding, add output without any other properties
if(!embedOn) {
_addFrameOutput(state, parent, property, output);
- }
- else {
+ } else {
// add embed meta info
state.embeds[id] = embed;
@@ -4127,25 +4037,23 @@
var src = o['@list'];
for(var n in src) {
o = src[n];
- // recurse into subject reference
if(_isSubjectReference(o)) {
+ // recurse into subject reference
_frame(state, [o['@id']], frame[prop][0]['@list'],
list, '@list');
- }
- // include other values automatically
- else {
+ } else {
+ // include other values automatically
_addFrameOutput(state, list, '@list', _clone(o));
}
}
continue;
}
- // recurse into subject reference
if(_isSubjectReference(o)) {
+ // recurse into subject reference
_frame(state, [o['@id']], frame[prop], output, prop);
- }
- // include other values automatically
- else {
+ } else {
+ // include other values automatically
_addFrameOutput(state, output, prop, _clone(o));
}
}
@@ -4310,9 +4218,8 @@
}
}
_addFrameOutput(state, output, property, o);
- }
- // copy non-subject value
- else {
+ } else {
+ // copy non-subject value
_addFrameOutput(state, output, property, _clone(o));
}
}
@@ -4343,8 +4250,7 @@
break;
}
}
- }
- else {
+ } else {
// replace subject with reference
var useArray = _isArray(parent[property]);
jsonld.removeValue(parent, property, subject, {propertyIsArray: useArray});
@@ -4378,8 +4284,7 @@
function _addFrameOutput(state, parent, property, output) {
if(_isObject(parent)) {
jsonld.addValue(parent, property, output, {propertyIsArray: true});
- }
- else {
+ } else {
parent.push(output);
}
}
@@ -4405,8 +4310,7 @@
}
}
input = output;
- }
- else if(_isObject(input)) {
+ } else if(_isObject(input)) {
// remove @preserve
if('@preserve' in input) {
if(input['@preserve'] === '@null') {
@@ -4452,10 +4356,10 @@
if(a.length < b.length) {
return -1;
}
- else if(b.length < a.length) {
+ if(b.length < a.length) {
return 1;
}
- else if(a === b) {
+ if(a === b) {
return 0;
}
return (a < b) ? -1 : 1;
@@ -4496,13 +4400,11 @@
activeCtx.mappings[term]['@id'] === value['@id']) {
// prefer @vocab
prefs.push.apply(prefs, ['@vocab', '@id']);
- }
- else {
+ } else {
// prefer @id
prefs.push.apply(prefs, ['@id', '@vocab']);
}
- }
- else {
+ } else {
prefs.push(typeOrLanguageValue);
}
prefs.push('@none');
@@ -4583,9 +4485,8 @@
typeOrLanguage = '@type';
typeOrLanguageValue = '@reverse';
containers.push('@set');
- }
- // choose the most specific term that works for all elements in @list
- else if(_isList(value)) {
+ } else if(_isList(value)) {
+ // choose the most specific term that works for all elements in @list
// only select @list containers if @index is NOT in value
if(!('@index' in value)) {
containers.push('@list');
@@ -4600,28 +4501,23 @@
if(_isValue(item)) {
if('@language' in item) {
itemLanguage = item['@language'];
- }
- else if('@type' in item) {
+ } else if('@type' in item) {
itemType = item['@type'];
- }
- // plain literal
- else {
+ } else {
+ // plain literal
itemLanguage = '@null';
}
- }
- else {
+ } else {
itemType = '@id';
}
if(commonLanguage === null) {
commonLanguage = itemLanguage;
- }
- else if(itemLanguage !== commonLanguage && _isValue(item)) {
+ } else if(itemLanguage !== commonLanguage && _isValue(item)) {
commonLanguage = '@none';
}
if(commonType === null) {
commonType = itemType;
- }
- else if(itemType !== commonType) {
+ } else if(itemType !== commonType) {
commonType = '@none';
}
// there are different languages and types in the list, so choose
@@ -4635,23 +4531,19 @@
if(commonType !== '@none') {
typeOrLanguage = '@type';
typeOrLanguageValue = commonType;
- }
- else {
+ } else {
typeOrLanguageValue = commonLanguage;
}
- }
- else {
+ } else {
if(_isValue(value)) {
if('@language' in value && !('@index' in value)) {
containers.push('@language');
typeOrLanguageValue = value['@language'];
- }
- else if('@type' in value) {
+ } else if('@type' in value) {
typeOrLanguage = '@type';
typeOrLanguageValue = value['@type'];
}
- }
- else {
+ } else {
typeOrLanguage = '@type';
typeOrLanguageValue = '@id';
}
@@ -4782,13 +4674,12 @@
rval[_compactIri(activeCtx, '@index')] = value['@index'];
}
- // compact @type IRI
if('@type' in value) {
+ // compact @type IRI
rval[_compactIri(activeCtx, '@type')] = _compactIri(
activeCtx, value['@type'], null, {vocab: true});
- }
- // alias @language
- else if('@language' in value) {
+ } else if('@language' in value) {
+ // alias @language
rval[_compactIri(activeCtx, '@language')] = value['@language'];
}
@@ -4902,8 +4793,7 @@
}
mapping['@id'] = id;
mapping.reverse = true;
- }
- else if('@id' in value) {
+ } else if('@id' in value) {
var id = value['@id'];
if(!_isString(id)) {
throw new JsonLdError(
@@ -4936,17 +4826,15 @@
_createTermDefinition(activeCtx, localCtx, prefix, defined);
}
- // set @id based on prefix parent
if(activeCtx.mappings[prefix]) {
+ // set @id based on prefix parent
var suffix = term.substr(colon + 1);
mapping['@id'] = activeCtx.mappings[prefix]['@id'] + suffix;
- }
- // term is an absolute IRI
- else {
+ } else {
+ // term is an absolute IRI
mapping['@id'] = term;
}
- }
- else {
+ } else {
// non-IRIs *must* define @ids if @vocab is not available
if(!('@vocab' in activeCtx)) {
throw new JsonLdError(
@@ -5156,8 +5044,7 @@
var hierPart = (base.protocol || '');
if(rel.authority) {
hierPart += '//' + rel.authority;
- }
- else if(base.href !== '') {
+ } else if(base.href !== '') {
hierPart += '//' + base.authority;
}
@@ -5167,8 +5054,7 @@
// IRI represents an absolute path
if(rel.pathname.indexOf('/') === 0) {
path = rel.pathname;
- }
- else {
+ } else {
path = base.pathname;
// append relative path to the end of the last directory from base
@@ -5223,9 +5109,8 @@
var root = '';
if(base.href !== '') {
root += (base.protocol || '') + '//' + base.authority;
- }
- // support network-path reference with empty base
- else if(iri.indexOf('//')) {
+ } else if(iri.indexOf('//')) {
+ // support network-path reference with empty base
root += '//';
}
@@ -5351,22 +5236,19 @@
}
entry = entry[container];
- // term is preferred for values using @reverse
if(mapping.reverse) {
+ // term is preferred for values using @reverse
_addPreferredTerm(mapping, term, entry['@type'], '@reverse');
- }
- // term is preferred for values using specific type
- else if('@type' in mapping) {
+ } else if('@type' in mapping) {
+ // term is preferred for values using specific type
_addPreferredTerm(mapping, term, entry['@type'], mapping['@type']);
- }
- // term is preferred for values using specific language
- else if('@language' in mapping) {
+ } else if('@language' in mapping) {
+ // term is preferred for values using specific language
var language = mapping['@language'] || '@null';
_addPreferredTerm(mapping, term, entry['@language'], language);
- }
- // term is preferred for values w/default language or no type and
- // no language
- else {
+ } else {
+ // term is preferred for values w/default language or no type and
+ // no language
// add an entry for the default language
_addPreferredTerm(mapping, term, entry['@language'], defaultLanguage);
@@ -5664,8 +5546,7 @@
if(_isObject(v)) {
if('@id' in v) {
rval = (v['@id'].indexOf('_:') === 0);
- }
- else {
+ } else {
rval = (Object.keys(v).length === 0 ||
!(('@value' in v) || ('@set' in v) || ('@list' in v)));
}
@@ -5699,8 +5580,7 @@
for(var i = 0; i < value.length; ++i) {
rval[i] = _clone(value[i]);
}
- }
- else {
+ } else {
rval = {};
for(var key in value) {
rval[key] = _clone(value[key]);
@@ -5729,8 +5609,7 @@
_findContextUrls(input[i], urls, replace, base);
}
return (count < Object.keys(urls).length);
- }
- else if(_isObject(input)) {
+ } else if(_isObject(input)) {
for(var key in input) {
if(key !== '@context') {
_findContextUrls(input[key], urls, replace, base);
@@ -5755,27 +5634,23 @@
Array.prototype.splice.apply(ctx, [i, 1].concat(_ctx));
i += _ctx.length;
length += _ctx.length;
- }
- else {
+ } else {
ctx[i] = _ctx;
}
- }
- // @context URL found
- else if(!(_ctx in urls)) {
+ } else if(!(_ctx in urls)) {
+ // @context URL found
urls[_ctx] = false;
}
}
}
- }
- // string @context
- else if(_isString(ctx)) {
+ } else if(_isString(ctx)) {
+ // string @context
ctx = _prependBase(base, ctx);
// replace w/@context if requested
if(replace) {
input[key] = urls[ctx];
- }
- // @context URL found
- else if(!(ctx in urls)) {
+ } else if(!(ctx in urls)) {
+ // @context URL found
urls[ctx] = false;
}
}
@@ -5868,8 +5743,7 @@
if(!err && _isString(ctx)) {
try {
ctx = JSON.parse(ctx);
- }
- catch(ex) {
+ } catch(ex) {
err = ex;
}
}
@@ -5885,8 +5759,7 @@
'provided for a remote context.',
'jsonld.InvalidUrl',
{code: 'loading remote context failed', url: url, cause: err});
- }
- else if(!_isObject(ctx)) {
+ } else if(!_isObject(ctx)) {
err = new JsonLdError(
'Dereferencing a URL did not result in a JSON object. The ' +
'response was valid JSON, but it was not a JSON object.',
@@ -5901,8 +5774,7 @@
// use empty context if no @context key is present
if(!('@context' in ctx)) {
ctx = {'@context': {}};
- }
- else {
+ } else {
ctx = {'@context': ctx['@context']};
}
@@ -6011,8 +5883,7 @@
// get subject
if(!_isUndefined(match[1])) {
triple.subject = {type: 'IRI', value: match[1]};
- }
- else {
+ } else {
triple.subject = {type: 'blank node', value: match[2]};
}
@@ -6022,20 +5893,16 @@
// get object
if(!_isUndefined(match[4])) {
triple.object = {type: 'IRI', value: match[4]};
- }
- else if(!_isUndefined(match[5])) {
+ } else if(!_isUndefined(match[5])) {
triple.object = {type: 'blank node', value: match[5]};
- }
- else {
+ } else {
triple.object = {type: 'literal'};
if(!_isUndefined(match[7])) {
triple.object.datatype = match[7];
- }
- else if(!_isUndefined(match[8])) {
+ } else if(!_isUndefined(match[8])) {
triple.object.datatype = RDF_LANGSTRING;
triple.object.language = match[8];
- }
- else {
+ } else {
triple.object.datatype = XSD_STRING;
}
var unescaped = match[6]
@@ -6051,17 +5918,15 @@
var name = '@default';
if(!_isUndefined(match[9])) {
name = match[9];
- }
- else if(!_isUndefined(match[10])) {
+ } else if(!_isUndefined(match[10])) {
name = match[10];
}
// initialize graph in dataset
if(!(name in dataset)) {
dataset[name] = [triple];
- }
- // add triple if unique to its graph
- else {
+ } else {
+ // add triple if unique to its graph
var unique = true;
var triples = dataset[name];
for(var ti = 0; unique && ti < triples.length; ++ti) {
@@ -6126,13 +5991,11 @@
// subject is an IRI
if(s.type === 'IRI') {
quad += '<' + s.value + '>';
- }
- // bnode normalization mode
- else if(bnode) {
+ } else if(bnode) {
+ // bnode normalization mode
quad += (s.value === bnode) ? '_:a' : '_:z';
- }
- // bnode normal mode
- else {
+ } else {
+ // bnode normal mode
quad += s.value;
}
quad += ' ';
@@ -6140,14 +6003,12 @@
// predicate is an IRI
if(p.type === 'IRI') {
quad += '<' + p.value + '>';
- }
- // FIXME: TBD what to do with bnode predicates during normalization
- // bnode normalization mode
- else if(bnode) {
+ } else if(bnode) {
+ // FIXME: TBD what to do with bnode predicates during normalization
+ // bnode normalization mode
quad += '_:p';
- }
- // bnode normal mode
- else {
+ } else {
+ // bnode normal mode
quad += p.value;
}
quad += ' ';
@@ -6155,18 +6016,15 @@
// object is IRI, bnode, or literal
if(o.type === 'IRI') {
quad += '<' + o.value + '>';
- }
- else if(o.type === 'blank node') {
+ } else if(o.type === 'blank node') {
// normalization mode
if(bnode) {
quad += (o.value === bnode) ? '_:a' : '_:z';
- }
- // normal mode
- else {
+ } else {
+ // normal mode
quad += o.value;
}
- }
- else {
+ } else {
var escaped = o.value
.replace(/\\/g, '\\\\')
.replace(/\t/g, '\\t')
@@ -6178,8 +6036,7 @@
if(o.language) {
quad += '@' + o.language;
}
- }
- else if(o.datatype !== XSD_STRING) {
+ } else if(o.datatype !== XSD_STRING) {
quad += '^^<' + o.datatype + '>';
}
}
@@ -6188,11 +6045,9 @@
if(g !== null) {
if(g.indexOf('_:') !== 0) {
quad += ' <' + g + '>';
- }
- else if(bnode) {
+ } else if(bnode) {
quad += ' _:g';
- }
- else {
+ } else {
quad += ' ' + g;
}
}
@@ -6237,16 +6092,14 @@
// add subject
if(subject.indexOf('_:') === 0) {
triple.subject = {type: 'blank node', value: subject};
- }
- else {
+ } else {
triple.subject = {type: 'IRI', value: subject};
}
// add predicate
if(predicate.indexOf('_:') === 0) {
triple.predicate = {type: 'blank node', value: predicate};
- }
- else {
+ } else {
triple.predicate = {type: 'IRI', value: predicate};
}
@@ -6262,8 +6115,7 @@
for(var x = 0; x < object.value.length; x++) {
if(object.value[x].nodeType === Node.ELEMENT_NODE) {
value += serializer.serializeToString(object.value[x]);
- }
- else if(object.value[x].nodeType === Node.TEXT_NODE) {
+ } else if(object.value[x].nodeType === Node.TEXT_NODE) {
value += object.value[x].nodeValue;
}
}
@@ -6276,24 +6128,20 @@
if(object.type === RDF_OBJECT) {
if(object.value.indexOf('_:') === 0) {
triple.object.type = 'blank node';
- }
- else {
+ } else {
triple.object.type = 'IRI';
}
- }
- // literal
- else {
+ } else {
+ // object is a literal
triple.object.type = 'literal';
if(object.type === RDF_PLAIN_LITERAL) {
if(object.language) {
triple.object.datatype = RDF_LANGSTRING;
triple.object.language = object.language;
- }
- else {
+ } else {
triple.object.datatype = XSD_STRING;
}
- }
- else {
+ } else {
triple.object.datatype = object.type;
}
}
@@ -6431,8 +6279,7 @@
// no more permutations
if(k === null) {
this.done = true;
- }
- else {
+ } else {
// swap k and the element it is looking at
var swap = this.left[k] ? pos - 1 : pos + 1;
this.list[pos] = this.list[swap];
@@ -6465,8 +6312,7 @@
}
};
};
-}
-else {
+} else {
sha1.create = function() {
return new sha1.MessageDigest();
};
@@ -6829,8 +6675,7 @@
parsed.pathname, parsed.authority !== '');
return parsed;
};
-}
-else {
+} else {
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
@@ -6882,13 +6727,11 @@
if(idx === -1) {
parsed.authority = parsed.pathname;
parsed.pathname = '';
- }
- else {
+ } else {
parsed.authority = parsed.pathname.substr(0, idx);
parsed.pathname = parsed.pathname.substr(idx);
}
- }
- else {
+ } else {
// construct authority
parsed.authority = parsed.host || '';
if(parsed.auth) {
@@ -6923,9 +6766,8 @@
if(hasAuthority ||
(output.length > 0 && output[output.length - 1] !== '..')) {
output.pop();
- }
- // leading relative URL '..'
- else {
+ } else {
+ // leading relative URL '..'
output.push('..');
}
continue;
@@ -6936,12 +6778,11 @@
return rval + output.join('/');
}
-// use node document loader by default
if(_nodejs) {
+ // use node document loader by default
jsonld.useDocumentLoader('node');
-}
-// use xhr document loader by default
-else if(typeof XMLHttpRequest !== 'undefined') {
+} else if(typeof XMLHttpRequest !== 'undefined') {
+ // use xhr document loader by default
jsonld.useDocumentLoader('xhr');
}
@@ -6975,22 +6816,19 @@
// the shared global jsonld API instance
wrapper(factory);
-// export nodejs API
if(_nodejs) {
+ // export nodejs API
module.exports = factory;
-}
-// export AMD API
-else if(typeof define === 'function' && define.amd) {
+} else if(typeof define === 'function' && define.amd) {
+ // export AMD API
define([], function() {
return factory;
});
-}
-// export simple browser API
-else if(_browser) {
+} else if(_browser) {
+ // export simple browser API
if(typeof jsonld === 'undefined') {
jsonld = jsonldjs = factory;
- }
- else {
+ } else {
jsonldjs = factory;
}
}