
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
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
The npm package fixed-width-ts-decorator receives a total of 42 weekly downloads. As such, fixed-width-ts-decorator popularity was classified as not popular.
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
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.