-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from rdfjs-base/esm
feat!: switched to esm, added factory for environment, code cleanup
- Loading branch information
Showing
27 changed files
with
459 additions
and
796 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import BlankNode from './lib/BlankNode.js' | ||
import DefaultGraph from './lib/DefaultGraph.js' | ||
import fromTerm from './lib/fromTerm.js' | ||
import Literal from './lib/Literal.js' | ||
import NamedNode from './lib/NamedNode.js' | ||
import Quad from './lib/Quad.js' | ||
import Variable from './lib/Variable.js' | ||
|
||
const langStringDatatype = new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString') | ||
const stringDatatype = new NamedNode('http://www.w3.org/2001/XMLSchema#string') | ||
|
||
class DataFactory { | ||
constructor () { | ||
this.init() | ||
} | ||
|
||
init () { | ||
this._data = { | ||
blankNodeCounter: 0, | ||
defaultGraph: new DefaultGraph() | ||
} | ||
} | ||
|
||
namedNode (value) { | ||
return new NamedNode(value) | ||
} | ||
|
||
blankNode (value) { | ||
value = value || ('b' + (++this._data.blankNodeCounter)) | ||
|
||
return new BlankNode(value) | ||
} | ||
|
||
literal (value, languageOrDatatype) { | ||
if (typeof languageOrDatatype === 'string') { | ||
return new Literal(value, languageOrDatatype, langStringDatatype) | ||
} else { | ||
return new Literal(value, '', languageOrDatatype || stringDatatype) | ||
} | ||
} | ||
|
||
variable (value) { | ||
return new Variable(value) | ||
} | ||
|
||
defaultGraph () { | ||
return this._data.defaultGraph | ||
} | ||
|
||
quad (subject, predicate, object, graph = this.defaultGraph()) { | ||
return new Quad(subject, predicate, object, graph) | ||
} | ||
|
||
fromTerm (original) { | ||
return fromTerm(this, original) | ||
} | ||
|
||
fromQuad (original) { | ||
return fromTerm(this, original) | ||
} | ||
} | ||
|
||
DataFactory.exports = [ | ||
'blankNode', | ||
'defaultGraph', | ||
'fromQuad', | ||
'fromTerm', | ||
'literal', | ||
'namedNode', | ||
'quad', | ||
'variable' | ||
] | ||
|
||
export default DataFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# @rdfjs/data-model | ||
|
||
[![Build Status](https://travis-ci.org/rdfjs/data-model.svg?branch=master)](https://travis-ci.org/rdfjs/data-model) | ||
[![Build Status](https://img.shields.io/github/workflow/status/rdfjs-base/data-model/CI)](https://github.com/rdfjs-base/data-model/actions/workflows/ci.yaml) | ||
|
||
[![npm version](https://img.shields.io/npm/v/@rdfjs/data-model.svg)](https://www.npmjs.com/package/@rdfjs/data-model) | ||
|
||
A basic implementation of the [RDFJS Data Model](http://rdf.js.org/). | ||
A basic implementation of the [RDF/JS Data Model](http://rdf.js.org/). | ||
See [the specification](http://rdf.js.org/) for further details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path') | ||
const Mocha = require('mocha') | ||
import { resolve } from 'path' | ||
import Mocha from 'mocha' | ||
|
||
const mocha = new Mocha() | ||
async function main () { | ||
const tests = new Mocha() | ||
|
||
global.rdf = require(path.resolve(process.argv[2] || '')) | ||
global.rdf = (await import(resolve(process.argv[2] || ''))).default | ||
|
||
mocha.addFile(path.join(__dirname, '../test/index.js')).run(failures => { | ||
process.on('exit', () => { | ||
process.exit(failures) | ||
tests.files.push((new URL('../test/index.js', import.meta.url)).pathname) | ||
await tests.loadFilesAsync() | ||
|
||
tests.run(failures => { | ||
process.on('exit', () => { | ||
process.exit(failures) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const DataFactory = require('./lib/DataFactory.js') | ||
import Factory from './Factory.js' | ||
|
||
module.exports = DataFactory | ||
const factory = new Factory() | ||
|
||
export default factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.