1.1.1 • Published 2 years ago

@floralink/generator v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@floralink/generator

Simple CLI tool for generating Floralink plugin databases from CSV files. The data is mapped to per-taxon objects with the help of a mappings.js configuration file. More generally Generator can map CSV tables to JSON files given a mapping structure. It's possible to build nested object structures from two-dimensional tables.

Usage

Install @floralink/generator as a dev dependency in your plugin package:

$ npm install -D @floralink/generator

Use from your source data folder:

$ npx flgen -i mydatabase.csv

Flags

You can configure the generator with flags:

$ npx flgen -i mydatabase.csv -o db.json -m map.js -d ";"
FlagShorthandDescriptionDefault
--input-iInput file (*.csv)- (required)
--output-oOutput file (*.json)database.json
--mappings-mField mappingsmappings.js
--delimiter-dDelimiter for cells in CSV file","
--emptyvalues-eComma seperated list of values to excludeNA,k. A.

Mappings

Example mappings.js file for returning the desired object structure from a CSV generated object:

// the argument passed by the generator is the parsed object from a CSV row
export default function (o) {
  return {
    // reference
    id: o["DATA_ID"],
    reference: {
      id: "myplugin",
      version: "1.0.0",
    },
    // db fields
    myFieldOne: o["MY_FACTOR"],
    myFieldTwo: o["CRYPTIC_FIELD_NAME,d,d"],
    // can be nested too
    myFieldThree: {
      myFieldFour: "MyFieldType", // static field values
      myFieldFive: o["REF_FACTOR"],
    },
    // use functions to modify data
    myFieldSix: convertToMyFieldSix(o["component value 1"], o["component value 2"]),
  };
}

// this can be anything from switch/case statements to calculations
// it is recommended to convert data only as such
// that original data can be rebuilt though
function convertToMyFieldSix(val1, val2) {
  switch (val1): {
    // ...
  }
}

You can specify if the data entry passed in the argument should be ommited in the resulting database by returning undefined in your function. After the mapping of all entries, Generator checks all values of an entry against a list of values that mean that there is no data (see --emptyvalues flag). Fields with an empty string are always ommited.

Look at the available plugins of Floralink on GitHub for further examples.

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago