Ghost/ghost/members-csv
Daniel Lockyer 54aa9f016b Fixed full Admin test suite running during unit tests
- because of how the npm scripts were set up, we were running the full
  Admin integration tests during the unit tests phase of CI
- this commit renames the majority of `test` to `test:unit` in the
  package.json files, and aliases `test` to `test:unit`
- special packages like Admin have no-op'd `test:unit` scripts so we
  don't end up running its tests
2022-08-15 15:34:52 +02:00
..
lib Fixed members-csv not using renamed tiers field 2022-05-19 18:09:50 +02:00
test Fixed CSV unparsing for subscribed flag 2022-01-11 16:26:11 +02:00
.eslintrc.js Removed trailing commas from .eslintrc.js 2021-07-14 12:04:46 +01:00
index.js Fixed module paths 2020-06-19 19:52:21 +12:00
package.json Fixed full Admin test suite running during unit tests 2022-08-15 15:34:52 +02:00
README.md Tidied up package READMEs 2022-07-25 15:17:12 +02:00

Members Csv

Usage

There are 2 parts to this package: CSV to JSON serialization and JSON to CSV serialization. The module exposes 2 methods to fullfil these: parse and unparse respectively.

To parse CSV file and convert it to JSON use parse method, e.g.:

const {parse} = require('@tryghost/members-csv');

const mapping = {
    email: 'csv_column_containing_email_data',
    name: 'csv_column_containing_names_data'
}
const membersJSON = await parse(csvFilePath, mapping);

csvFilePath - is a path to the CSV file that has to be processed mapping - optional parameter, it's a hash describing custom mapping for CSV columns to JSON properties

Example mapping for CSV having email under correo_electronico column would look like following:

{
    email: 'correo_electronico'
}

To unparse JSON to CSV compatible with members format use following:

const {unparse} = require('@tryghost/members-csv');

const members = [{
    email: 'email@example.com',
    name: 'Sam Memberino',
    note: 'Early supporter'
}];

const membersCSV = unparse(members);

console.log(membersCSV);
// -> "id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels\r\n,email@example.com,Sam Memberino,Early supporter,,,,,,"