Skip to content

Commit ee4386c

Browse files
committed
updated
1 parent 66b1d59 commit ee4386c

File tree

6 files changed

+340
-334
lines changed

6 files changed

+340
-334
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
temp.jsonld
22
node_modules/
33
functionhub_implementations/
4-
4+
function-handler-js.iml

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Function Handler (JS implementation)
2+
3+
## Installation
4+
5+
`npm install`
6+
7+
## Example
8+
9+
`node example-client.js`

example-client.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
1-
var fnHub = require('./functionHub-library')('https://fno.io/hub/api');
1+
const fnHub = require('./functionHub-library')('https://fno.io/hub/api');
22

33
function printFunctions(functions) {
4-
console.log(
5-
'This query found ' + functions.length + ' possible functions:'
6-
);
7-
functions.forEach(func => console.log('\t' + func.func.name));
4+
console.log(
5+
'This query found ' + functions.length + ' possible functions:'
6+
);
7+
functions.forEach(func => console.log('\t' + func.func.name));
88
}
99

1010
function printParameters(func) {
11-
const { expects, returns } = func.func;
12-
console.log({ expects, returns });
11+
const {expects, returns} = func.func;
12+
console.log({expects, returns});
1313
}
1414

1515
var query = {
16-
expects: [{ type: 'float' }, { type: 'float' }],
17-
returns: { type: 'float' }
16+
expects: [{type: 'float'}, {type: 'float'}],
17+
returns: {type: 'float'}
1818
};
1919

2020
async function main() {
21-
console.log('Query without keyword filter:');
22-
let queryResult = await fnHub.doQuery(query);
23-
printFunctions(queryResult);
24-
25-
query['keywords'] = ['total population'];
26-
27-
console.log('\nQuery with keyword filter:');
28-
printFunctions(await fnHub.doQuery(query));
29-
30-
// This is the one
31-
var totalPopulationFunction = (await fnHub.doQuery(query))[0];
32-
33-
console.log('\nFunction parameters info:');
34-
printParameters(totalPopulationFunction);
35-
36-
var populationDensity = 363.6;
37-
var totalArea = 30528.0;
38-
var totalPopulationImplementation = (await fnHub.getImplementationsFromFunction(
39-
totalPopulationFunction
40-
))[0];
41-
console.log(
42-
'\nThe total population of Belgium is: ' +
43-
totalPopulationImplementation(populationDensity, totalArea)
44-
);
45-
46-
console.log("\nNew query, let's find indent function.");
47-
const indentQuery = {
48-
expects: [{ type: 'string' }, { type: 'integer' }],
49-
returns: { type: 'string' },
50-
keywords: ['indent']
51-
};
52-
queryResult = await fnHub.doQuery(indentQuery);
53-
printFunctions(queryResult);
54-
55-
console.log(
56-
'Let\'s call its implementation on the string "Hey" with the additional parameter "8":'
57-
);
58-
var indentImplementation = (await fnHub.getImplementationsFromFunction(
59-
queryResult[0]
60-
))[0];
61-
62-
console.log(indentImplementation('Hey', 8));
63-
64-
console.log("\nNew query, let's find left-pad function.");
65-
const leftpadQuery = {
66-
expects: [{ type: 'string' }, { type: 'integer' }],
67-
returns: { type: 'string' },
68-
keywords: ['left-pad']
69-
};
70-
queryResult = await fnHub.doQuery(leftpadQuery);
71-
printFunctions(queryResult);
72-
73-
console.log(
74-
'Let\'s call its implementation on the string "Hey" with the additional parameter "5":'
75-
);
76-
var leftpadImplementations = await fnHub.getImplementationsFromFunction(
77-
queryResult[0]
78-
);
79-
80-
console.log(`Found ${leftpadImplementations.length} implementations:`);
81-
leftpadImplementations.forEach((imp, i) => {
82-
console.log('\tOutput of implementation', i, ':', imp('Hey', 5));
83-
});
21+
console.log('Query without keyword filter:');
22+
let queryResult = await fnHub.doQuery(query);
23+
printFunctions(queryResult);
24+
25+
query['keywords'] = ['total population'];
26+
27+
console.log('\nQuery with keyword filter:');
28+
printFunctions(await fnHub.doQuery(query));
29+
30+
// This is the one
31+
var totalPopulationFunction = (await fnHub.doQuery(query))[0];
32+
33+
console.log('\nFunction parameters info:');
34+
printParameters(totalPopulationFunction);
35+
36+
var populationDensity = 363.6;
37+
var totalArea = 30528.0;
38+
var totalPopulationImplementation = (await fnHub.getImplementationsFromFunction(
39+
totalPopulationFunction
40+
))[0];
41+
console.log(
42+
'\nThe total population of Belgium is: ' +
43+
totalPopulationImplementation(populationDensity, totalArea)
44+
);
45+
46+
console.log("\nNew query, let's find indent function.");
47+
const indentQuery = {
48+
expects: [{type: 'string'}, {type: 'integer'}],
49+
returns: {type: 'string'},
50+
keywords: ['indent']
51+
};
52+
queryResult = await fnHub.doQuery(indentQuery);
53+
printFunctions(queryResult);
54+
55+
console.log(
56+
'Let\'s call its implementation on the string "Hey" with the additional parameter "8":'
57+
);
58+
var indentImplementation = (await fnHub.getImplementationsFromFunction(
59+
queryResult[0]
60+
))[0];
61+
62+
console.log(indentImplementation('Hey', 8));
63+
64+
console.log("\nNew query, let's find left-pad function.");
65+
const leftpadQuery = {
66+
expects: [{type: 'string'}, {type: 'integer'}],
67+
returns: {type: 'string'},
68+
keywords: ['left-pad']
69+
};
70+
queryResult = await fnHub.doQuery(leftpadQuery);
71+
printFunctions(queryResult);
72+
73+
console.log(
74+
'Let\'s call its implementation on the string "Hey" with the additional parameter "5":'
75+
);
76+
var leftpadImplementations = await fnHub.getImplementationsFromFunction(
77+
queryResult[0]
78+
);
79+
80+
console.log(`Found ${leftpadImplementations.length} implementations:`);
81+
leftpadImplementations.forEach((imp, i) => {
82+
console.log('\tOutput of implementation', i, ':', imp('Hey', 5));
83+
});
8484
}
8585

8686
main().catch(console.error);

0 commit comments

Comments
 (0)