Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for xsd:float as native type #462

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
XSD,
XSD_BOOLEAN: XSD + 'boolean',
XSD_DOUBLE: XSD + 'double',
XSD_FLOAT: XSD + 'float',
XSD_INTEGER: XSD + 'integer',
XSD_STRING: XSD + 'string',
};
5 changes: 4 additions & 1 deletion lib/fromRdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
// XSD,
XSD_BOOLEAN,
XSD_DOUBLE,
XSD_FLOAT,
XSD_INTEGER,
XSD_STRING,
} = require('./constants');
Expand Down Expand Up @@ -320,11 +321,13 @@ function _RDFToObject(o, useNativeTypes, rdfDirection) {
if(i.toFixed(0) === rval['@value']) {
rval['@value'] = i;
}
} else if(type === XSD_DOUBLE) {
} else if(type === XSD_DOUBLE || type === XSD_FLOAT) {
rval['@value'] = parseFloat(rval['@value']);
}
}
// do not add native type
// Remark: xsd:float are parsed into native type (above), but yet the type is explicitly added
// so as to keep the type information and not conflate xsd:float with xsd:double
if(![XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING].includes(type)) {
rval['@type'] = type;
}
Expand Down