Hi, Florent:

To inspect the type of a returned object, you can call toString on the 
prototype, as in:

    Object.prototype.toString.call(xdmp.filesystemFile('/path/to/some.js'));

which yields:

    [object xs.string]

So, an xs.string and not a JavaScript String or string literal, which you can 
convert with valueOf():

    
Object.prototype.toString.call(xdmp.filesystemFile('/path/to/some.js').valueOf());

which yields:

    [object String]


Hoping that helps,


Erik Hennum


________________________________________
From: [email protected] 
[[email protected]] on behalf of Florent Georges 
[[email protected]]
Sent: Saturday, March 26, 2016 3:51 AM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Return of xdmp.filesystemFile() not a  proper 
string object?

Hi,

The documentation for xdmp.filesystemFile() (that is the JavaScript
version of it, at https://docs.marklogic.com/xdmp.filesystemFile) says
it returns a `String` object.  But it seems to be of a different type.

I use the NPM package `yamljs`, so you can reproduce it, but I think
the example shows clearly the difference without requiring knowledge
of the package.  Given you have a file tmp.yaml (e.g. with the content
"---\n  foo: bar") then the following code (with an absolute path for
the YAML file):

var yaml = require('./node_modules/yamljs/lib/Yaml.js');
var src  = xdmp.filesystemFile('.../tmp.yaml');
yaml.parse(src);

gives the following error:

JS-JAVASCRIPT: if (value.indexOf("\r") !== -1) { -- Error running
JavaScript request: TypeError: undefined is not a function

I assume that `value`, somewhere in the package code, comes from the
parameter to yaml.parse() and is supposed to be a String object,
containing a function `indexOf`.  Indeed, if I explicitly create a
String object on the return value of `xdmp.filesystemFile()`, then it
succeeds:

var yaml = require('./node_modules/yamljs/lib/Yaml.js');
var src  = xdmp.filesystemFile('.../tmp.yaml');
yaml.parse(new String(src));

The only conclusion I can reach is that the return value of
`xdmp.filesystemFile()` is not a proper String object.  Did I miss
anything?

Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to