@tpluscode/rdf-string
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.11](https://github.com/tpluscode/rdf-string/compare/v0.2.10...v0.2.11) (2020-04-18) | ||
### Bug Fixes | ||
* properly escape multiple literals and sepcial chars ([eb420cc](https://github.com/tpluscode/rdf-string/commit/eb420cc3869861844a49b0518589feb9f884c48b)) | ||
### [0.2.10](https://github.com/tpluscode/rdf-string/compare/v0.2.9...v0.2.10) (2020-04-08) | ||
@@ -7,0 +14,0 @@ |
import { BlankNode, Literal, NamedNode } from 'rdf-js'; | ||
export declare function blankNode(term: BlankNode): string; | ||
export declare function namedNode(term: NamedNode): string; | ||
export declare function literalValue(term: Literal): string; | ||
export declare function literal(term: Literal): string; | ||
//# sourceMappingURL=ntriples.d.ts.map |
import xsd from './xsd'; | ||
const echarRegEx = new RegExp('["\\\\\n\r]'); // eslint-disable-line no-control-regex | ||
const echarRegExAll = new RegExp('["\\\\\n\r]', 'g'); // eslint-disable-line no-control-regex | ||
const echarReplacement = { | ||
'"': '\\"', | ||
'\\': '\\\\', | ||
'\n': '\\n', | ||
'\r': '\\r', | ||
}; | ||
function echarReplacer(char) { | ||
return echarReplacement[char]; | ||
} | ||
function escapeValue(value) { | ||
if (echarRegEx.test(value)) { | ||
return value.replace(echarRegExAll, echarReplacer); | ||
} | ||
return value; | ||
} | ||
export function blankNode(term) { | ||
@@ -8,4 +25,7 @@ return `_:${term.value}`; | ||
} | ||
export function literalValue(term) { | ||
return `"${escapeValue(term.value)}"`; | ||
} | ||
export function literal(term) { | ||
const value = `"${term.value}"`; | ||
const value = literalValue(term); | ||
if (term.language) { | ||
@@ -12,0 +32,0 @@ return `${value}@${term.language}`; |
@@ -38,3 +38,3 @@ import { shrink } from '@zazuko/rdf-vocabularies'; | ||
return { | ||
value: `"${term.value}"^^${datatypeResult.value}`, | ||
value: `${ntriples.literalValue(term)}^^${datatypeResult.value}`, | ||
prefixes: datatypeResult.prefixes, | ||
@@ -41,0 +41,0 @@ }; |
{ | ||
"name": "@tpluscode/rdf-string", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"description": "Simplifies creating of RDF strings using ECMAscript templates", | ||
@@ -5,0 +5,0 @@ "main": "main.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
43295
635