JavaScript/TypeScript Documentation
fitl-js is available on npm repositories
npm install fitl-js
pnpm install fitl-js
Getting Started
To filter a basic JavaScript array of objects:
import { fitlFilter } from "fitl-js";
let tableData = [
{ category: "meat" },
{ category: "fruit" }
];
let query = "category = fruit";
async function main() {
try {
let resultTable = await fitlFilter(query, tableData);
console.log(resultTable);
} catch (error: unknown) {
console.error(error);
}
}
main();
With everything installed correctly this outputs to a new table:
> [{category: "fruit"}]
Options are optional of course, currently used to specify input/output table types with other future options coming soon.
import { fitlFilter, type Options } from 'fitl-js';
let tableData = [
{ category: "meat" },
{ category: "fruit" }
];
let query = "category = fruit";
let options: Options = { tableFormat: 'JSARRAY' };
async function main(){
try {
let resultTable = await fitlFilter(query, tableData, options);
} catch (error: unknown) {
console.error(error);
}
}
main();
Default tableFormat is JSARRAY, other table formats coming soon and will have to be specifically defined in options
Column Types
You can specify a data type for a column for more specific query options.
For example:
let tableData = [
{ name: "apple", amount: 3 },
{ name: "banana", amount: 8 }
];
let query = "";
console.log(await fitlFilter(query, tableData));
The above will automatically parse the "amount" column as a string. This example outputs:
[{ name: "apple", amount: 3 },
{ name: "banana", amount: 8 }]
And only allows you to do string based operations on the amount column. To specify that the amount column is a numeric column in the options parameter of "filtFilter" like so:
const options: Options = {
columnTypes: {
amount: "number",
}
}
In code example:
let tableData = [
{ name: "apple", amount: 3 },
{ name: "banana", amount: 8 }
];
let query = "";
const options: Options = {
tableFormat: "JSARRAY",
columnTypes: {
amount: "number",
}
}
console.log(await fitlFilter(query, tableData, options));
Which allows for numeric operations on columns and outputs the "amount" values as actual JavaScript numbers:
[{ name: "apple", amount: 3 },
{ name: "banana", amount: 8 }]