0111e23fb7
- @tryghost/domain-events@0.1.12 - @tryghost/express-dynamic-redirects@0.2.11 - @tryghost/magic-link@1.0.24 - @tryghost/member-analytics-service@0.1.14 - @tryghost/member-events@0.4.4 - @tryghost/members-analytics-ingress@0.1.15 - @tryghost/members-api@6.3.1 - @tryghost/members-csv@1.2.13 - @tryghost/members-events-service@0.4.1 - @tryghost/members-importer@0.5.12 - @tryghost/members-ssr@1.0.26 - @tryghost/members-offers@0.11.4 - @tryghost/members-payments@0.3.4 - @tryghost/members-stripe-service@0.10.3 - @tryghost/verification-trigger@0.2.3 |
||
---|---|---|
.. | ||
lib | ||
test | ||
.eslintrc.js | ||
index.js | ||
LICENSE | ||
package.json | ||
README.md |
Members Csv
Install
npm install @tryghost/members-csv --save
or
yarn add @tryghost/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,,,,,,"
Develop
This is a mono repository, managed with lerna.
Follow the instructions for the top-level repo.
git clone
this repo &cd
into it as usual- Run
yarn
to install top-level dependencies.
Run
yarn dev
Test
yarn lint
run just eslintyarn test
run lint and tests
Copyright & License
Copyright (c) 2013-2022 Ghost Foundation - Released under the MIT license.