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

Add flags to have options with columns with same name, fix #10 and #8 #11

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

Irraky
Copy link

@Irraky Irraky commented Sep 5, 2018

Hello @revolunet ,

I spoke with you about columns with the same name but I don't think you understood me.

What I mean to do is that: Add two flag to precise if we want to keep column with same name.

Flag 'toArray': (transform other column to same name in an array)

const { extractSheets } = require("spreadsheet-to-json");

extractSheets({
    // your google spreadhsheet key
    spreadsheetKey: "1RbwBQOJRYNefRtAtux3O-gyV8JDrHL9BwXCoBPPQMjA",
    // your google oauth2 credentials
    credentials: null,
    // names of the sheet you want to extract (or [] for all)
    sheetsToExtract: [],
    // In an array, you list the name of the column you want to concatenate
    toArray: ["wrong"]
}, function(err, data) {
    console.log(data);
    // will output 
    //  { 'Feuille 1': 
    //   [
    //    {
    //      question: 'The sky is ?', 
    //      good: 'blue',
    //      wrong: ['red', 'pink', 'green'] },               <= LIKE THIS
    //    { 
    //      question: 'Water freeze at ?',
    //      good: '0',
    //      wrong: ['4', '90', '-23']                             <= LIKE THIS
    //    } 
    //   ]
    //  }

});

And flag 'toColumn': (create new object for columns with same name)

const { extractSheets } = require("spreadsheet-to-json");

extractSheets({
    // your google spreadhsheet key
    spreadsheetKey: "1RbwBQOJRYNefRtAtux3O-gyV8JDrHL9BwXCoBPPQMjA",
    // your google oauth2 credentials
    credentials: null),
    // names of the sheet you want to extract (or [] for all)
    sheetsToExtract: [],
    // Flag to return same columns in an array
    toArray: ["wrong"]
}, function(err, data) {
    console.log(data);
    // will output 
    //  { 'Feuille 1': 
    //       [ { question: 'The sky is ?',
    //           good: 'blue',
    //           wrong: 'red',                                                   
    //           wrong_2: 'pink',                                     <= LIKE THIS
    //           wrong_3: 'green' },                                <= LIKE THIS
    //         { question: 'Water freeze at ?',
    //           good: '0',
    //           wrong: '4',
    //           wrong_2: '90',                                        <= LIKE THIS
    //           wrong_3: '-23' } ] }                                  <= LIKE THIS 


});

I also add test in test.spec.js if you want to console.log and see the result.

It was not possible to have those info create with a transform function that you can apply on the output.

@gabrielstuff
Copy link

@Irraky please merge recents changes from upstream so Revolunet could check your work. Thanks!

@gabrielstuff
Copy link

Thanks @Irraky ! @revolunet what do you think of this feature and the according test?

@revolunet
Copy link
Owner

well i'm not a big fan of the toArray and toColumn naming... what about sticking to the automatic rename as proposed by the underlying module as said in #10 ?

@gabrielstuff
Copy link

gabrielstuff commented Sep 17, 2018 via email

@revolunet
Copy link
Owner

@gabrielstuff i'd be happy if we could work on this together IRL ☕️

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