diff --git a/lib/handler/TypeHandlerBoolean.ts b/lib/handler/TypeHandlerBoolean.ts index 82c5c36..a7f51ea 100644 --- a/lib/handler/TypeHandlerBoolean.ts +++ b/lib/handler/TypeHandlerBoolean.ts @@ -27,8 +27,8 @@ export class TypeHandlerBoolean implements ITypeHandler { } public toRdf(value: any, { datatype, dataFactory }: IToRdfOptions): RDF.Literal { - return dataFactory.literal(value ? 'true' : 'false', - datatype || dataFactory.namedNode(TypeHandlerBoolean.TYPE)); + return dataFactory!.literal(value ? 'true' : 'false', + datatype || dataFactory!.namedNode(TypeHandlerBoolean.TYPE)); } } diff --git a/lib/handler/TypeHandlerDate.ts b/lib/handler/TypeHandlerDate.ts index 23f2e66..2744201 100644 --- a/lib/handler/TypeHandlerDate.ts +++ b/lib/handler/TypeHandlerDate.ts @@ -45,11 +45,11 @@ export class TypeHandlerDate implements ITypeHandler { } public toRdf(value: any, { datatype, dataFactory }: IToRdfOptions): RDF.Literal { - datatype = datatype || dataFactory.namedNode(TypeHandlerDate.TYPES[0]); + datatype = datatype || dataFactory!.namedNode(TypeHandlerDate.TYPES[0]); // Assume date values if (!(value instanceof Date)) { - return null; + return null!; // TODO: throw error in next breaking change } const date: Date = value; @@ -73,7 +73,7 @@ export class TypeHandlerDate implements ITypeHandler { default: valueString = date.toISOString(); } - return dataFactory.literal(valueString, datatype); + return dataFactory!.literal(valueString, datatype); } } diff --git a/lib/handler/TypeHandlerNumberDouble.ts b/lib/handler/TypeHandlerNumberDouble.ts index dd95003..d0e6c31 100644 --- a/lib/handler/TypeHandlerNumberDouble.ts +++ b/lib/handler/TypeHandlerNumberDouble.ts @@ -25,17 +25,17 @@ export class TypeHandlerNumberDouble implements ITypeHandler { } public toRdf(value: any, { datatype, dataFactory }: IToRdfOptions): RDF.Literal { - datatype = datatype || dataFactory.namedNode(TypeHandlerNumberDouble.TYPES[0]); + datatype = datatype || dataFactory!.namedNode(TypeHandlerNumberDouble.TYPES[0]); if (isNaN(value)) { - return dataFactory.literal('NaN', datatype); + return dataFactory!.literal('NaN', datatype); } if (!isFinite(value)) { - return dataFactory.literal(value > 0 ? 'INF' : '-INF', datatype); + return dataFactory!.literal(value > 0 ? 'INF' : '-INF', datatype); } if (value % 1 === 0) { - return null; + return null!; // TODO: throw error in next breaking change } - return dataFactory.literal(value.toExponential(15).replace(/(\d)0*e\+?/, '$1E'), datatype); + return dataFactory!.literal(value.toExponential(15).replace(/(\d)0*e\+?/, '$1E'), datatype); } } diff --git a/lib/handler/TypeHandlerNumberInteger.ts b/lib/handler/TypeHandlerNumberInteger.ts index daa9ae9..0ab82f5 100644 --- a/lib/handler/TypeHandlerNumberInteger.ts +++ b/lib/handler/TypeHandlerNumberInteger.ts @@ -37,10 +37,10 @@ export class TypeHandlerNumberInteger implements ITypeHandler { } public toRdf(value: any, { datatype, dataFactory }: IToRdfOptions): RDF.Literal { - return dataFactory.literal(String(value), datatype + return dataFactory!.literal(String(value), datatype || (value <= TypeHandlerNumberInteger.MAX_INT && value >= TypeHandlerNumberInteger.MIN_INT - ? dataFactory.namedNode(TypeHandlerNumberInteger.TYPES[0]) - : dataFactory.namedNode(TypeHandlerNumberInteger.TYPES[1]))); + ? dataFactory!.namedNode(TypeHandlerNumberInteger.TYPES[0]) + : dataFactory!.namedNode(TypeHandlerNumberInteger.TYPES[1]))); } } diff --git a/lib/handler/TypeHandlerString.ts b/lib/handler/TypeHandlerString.ts index e401bc4..f541d13 100644 --- a/lib/handler/TypeHandlerString.ts +++ b/lib/handler/TypeHandlerString.ts @@ -18,6 +18,7 @@ export class TypeHandlerString implements ITypeHandler { 'http://www.w3.org/2001/XMLSchema#token', 'http://www.w3.org/2001/XMLSchema#hexBinary', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString', 'http://www.w3.org/2001/XMLSchema#time', 'http://www.w3.org/2001/XMLSchema#duration', @@ -28,7 +29,7 @@ export class TypeHandlerString implements ITypeHandler { } public toRdf(value: any, { datatype, dataFactory }: IToRdfOptions): RDF.Literal { - return dataFactory.literal(value, datatype); + return dataFactory!.literal(value, datatype); } } diff --git a/test/index-test.ts b/test/index-test.ts index 0cc4506..610d9b6 100644 --- a/test/index-test.ts +++ b/test/index-test.ts @@ -17,6 +17,11 @@ describe('fromRdf', () => { .toEqual('abc'); }); + it('should handle language tagged strings with direction', () => { + return expect(fromRdf(DF.literal('abc', { language: 'en-us', direction: 'ltr' }))) + .toEqual('abc'); + }); + it('should handle normalized strings', () => { return expect(fromRdf(DF.literal('abc', DF.namedNode('http://www.w3.org/2001/XMLSchema#normalizedString')))) @@ -655,6 +660,7 @@ describe('getSupportedRdfDatatypes', () => { DF.namedNode('http://www.w3.org/2001/XMLSchema#token'), DF.namedNode('http://www.w3.org/2001/XMLSchema#hexBinary'), DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString'), + DF.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString'), DF.namedNode('http://www.w3.org/2001/XMLSchema#time'), DF.namedNode('http://www.w3.org/2001/XMLSchema#duration'), diff --git a/tsconfig.json b/tsconfig.json index ec158fd..93e1d47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "sourceMap": true, "inlineSources": true, "declaration": true, - "importHelpers": false + "importHelpers": false, + "strict": true }, "include": [ "index.ts",