fetcher.js
Functions
- fetchUrl(url, options) ⇒
Promise.<string>
This function tries to fetch a given URL using the fetch API. It either returns a Promise for the response text or throws an error,if the url can't be fetched.
- fetchMeta(identifier) ⇒
Promise.<Document>
This function fetches a meta XML file using a given Trismegistos identifier.It constructs a URL from the identifier and fetches the URL with
fetchUrl
.The file is parsed usingDomParser
and returned in XML format.If the identifier is not valid, it will throw an error.- fetchDdb(ddbHybrid) ⇒
Promise.<Document>
This function fetches a meta XML file using a given hybrid identifier.It constructs a URL from the identifier and fetches the URL with
fetchUrl
.The file is parsed usingDomParser
and returned in XML format.- isInteger(str) ⇒
boolean
This function tests if a given string is an integer or not and returnsa boolean value.
fetchUrl(url, options) ⇒ Promise.<string>
This function tries to fetch a given URL using the fetch API. It either returns a Promise for the response text or throws an error, if the url can't be fetched.
Kind: global function
Returns: Promise.<string>
- Promise for the fetched data text.
Throws:
Error
Throws an error if the URL can't be fetched for some reason.
Param | Type | Description |
---|---|---|
url | string | Url to be fetched. |
options | Object | Optional fetch options. |
Example
fetchUrl("https://spoo.me/", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
},
body: new URLSearchParams({url: "example.com"})
}).then(data => {
console.log(data);
}).catch(error => {
console.error(error);
});
Example
fetchUrl("https://example.com/").then(d => {}).catch(e => {});
fetchMeta(identifier) ⇒ Promise.<Document>
This function fetches a meta XML file using a given Trismegistos identifier.
It constructs a URL from the identifier and fetches the URL with fetchUrl
.
The file is parsed using DomParser
and returned in XML format.
If the identifier is not valid, it will throw an error.
Kind: global function
Returns: Promise.<Document>
- Promise resolving to the wanted XML file.
Throws:
Error
Throws an error if the identifier is not valid or if an error occurs while fetching the URL.
Param | Type | Description |
---|---|---|
identifier | string | Trismegistos identifier for the file to fetch. |
Example
const xml = fetchMeta("1").then(metaXml => {}).catch(e => {});
fetchDdb(ddbHybrid) ⇒ Promise.<Document>
This function fetches a meta XML file using a given hybrid identifier.
It constructs a URL from the identifier and fetches the URL with fetchUrl
.
The file is parsed using DomParser
and returned in XML format.
Kind: global function
Returns: Promise.<Document>
- Promise resolving to the wanted XML file.
Throws:
Error
Throws an error if an error occurs while fetching the URL.
Param | Type | Description |
---|---|---|
ddbHybrid | string | Hybrid identifier for the file to fetch. |
Example
const xml = fetchDdb("psi;4;345").then(ddbXml => {}).catch(e => {});
isInteger(str) ⇒ boolean
This function tests if a given string is an integer or not and returns a boolean value.
Kind: global function
Returns: boolean
- True, if the string is a integer.
Param | Type | Description |
---|---|---|
str | string | String to test. |
Example
isInteger("42");
// Output: true.
Example
isInteger("I'm an integer.");
// Output: false.