@tpluscode/rdf-string
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [0.2.0](https://github.com/zazuko/rdf-string/compare/v0.1.0...v0.2.0) (2020-02-24) | ||
### ⚠ BREAKING CHANGES | ||
* renamed parameter of SparqlOptions | ||
### Bug Fixes | ||
* base was not applied to nested templates ([7b443e4](https://github.com/zazuko/rdf-string/commit/7b443e48a1cbdd1ab1f03105486fe6e4156409ee)) | ||
## [0.1.0](https://github.com/zazuko/rdf-string/compare/v0.0.8...v0.1.0) (2020-02-24) | ||
@@ -7,0 +18,0 @@ |
@@ -5,4 +5,3 @@ import { prefixes as knownPrefixes, shrink } from '@zazuko/rdf-vocabularies'; | ||
.filter(prefix => prefix in knownPrefixes) | ||
.map(prefix => `PREFIX ${prefix}: <${knownPrefixes[prefix]}>`) | ||
.join('\n'); | ||
.map(prefix => `PREFIX ${prefix}: <${knownPrefixes[prefix]}>`); | ||
} | ||
@@ -16,3 +15,3 @@ export class SparqlTemplateResult { | ||
toString(options = {}) { | ||
const prefixes = options.prefixes || typeof options.prefixes === 'undefined'; | ||
const prologue = options.prologue || typeof options.prologue === 'undefined'; | ||
const baseRegex = new RegExp('^' + options.base); | ||
@@ -32,3 +31,3 @@ const l = this.strings.length - 1; | ||
else if (value instanceof SparqlTemplateResult) { | ||
valueStr = value.toString({ prefixes: false }); | ||
valueStr = value.toString({ ...options, prologue: false }); | ||
value.prefixes.forEach(prefix => this.prefixes.add(prefix)); | ||
@@ -63,13 +62,13 @@ } | ||
query += this.strings[l]; | ||
let baseStatement = ''; | ||
if (options.base) { | ||
baseStatement = `BASE <${options.base}>\n\n`; | ||
let prologueLines = []; | ||
if (prologue) { | ||
prologueLines = prefixDeclarations(this.prefixes); | ||
if (options.base) { | ||
prologueLines = [`BASE <${options.base}>`, ...prologueLines]; | ||
} | ||
prologueLines.push('\n'); | ||
} | ||
let prefixStatements = ''; | ||
if (prefixes && this.prefixes.size > 0) { | ||
prefixStatements = `${prefixDeclarations(this.prefixes)}\n\n`; | ||
} | ||
return `${baseStatement}${prefixStatements}${query}`; | ||
return `${prologueLines.join('\n')}${query}`; | ||
} | ||
} | ||
export const sparql = (strings, ...values) => new SparqlTemplateResult(strings, values); |
@@ -7,4 +7,3 @@ "use strict"; | ||
.filter(prefix => prefix in rdf_vocabularies_1.prefixes) | ||
.map(prefix => `PREFIX ${prefix}: <${rdf_vocabularies_1.prefixes[prefix]}>`) | ||
.join('\n'); | ||
.map(prefix => `PREFIX ${prefix}: <${rdf_vocabularies_1.prefixes[prefix]}>`); | ||
} | ||
@@ -18,3 +17,3 @@ class SparqlTemplateResult { | ||
toString(options = {}) { | ||
const prefixes = options.prefixes || typeof options.prefixes === 'undefined'; | ||
const prologue = options.prologue || typeof options.prologue === 'undefined'; | ||
const baseRegex = new RegExp('^' + options.base); | ||
@@ -34,3 +33,3 @@ const l = this.strings.length - 1; | ||
else if (value instanceof SparqlTemplateResult) { | ||
valueStr = value.toString({ prefixes: false }); | ||
valueStr = value.toString(Object.assign(Object.assign({}, options), { prologue: false })); | ||
value.prefixes.forEach(prefix => this.prefixes.add(prefix)); | ||
@@ -65,11 +64,11 @@ } | ||
query += this.strings[l]; | ||
let baseStatement = ''; | ||
if (options.base) { | ||
baseStatement = `BASE <${options.base}>\n\n`; | ||
let prologueLines = []; | ||
if (prologue) { | ||
prologueLines = prefixDeclarations(this.prefixes); | ||
if (options.base) { | ||
prologueLines = [`BASE <${options.base}>`, ...prologueLines]; | ||
} | ||
prologueLines.push('\n'); | ||
} | ||
let prefixStatements = ''; | ||
if (prefixes && this.prefixes.size > 0) { | ||
prefixStatements = `${prefixDeclarations(this.prefixes)}\n\n`; | ||
} | ||
return `${baseStatement}${prefixStatements}${query}`; | ||
return `${prologueLines.join('\n')}${query}`; | ||
} | ||
@@ -76,0 +75,0 @@ } |
@@ -6,3 +6,3 @@ import { Term } from 'rdf-js'; | ||
base?: string; | ||
prefixes?: boolean; | ||
prologue?: boolean; | ||
} | ||
@@ -9,0 +9,0 @@ export declare class SparqlTemplateResult { |
{ | ||
"name": "@tpluscode/rdf-string", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simplifies creating of RDF strings using ECMAscript templates", | ||
@@ -5,0 +5,0 @@ "main": "dist/node/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14343
170