Comparing version 0.1.5 to 0.1.6
@@ -71,3 +71,7 @@ /** | ||
var P_RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; | ||
var P_RDF_NAMESPACE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; | ||
var H_IRI_RDF_NIL = { | ||
type: 'iri', | ||
iri: P_RDF_NAMESPACE + 'nil' | ||
}; | ||
@@ -629,12 +633,18 @@ var P_XSD_INTEGER = 'http://www.w3.org/2001/XMLSchema#integer'; | ||
// empty-args call | ||
if (0 === arguments.length) { | ||
// return collection as array | ||
return a_collection.map(f_collection_item); | ||
} | ||
// this is an implicit each call | ||
if ('function' === typeof f_each) { | ||
else if ('function' === typeof f_each) { | ||
// each item | ||
a_collection.map(f_collection_item).forEach(f_each); | ||
} | ||
// other | ||
else { | ||
local.fail('calling a collection is an implicit forEach on the underlying list; method requires a callback function, instead got: ' + (0, _arginfo2['default'])(f_each)); | ||
// each item | ||
a_collection.map(f_collection_item).forEach(f_each); | ||
} | ||
// other | ||
else { | ||
local.fail('calling a collection is an implicit forEach on the underlying list; method requires a callback function, instead got: ' + (0, _arginfo2['default'])(f_each)); | ||
} | ||
}); | ||
@@ -659,2 +669,13 @@ | ||
// namespace is rdf: ; emulate rdf collection | ||
if (P_RDF_NAMESPACE === p_namespace) { | ||
// emulate rdf:first | ||
k_collection.first = cover_networked_node(a_collection[0][0]); | ||
// emulate rdf:rest | ||
var a_rest = a_collection.slice(1); | ||
k_collection.rest = a_rest.length ? cover_collection(a_rest, p_namespace) : cover_iri(H_IRI_RDF_NIL, P_RDF_NAMESPACE); | ||
} | ||
// | ||
@@ -963,8 +984,8 @@ return k_collection; | ||
else if (Array.isArray()) { | ||
this.open('[ ', ',', true); | ||
add.open('[ ', ',', true); | ||
for (var i_item in z_thing) { | ||
add(''); | ||
stringify_thing.apply(this, [add, z_thing[i_item]]); | ||
stringify_thing(add, z_thing[i_item]); | ||
} | ||
this.close(']'); | ||
add.close(']'); | ||
} | ||
@@ -975,5 +996,5 @@ // something with enumerable properties | ||
if ('function' === s_type) { | ||
this.open('(function){', ',', true); | ||
add.open('(function){', ',', true); | ||
} else { | ||
this.open('{', ',', true); | ||
add.open('{', ',', true); | ||
} | ||
@@ -984,8 +1005,8 @@ var b_was_found = false; | ||
add('\'' + s_property.replace(/'/g, '\\\'') + '\': '); | ||
stringify_thing.apply(this, [add, z_thing[s_property]]); | ||
stringify_thing(add, z_thing[s_property]); | ||
} | ||
if (!b_was_found) { | ||
this.close('', ''); | ||
add.close('', ''); | ||
} else { | ||
this.close('}'); | ||
add.close('}'); | ||
} | ||
@@ -997,3 +1018,3 @@ } | ||
body: function body(add) { | ||
return stringify_thing.apply(this, [add, z_what]); | ||
return stringify_thing(add, z_what); | ||
} | ||
@@ -1000,0 +1021,0 @@ }).produce({ |
{ | ||
"name": "graphy", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Query linked-data graphs by abstracting away traditional JSON-LD interaction", | ||
@@ -42,5 +42,5 @@ "author": { | ||
"clone": "^1.0.2", | ||
"rapunzel": "0.0.5", | ||
"rapunzel": "^0.1.3", | ||
"rmprop": "^1.0.0" | ||
} | ||
} |
@@ -117,2 +117,32 @@ # graphy [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url] | ||
## RDF Collections | ||
In order to be consistent with the graph, rdf collection properties are emulated on collection objects. So instead of accessing a collection's elements via Array's properties/methods, you can also use the `rdf:first` and `rdf:rest` properties: | ||
```javascript | ||
let w_list = k_banana.stages.$('rdf:'); | ||
w_list.first.$('ns:').$id; // 'FindSpace' | ||
w_list = w_list.rest; | ||
w_list.first.$('plant:').$id; // 'Seed' | ||
w_list = w_list.rest; | ||
w_list.first.$('plant:').$id; // 'Grow' | ||
w_list = w_list.rest; | ||
w_list.first.$('plant:').$id; // 'Harvest' | ||
w_list = w_list.rest; | ||
w_list.$id; // 'nil' | ||
// ------------ or in a loop ------------ | ||
let a_stages = []; | ||
let w_list = k_banana.stages.$('rdf:'); | ||
while(w_list.$id !== 'nil') { | ||
a_stage.push(w_list.first.$('plant:').$id || w_list.first.$('ns:').$id); | ||
w_list = w_list.rest; | ||
} | ||
a_stages; // ['FindSpace', 'Seed', 'Grow', 'Harvest'] | ||
``` | ||
## License | ||
@@ -119,0 +149,0 @@ |
31812
837
160
+ Addedclasser@1.3.0(transitive)
+ Addedrapunzel@0.1.13(transitive)
- Removedrapunzel@0.0.5(transitive)
Updatedrapunzel@^0.1.3