fixedwidth 0.2.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 0

fixedwidth

A library for working with fixed width files in dart.

This library helps you easily create a Record layout that clearly describes the desired layout size and output formats. You can go both ways - taking a fixed width record and turning it into a dart object, or loading a dart object and outputting a fixed width string.

Usage

To get started - first define your Record layout. Note that class constructors are not inherited and you'll need to include them in your own Record definition to get the fromRecord behavior.

import 'package:intl/intl.dart';
import 'package:fixedwidth/fixedwidth.dart';

class PersonRecord extends Record {
  StringField first_name = new StringField(20);
  StringField last_name = new StringField(20);
  DateTimeField dob =
      new DateTimeField(10, format: new DateFormat("yyyy-MM-dd"));
  IntegerField num_siblings = new IntegerField(2, defaultValue: 0);
  DecimalField amount_due = new DecimalField(8, decimals: 2);

  PersonRecord();
  PersonRecord.fromRecord(String record) : super.fromString(record);
}

You can take a Record, populate it, and turn it to a fixed width string.

var record = new PersonRecord()
  ..first_name.value = "John"
  ..last_name.value = "Doe"
  ..dob.value = new DateTime(1980, 4, 16)
  ..num_siblings.value = 2
  ..amount_due.value = 24.75;
print(record.toString());
print("Total Record Length: ${record.length()}");

You can also take a fixed width string and turn it into the appropriate dart object. Calling a field's value gives you the dart typed object.

var record2 = new PersonRecord.fromRecord(
  "Benjamin            Franklin            1706-01-171600003.00");
print(record2.first_name);
print(record2.last_name);
print(record2.dob.value);
print(record2.num_siblings.value);
print(record2.amount_due.value);
}

See the examples for additional usage samples.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Changelog

0.2.0

  • Added ImpliedDecimalField
  • Added SignedImpliedDecimalField
  • Added RecordField
  • Added ListField
  • Breaking Change: Record.length is now a getter, not a method

0.1.0

  • Initial version.

    Contains StringField, IntegerField, DecimalField, DateTimeField, BooleanField, and NullBooleanField

0.0.1

  • placeholder to reserve pub.dartlang.org name

example/fixedwidth_example.dart

import 'package:intl/intl.dart';
import 'package:fixedwidth/fixedwidth.dart';

class PhoneNumber extends Record {
  IntegerField area_code = new IntegerField(3);
  IntegerField prefix = new IntegerField(3);
  IntegerField line_number = new IntegerField(4);

  PhoneNumber();
  PhoneNumber.fromRecord(String record) : super.fromString(record);
}

/// Person Record demonstrates using most field types.
///
/// The phone_number field is a `RecordField` which is comprised of
/// an entire record.
class PersonRecord extends Record {
  StringField first_name = new StringField(20);
  StringField last_name = new StringField(20);
  DateTimeField dob =
      new DateTimeField(10, format: new DateFormat("yyyy-MM-dd"));
  IntegerField num_siblings = new IntegerField(2, defaultValue: 0);
  DecimalField amount_due = new DecimalField(8, decimals: 2);
  RecordField phone_number = new RecordField(PhoneNumber);

  PersonRecord();
  PersonRecord.fromRecord(String record) : super.fromString(record);
}

main() {
  // You can take a Record, populate it, and turn it to a fixed width string.
  var phone = new PhoneNumber()
    ..area_code.value = 215
    ..prefix.value = 222
    ..line_number.value = 3333;

  var record = new PersonRecord()
    ..first_name.value = "John"
    ..last_name.value = "Doe"
    ..dob.value = new DateTime(1980, 4, 16)
    ..num_siblings.value = 2
    ..amount_due.value = 24.75
    ..phone_number.value = phone;
  print("'${record.toString()}'");
  print("Total Record Length: ${record.length}");

  // You can take a fixed width string and turn it into the appropriate
  // dart object
  var record2 = new PersonRecord.fromRecord(
      "Benjamin            Franklin            1706-01-171600003.002151112222");
  print(record2.first_name);
  print(record2.last_name);
  print(record2.dob.value);
  print(record2.num_siblings.value);
  print(record2.amount_due.value);
  print(record2.phone_number.value.area_code.value);
  print(record2.phone_number.value.prefix.value);
  print(record2.phone_number.value.line_number.value);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fixedwidth: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fixedwidth/fixedwidth.dart';
  
Version Uploaded Documentation Archive
0.3.1 Apr 11, 2018 Go to the documentation of fixedwidth 0.3.1 Download fixedwidth 0.3.1 archive
0.3.0 Mar 16, 2018 Go to the documentation of fixedwidth 0.3.0 Download fixedwidth 0.3.0 archive
0.2.0 Mar 13, 2018 Go to the documentation of fixedwidth 0.2.0 Download fixedwidth 0.2.0 archive
0.1.0 Mar 9, 2018 Go to the documentation of fixedwidth 0.1.0 Download fixedwidth 0.1.0 archive
0.0.1 Mar 4, 2018 Go to the documentation of fixedwidth 0.0.1 Download fixedwidth 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0