itol-ts
v1.0.0
Published
A TypeScript library for JSON-based function execution with file I/O operations
Maintainers
Readme
ITOL-TS
A TypeScript library for JSON-based function execution with file I/O operations.
Installation
npm install itol-tsUsage
Basic Usage
import { createStartPoint } from 'itol-ts';
// Define your function with typed parameters
interface MyParams {
name: string;
age: number;
}
interface MyResult {
message: string;
timestamp: number;
}
function myFunction(params: MyParams): MyResult {
return {
message: `Hello ${params.name}, you are ${params.age} years old!`,
timestamp: Date.now()
};
}
// Create the start point
const startFunction = createStartPoint<MyParams, MyResult>(myFunction);
// Execute (this would typically be called from command line)
startFunction();Command Line Usage
After building your script, you can run it from the command line:
node your-script.js request.json response.jsonWhere:
request.jsoncontains the input parametersresponse.jsonwill contain the function result
Example request.json:
{
"name": "John",
"age": 30
}Example response.json (generated):
{
"message": "Hello John, you are 30 years old!",
"timestamp": 1629123456789
}Advanced Usage
You can also use the utility functions directly:
import { readJsonFile, saveResultJson } from 'itol-ts';
// Read JSON file with type safety
const data = readJsonFile<MyParams>('input.json');
// Save result to JSON file
saveResultJson('output.json', { success: true });API
createStartPoint<Params, ResultType>(startFunc)
Creates a function that can be executed with JSON file input/output.
startFunc: The function to execute with the parsed JSON parameters- Returns: A function that reads JSON from command line arguments, executes the function, and saves the result
readJsonFile<T>(filePath)
Reads and parses a JSON file with type safety.
filePath: Path to the JSON file- Returns: Parsed object of type T, or undefined if reading/parsing fails
saveResultJson<T>(responseJsonPath, result)
Saves a result object to a JSON file.
responseJsonPath: Path where to save the JSON fileresult: The object to save
License
MIT
