flt-lib
is a JavaScript library for creating and manipulating filter byte arrays compatible with Developer Express's FLT format. It allows converting between a JSON-based filter object and the binary FLT format.
To convert between FLT files and JSON:
# Convert a JSON file to FLT (using example.js)
node example.js
The library provides functions for converting a JSON filter object to FLT files and vice versa. It supports various comparison operations and logical operations, defined in constants.js
.
{
"operation": "OR",
"conditions": [
{
"type": "condition",
"value": "prefix%",
"matchType": "LIKE",
"row": 1
},
{
"type": "group",
"operation": "AND",
"conditions": [
{
"type": "condition",
"value": ["X", "Y"],
"matchType": "IN_LIST",
"row": 2
},
{
"type": "condition",
"value": "100",
"matchType": "BIGGER_EQUALS",
"row": 3
}
]
}
]
}
To run the tests, execute the following command:
npm test
This will run the tests defined in lib.test.js
.
npm install flt-lib
const {
jsonToByteArray, // Convert JSON filter to FLT byte array
saveUint8ArrayToFile, // Save byte array to .flt file
parseFlt // Parse FLT bytes to JSON
} = require('flt-lib');
The library provides the following operations and match types:
AND
OR
NAND
NOR
EQUALS
NOT_EQUALS
SMALLER
SMALLER_EQUALS
BIGGER
BIGGER_EQUALS
LIKE
NOT_LIKE
BETWEEN
NOT_BETWEEN
IN_LIST
NOT_IN_LIST
CONTAINS
NOT_CONTAINS
STARTS_WITH
ENDS_WITH
// 1. Create a filter object
const filter = {
operation: 'OR',
conditions: [{
type: 'condition',
value: ['A', 'B', 'C'],
matchType: 'IN_LIST',
row: 2
}]
};
// 2. Convert to FLT format
const fltBytes = jsonToByteArray(filter);
saveUint8ArrayToFile(fltBytes, 'filter.flt');
// 3. Read and convert back
const restoredFilter = byteArrayToJson(fltBytes);
try {
const parsed = parseFlt(fltBytes);
} catch (error) {
console.error('Invalid FLT format:', error);
}
The library verifies round-trip conversion integrity:
- Sort object keys consistently
- Compare JSON representations
- Validate binary serialization
Run tests with:
npm test
- Validate FLT bytes with
parseFlt()
- Prefer
IN_LIST
over multipleEQUALS
conditions - Use groups for complex nested logic