
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
fixed-width-ts-decorator
Advanced tools
This lib provide decorator for fixed width file so that the domain class and spec can stay together. No separate schema creation is needed so that it is more readable, maintainable and extensible.
npm i fixed-width-ts-decorator
This lib uses reflect-metadata for Meta programming.
Inheritance is supported that fields decorated in parent classes will also be included/processed.
// class inheritance is Optional here.
export class Transaction extends FixedWidthConvertible {
@FixedWidth({ start: 0, width: 5 })
clientId: string;
@FixedWidth({ start: 5, width: 40 })
parentName: string;
@FixedWidth({ start: 45, width: 40, format: { type: DataType.Float } })
taxAmount: number;
@FixedWidth({
start: 85,
width: 40,
format: {
type: DataType.Float,
precision: 3,
},
})
paymentAmount: number;
@FixedWidth({
start: 125,
width: 20,
format: { type: DataType.Integer },
})
paymentTimeStamp: number;
@FixedWidth({ start: 145, width: 40 })
userId: string;
@FixedWidth({ start: 225, width: 40 })
paymentId: string;
// other non-decorated fields
otherField: string;
}
(() => {
// Or you can read file line by line
const file = fs.readFileSync('data/sample.txt', { encoding: 'utf8' });
const lines = file.split('\n').filter(l => l);
const rs: Array<Transaction> = lines.map(line => {
const trans = new Transaction();
/**
* Option 1: if your domain class extends the abstract `FixedWidthConvertible` class,
* then you can use the instance.convertFixedWidth method.
*/
trans.convertFixedWidth(line);
/**
* Option 2: if your domain class already extends some other classes
* then use the static function on the `FixedWidthConvertible` class and pass in the instance as argument like below.
*/
// FixedWidthConvertible.convertFixedWidth(line, trans);
return trans;
});
console.log(rs);
})()
FAQs
Fixed width file handler with TypeScript Decorator
We found that fixed-width-ts-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.