Skip to content

Commit

Permalink
Merge pull request #37 from rdfjs-base/esm
Browse files Browse the repository at this point in the history
feat!: switched to esm, added factory for environment, code cleanup
  • Loading branch information
bergos authored Dec 29, 2021
2 parents b8be2d9 + bf8268b commit 67447e0
Show file tree
Hide file tree
Showing 27 changed files with 459 additions and 796 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

74 changes: 74 additions & 0 deletions Factory.js
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
4 changes: 2 additions & 2 deletions README.md
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.
23 changes: 15 additions & 8 deletions bin/test.js
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()
233 changes: 0 additions & 233 deletions dist/rdf-data-model.js

This file was deleted.

12 changes: 0 additions & 12 deletions index.d.ts

This file was deleted.

6 changes: 4 additions & 2 deletions index.js
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
6 changes: 2 additions & 4 deletions lib/BlankNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class BlankNode {
constructor (id) {
this.value = id || ('b' + (++BlankNode.nextId))
this.value = id
}

equals (other) {
Expand All @@ -10,6 +10,4 @@ class BlankNode {

BlankNode.prototype.termType = 'BlankNode'

BlankNode.nextId = 0

module.exports = BlankNode
export default BlankNode
Loading

0 comments on commit 67447e0

Please # to comment.