clownface
Version:
Simple but powerful graph traversing library
614 lines (526 loc) • 19.9 kB
Markdown
## Members
<dl>
<dt><a href="#term">term</a> ⇒ <code>undefined</code> | <code>Term</code></dt>
<dd><p>Gets the current RDF/JS term or undefined if pointer has no context</p>
</dd>
<dt><a href="#terms">terms</a> ⇒ <code>Array.<Term></code></dt>
<dd><p>Gets the current terms or an empty array if the pointer has no context</p>
</dd>
<dt><a href="#value">value</a> ⇒ <code>undefined</code> | <code>string</code></dt>
<dd><p>Gets the string representation of term</p>
</dd>
<dt><a href="#values">values</a> ⇒ <code>Array.<string></code></dt>
<dd><p>Gets the string representation of terms</p>
</dd>
<dt><a href="#dataset">dataset</a> ⇒ <code>undefined</code> | <code>DatasetCore</code></dt>
<dd><p>Gets the current context's dataset, or undefined if there are multiple</p>
</dd>
<dt><a href="#datasets">datasets</a> ⇒ <code>Array.<DatasetCore></code></dt>
<dd><p>Gets the current context's datasets</p>
</dd>
</dl>
## Functions
<dl>
<dt><a href="#any">any()</a> ⇒ <code>Clownface</code></dt>
<dd><p>Removes current pointers from the context and return an "any pointer".
The returned object can be used to find any nodes in the dataset</p>
</dd>
<dt><a href="#isList">isList()</a> ⇒ <code>boolean</code></dt>
<dd><p>Returns true if the current term is a rdf:List</p>
</dd>
<dt><a href="#list">list()</a> ⇒ <code>Iterable</code> | <code>null</code></dt>
<dd><p>Creates an iterator which iterates and rdf:List of the current term</p>
</dd>
<dt><a href="#toArray">toArray()</a> ⇒ <code>Array.<Clownface></code></dt>
<dd><p>Returns an array of graph pointers where each one has a single _context</p>
</dd>
<dt><a href="#filter">filter(callback)</a> ⇒ <code>Clownface</code></dt>
<dd><p>Returns graph pointers which meet the condition specified in a callback function</p>
</dd>
<dt><a href="#forEach">forEach(callback)</a> ⇒ <code>Clownface</code></dt>
<dd><p>Performs the specified action on every graph pointer</p>
</dd>
<dt><a href="#map">map(callback)</a> ⇒ <code>Array.<T></code></dt>
<dd><p>Calls a defined callback function on each graph pointer, and returns an array that contains the results.</p>
</dd>
<dt><a href="#node">node(values, [options])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates graph pointer to one or more node(s)</p>
<p>Depending on the value creates pointers to:</p>
<ul>
<li>blank node context for null <code>values</code></li>
<li>literal for string <code>values</code> and no <code>options</code> paramter</li>
<li>matching RDF/JS term</li>
<li>term created according to <code>options.type</code> parameter</li>
</ul>
</dd>
<dt><a href="#blankNode">blankNode([values])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates graph pointer to one or more blank nodes</p>
</dd>
<dt><a href="#literal">literal(values, [languageOrDatatype])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates graph pointer to one or more literal nodes</p>
</dd>
<dt><a href="#namedNode">namedNode(values)</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates graph pointer to one or more named nodes</p>
</dd>
<dt><a href="#in">in([predicates])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a graph pointer to nodes which are linked to the current pointer by <code>predicates</code></p>
</dd>
<dt><a href="#out">out([predicates], [options])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a graph pointer to the result nodes after following a predicate, or after
following any predicates in an array, starting from the subject(s) (current graph pointer) to the objects.</p>
</dd>
<dt><a href="#has">has(predicates, [objects])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a graph pointer to nodes which are subjects of predicates, optionally also with specific objects</p>
<p>If the current context is empty, will check all potential subjects</p>
</dd>
<dt><a href="#addIn">addIn(predicates, subjects, [callback])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a new quad(s) in the dataset where the current context is the object</p>
</dd>
<dt><a href="#addOut">addOut(predicates, objects, [callback])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a new quad(s) in the dataset where the current context is the subject</p>
</dd>
<dt><a href="#addList">addList(predicates, items)</a> ⇒ <code>Clownface</code></dt>
<dd><p>Creates a new RDF list or lists containing the given items</p>
</dd>
<dt><a href="#deleteIn">deleteIn([predicates], [subjects])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Deletes all quads where the current graph pointer contexts are the objects</p>
</dd>
<dt><a href="#deleteOut">deleteOut([predicates], [objects])</a> ⇒ <code>Clownface</code></dt>
<dd><p>Deletes all quads where the current graph pointer contexts are the subjects</p>
</dd>
<dt><a href="#deleteList">deleteList(predicates)</a> ⇒ <code>Clownface</code></dt>
<dd><p>Deletes entire RDF lists where the current graph pointer is the subject</p>
</dd>
<dt><a href="#filterTaggedLiterals">filterTaggedLiterals(terms, [options])</a> ⇒ <code>Array.<Term></code></dt>
<dd></dd>
</dl>
## Typedefs
<dl>
<dt><a href="#GraphPointerCallback">GraphPointerCallback</a> : <code>function</code></dt>
<dd></dd>
<dt><a href="#FilterCallback">FilterCallback</a> ⇒ <code>boolean</code></dt>
<dd></dd>
<dt><a href="#ForEachCallback">ForEachCallback</a> : <code>function</code></dt>
<dd></dd>
<dt><a href="#MapCallback">MapCallback</a> ⇒ <code>T</code></dt>
<dd></dd>
</dl>
<a name="term"></a>
## term ⇒ <code>undefined</code> \| <code>Term</code>
Gets the current RDF/JS term or undefined if pointer has no context
**Kind**: global variable
<a name="terms"></a>
## terms ⇒ <code>Array.<Term></code>
Gets the current terms or an empty array if the pointer has no context
**Kind**: global variable
<a name="value"></a>
## value ⇒ <code>undefined</code> \| <code>string</code>
Gets the string representation of term
**Kind**: global variable
<a name="values"></a>
## values ⇒ <code>Array.<string></code>
Gets the string representation of terms
**Kind**: global variable
<a name="dataset"></a>
## dataset ⇒ <code>undefined</code> \| <code>DatasetCore</code>
Gets the current context's dataset, or undefined if there are multiple
**Kind**: global variable
<a name="datasets"></a>
## datasets ⇒ <code>Array.<DatasetCore></code>
Gets the current context's datasets
**Kind**: global variable
<a name="any"></a>
## any() ⇒ <code>Clownface</code>
Removes current pointers from the context and return an "any pointer".
The returned object can be used to find any nodes in the dataset
**Kind**: global function
<a name="isList"></a>
## isList() ⇒ <code>boolean</code>
Returns true if the current term is a rdf:List
**Kind**: global function
<a name="list"></a>
## list() ⇒ <code>Iterable</code> \| <code>null</code>
Creates an iterator which iterates and rdf:List of the current term
**Kind**: global function
<a name="toArray"></a>
## toArray() ⇒ <code>Array.<Clownface></code>
Returns an array of graph pointers where each one has a single _context
**Kind**: global function
<a name="filter"></a>
## filter(callback) ⇒ <code>Clownface</code>
Returns graph pointers which meet the condition specified in a callback function
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td><td><code><a href="#FilterCallback">FilterCallback</a></code></td>
</tr> </tbody>
</table>
<a name="forEach"></a>
## forEach(callback) ⇒ <code>Clownface</code>
Performs the specified action on every graph pointer
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td><td><code><a href="#ForEachCallback">ForEachCallback</a></code></td>
</tr> </tbody>
</table>
<a name="map"></a>
## map(callback) ⇒ <code>Array.<T></code>
Calls a defined callback function on each graph pointer, and returns an array that contains the results.
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td><td><code>MapCallback.<T></code></td>
</tr> </tbody>
</table>
<a name="node"></a>
## node(values, [options]) ⇒ <code>Clownface</code>
Creates graph pointer to one or more node(s)
Depending on the value creates pointers to:
- blank node context for null `values`
- literal for string `values` and no `options` paramter
- matching RDF/JS term
- term created according to `options.type` parameter
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>values</td><td><code>null</code> | <code>string</code> | <code>Array.<string></code> | <code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td></td>
</tr><tr>
<td>[options]</td><td><code>Object</code></td><td></td>
</tr><tr>
<td>[options.type]</td><td><code>"NamedNode"</code> | <code>"BlankNode"</code> | <code>"Literal"</code></td><td><p>explicit type for nodes</p>
</td>
</tr><tr>
<td>[options.language]</td><td><code>string</code></td><td><p>language tag of literals</p>
</td>
</tr><tr>
<td>[options.datatype]</td><td><code>string</code></td><td><p>datatype of literals</p>
</td>
</tr> </tbody>
</table>
<a name="blankNode"></a>
## blankNode([values]) ⇒ <code>Clownface</code>
Creates graph pointer to one or more blank nodes
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>[values]</td><td><code>null</code> | <code>string</code> | <code>Array.<string></code> | <code>BlankNode</code> | <code>Array.<BlankNode></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>blank node identifiers (generates it when falsy) or existing RDF/JS blank node(s)</p>
</td>
</tr> </tbody>
</table>
<a name="literal"></a>
## literal(values, [languageOrDatatype]) ⇒ <code>Clownface</code>
Creates graph pointer to one or more literal nodes
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>values</td><td><code>string</code> | <code>Array.<string></code> | <code>boolean</code> | <code>Array.<boolean></code> | <code>number</code> | <code>Array.<number></code> | <code>Literal</code> | <code>Array.<Literal></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>literal values as JS objects or RDF/JS Literal(s)</p>
</td>
</tr><tr>
<td>[languageOrDatatype]</td><td><code>string</code> | <code>Term</code></td><td><p>a language tag string or datatype term</p>
</td>
</tr> </tbody>
</table>
<a name="namedNode"></a>
## namedNode(values) ⇒ <code>Clownface</code>
Creates graph pointer to one or more named nodes
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>values</td><td><code>string</code> | <code>Array.<string></code> | <code>NamedNode</code> | <code>Array.<NamedNode></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>URI(s) or RDF/JS NamedNode(s)</p>
</td>
</tr> </tbody>
</table>
<a name="in"></a>
## in([predicates]) ⇒ <code>Clownface</code>
Creates a graph pointer to nodes which are linked to the current pointer by `predicates`
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>[predicates]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>one or more RDF/JS term identifying a property</p>
</td>
</tr> </tbody>
</table>
<a name="out"></a>
## out([predicates], [options]) ⇒ <code>Clownface</code>
Creates a graph pointer to the result nodes after following a predicate, or after
following any predicates in an array, starting from the subject(s) (current graph pointer) to the objects.
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>[predicates]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>any predicates to follow</p>
</td>
</tr><tr>
<td>[options]</td><td><code>object</code></td><td></td>
</tr><tr>
<td>[options.language]</td><td><code>string</code> | <code>Array.<string></code> | <code>undefined</code></td><td></td>
</tr> </tbody>
</table>
<a name="has"></a>
## has(predicates, [objects]) ⇒ <code>Clownface</code>
Creates a graph pointer to nodes which are subjects of predicates, optionally also with specific objects
If the current context is empty, will check all potential subjects
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>predicates</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>RDF property identifiers</p>
</td>
</tr><tr>
<td>[objects]</td><td><code>*</code></td><td><p>object values to match</p>
</td>
</tr> </tbody>
</table>
<a name="addIn"></a>
## addIn(predicates, subjects, [callback]) ⇒ <code>Clownface</code>
Creates a new quad(s) in the dataset where the current context is the object
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>predicates</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td></td>
</tr><tr>
<td>subjects</td><td><code>NamedNode</code> | <code>Array.<NamedNode></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td><p>one or more nodes to use as subjects</p>
</td>
</tr><tr>
<td>[callback]</td><td><code><a href="#GraphPointerCallback">GraphPointerCallback</a></code></td><td><p>called for each object, with subject pointer as parameter</p>
</td>
</tr> </tbody>
</table>
<a name="addOut"></a>
## addOut(predicates, objects, [callback]) ⇒ <code>Clownface</code>
Creates a new quad(s) in the dataset where the current context is the subject
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>predicates</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td></td>
</tr><tr>
<td>objects</td><td><code>*</code></td><td><p>one or more values to use for objects</p>
</td>
</tr><tr>
<td>[callback]</td><td><code><a href="#GraphPointerCallback">GraphPointerCallback</a></code></td><td><p>called for each subject, with object pointer as parameter</p>
</td>
</tr> </tbody>
</table>
<a name="addList"></a>
## addList(predicates, items) ⇒ <code>Clownface</code>
Creates a new RDF list or lists containing the given items
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>predicates</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td><td></td>
</tr><tr>
<td>items</td><td><code>*</code></td><td><p>one or more values to use for subjects</p>
</td>
</tr> </tbody>
</table>
<a name="deleteIn"></a>
## deleteIn([predicates], [subjects]) ⇒ <code>Clownface</code>
Deletes all quads where the current graph pointer contexts are the objects
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>[predicates]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td>
</tr><tr>
<td>[subjects]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td>
</tr> </tbody>
</table>
<a name="deleteOut"></a>
## deleteOut([predicates], [objects]) ⇒ <code>Clownface</code>
Deletes all quads where the current graph pointer contexts are the subjects
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>[predicates]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td>
</tr><tr>
<td>[objects]</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td>
</tr> </tbody>
</table>
<a name="deleteList"></a>
## deleteList(predicates) ⇒ <code>Clownface</code>
Deletes entire RDF lists where the current graph pointer is the subject
**Kind**: global function
**Returns**: <code>Clownface</code> - current graph pointer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>predicates</td><td><code>Term</code> | <code>Array.<Term></code> | <code>Clownface</code> | <code>Array.<Clownface></code></td>
</tr> </tbody>
</table>
<a name="filterTaggedLiterals"></a>
## filterTaggedLiterals(terms, [options]) ⇒ <code>Array.<Term></code>
**Kind**: global function
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>terms</td><td><code>Array.<Term></code></td>
</tr><tr>
<td>[options]</td><td><code>object</code></td>
</tr><tr>
<td>[options.language]</td><td><code>string</code> | <code>Array.<string></code></td>
</tr> </tbody>
</table>
<a name="GraphPointerCallback"></a>
## GraphPointerCallback : <code>function</code>
**Kind**: global typedef
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>pointer</td><td><code>Clownface</code></td><td><p>graph pointer to the new or existing node</p>
</td>
</tr> </tbody>
</table>
<a name="FilterCallback"></a>
## FilterCallback ⇒ <code>boolean</code>
**Kind**: global typedef
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>pointer</td><td><code>Clownface</code></td>
</tr><tr>
<td>index</td><td><code>number</code></td>
</tr><tr>
<td>pointers</td><td><code>Array.<Clownface></code></td>
</tr> </tbody>
</table>
<a name="ForEachCallback"></a>
## ForEachCallback : <code>function</code>
**Kind**: global typedef
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>pointer</td><td><code>Clownface</code></td>
</tr> </tbody>
</table>
<a name="MapCallback"></a>
## MapCallback ⇒ <code>T</code>
**Kind**: global typedef
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>pointer</td><td><code>Clownface</code></td>
</tr> </tbody>
</table>