Giter Club home page Giter Club logo

swiftcsvencoder's People

Contributors

scottmatthewman avatar

Stargazers

 avatar  avatar

Watchers

 avatar

swiftcsvencoder's Issues

Create static configuration objects with the relevant structure for popular CSV importers

Different applications that are capable of importing CSV files have different ways of handling some data types. Indeed, that it why CSVEncoderConfiguration exists.

But each app generally wants the same format all the time, and developers shouldn’t need to have to remember (or investigate) which date formats are needed for the most popular apps.

We could provide static instances of CSVEncoderConfiguration that have the necessary encoding strategies predefined, for example:

CSVEncoderConfiguration.excel // All the necessary config to ensure CSV files are readable by Microsoft Excel
CSVEncoderConfiguration.numbers // All the necessary config to ensure CSV files are readable by Apple Numbers

This would make the definitions more expressive while hiding the implementation detail:

let table = CSVTable<Person>(columns: [  ], configuration: .excel)

Add a configuration strategy for Boolean encoding

Booleans are currently configured to output as the text strings true or false.

Add a new configuration parameter to CSVEncoderConfiguration to support different styles of encoding:

encoding type True encodes as False encodes as
.trueFalse (default) true false
.trueFalseUppercase TRUE FALSE
.yesNo yes no
.yesNoUppercase YES NO
.integer 1 0

Expected work to do:

  • Add BoolEncodingStrategy enum to CSVEncoderConfiguration with all options documented
  • Add boolEncodingStrategy property to CSVEncoderConguration
  • Update CSVEncoderConfiguration.default to use the default [^1]
  • Update Bool.encode() method to amend output based on configuration strategy
  • Add unit tests for each strategy
  • Review and verify generated DocC documentation

Add CSVEncodable support for more numeric types

Currently, Double and Int have CSVEncodable support added. Any other numeric types have to handle their own encoding within the CSVColumn configuration.

Expanding the list of support to Float, UInt, etc., could be useful.

Introduce Builder-style syntax

Currently, CSV tables are defined as in the following example:

let table = CSVTable<Person>(
  columns: [
    CSVColumn("ID", \.id),
    CSVColumn("Name", \.name),
    // etc.
  ],
  configuration: .default
)

This isn't great for situations where I might need a more dynamic approach to column inclusion. For example, only users with a certain level of access may have access to personally sensitive information and their CSVs shouldn't attempt to include those columns. Or, I may have a feature in the app that is governed by a feature flag, and columns should be omitted if that flag is not on.

Another approach would be to use a ResultBuilder-style syntax for building table definitions, say:

CSVTable(configuration: .default) {
  Column("ID", \.id)
  Column("Name", \.name)
  if currentUser.isSuperAdmin {
    Column("Address", \.postalAddress)
    Column("Tel", \.telephone)
  }
  if FeatureSet.includes(.starRatings) {
    Column("Star rating") { StarRating($0.value) }
  }
}

This might also allow for configuration to be broken up and implemented as modifiers:

CSVTable {
  Column("ID", \.id)
  Column("Date of birth", \.date)
    .dateFormat(.iso8601)
}
.fieldDelimiter(.tab)

Suggestion: Migrate configuration to `export` method

Currently, the configuration object that governs encoding strategies for dates (and, when #2 is implemented, Booleans) is defined in the CSVTable initialiser.

However, it is only used at the export stage. And it could be argued that it only matters there: the CSVTable is a definition of the structure, and it is only when we solidify that data that we actually care what format to use. This could allow the same CSVTable structure to be encoded in slightly different ways, for example, if Excel and/or Numbers needed slightly different formats than a custom app with its own CSV importer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.