Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce formatters #455

Merged
merged 1 commit into from
Sep 30, 2020
Merged

Introduce formatters #455

merged 1 commit into from
Sep 30, 2020

Conversation

juanjoDiaz
Copy link
Collaborator

Alright! v5 seems to have some shortcomings so let's get right into v6.

This PR introduces the concept of formatters which allow the user to customize how different Javascript types are converted into text for CSV.

This would fix the 2 use cases explained in #420 and will provide a better solution for #444.
Also, I'm planning to add a second argument to formatters indicating if it's a header or not) which will fix the use case explained in #195.

This PR is to gather comments from the community if there are any.
I'm still working on fine-tuning the concept a fit further.

@coveralls
Copy link

coveralls commented Apr 18, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 1a0d480 on juanjoDiaz:introduce_formatters into 7ade321 on zemirco:master.

@juanjoDiaz
Copy link
Collaborator Author

This PR is ready for review and merge.

Main features added:

Small changes:

  • move code examples to separate files in the docs folder (to be continued when tackling Improve the documentation/replace docpress #466)
  • change all the test data from "transmission": manual to "manual": true to include boolean data in the test and improve coverage.

Copy link
Collaborator

@knownasilya knownasilya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things, overall it looks 💯

Was the change to "manual" in the tests to test the boolean formatter?
Looks like coverage has decreased, do we need some additional tests?

package.json Outdated
@@ -34,7 +34,7 @@
"lint": "eslint bin lib test",
"test-with-coverage": "nyc --reporter=text node test | tap-spec",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"deploy:docs": "docpress b && gh-pages -d _docpress",
"deploy:docs": "docpress s",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this needs to be reverted. Maybe add another script for serving docs?

bin/json2csv.js Outdated Show resolved Hide resolved

if (value === undefined) return '';

if (value[0] === '"') value = value.replace(/^"(.+)"$/,'$1');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment about what this is doing.

const defaulStringFormatter = require('./string');

function stringExcel(opts = { stringFormatter: defaulStringFormatter() }) {
return (value) => `"="${opts.stringFormatter(value)}""`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A link or comment about why this is the way it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented in the readme. Do you think that it should also be documented here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, mainly if there is an issue or someone wants to submit a PR adding features here.

lib/formatters/stringQuoteOnlyIfNecessary.js Show resolved Hide resolved
@knownasilya
Copy link
Collaborator

Is this ready to merge?

@knownasilya knownasilya merged commit 88ed6ee into zemirco:master Sep 30, 2020
@juanjoDiaz
Copy link
Collaborator Author

sorry @knownasilya I've been in the middle of moving to a new country and pretty busy.

One thing that I was thinking is that we should probably merge these v5 PRs to a v5 branch so we don't get people confused because the Readme doesn't match the npm version.

@knownasilya
Copy link
Collaborator

I'm going to add a note to the top of the readme pointing to the last published readme and mentioning under construction.

@juanjoDiaz
Copy link
Collaborator Author

This closed #463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants