2.0.2 • Published 4 years ago

spread2json v2.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

NPM version Downloads

Spread2Json

Can be converted to JSON format any SpreadSheet data.

example SpreadSheet data

ABCD
1{}
2_idobj.codeobj.value:number
3
4firstone1
5secondtwo2
6

converted to Object

[
    {
        _id: 'first',
        obj: {
            code: 'one',
            value: 1
        }
    }, 
    {
        _id: 'second',
        obj: {
            code: 'two',
            value: 2
        }
    }
]

Installation

npm install spread2json

Usage

Quick start

example

ABCD
1{name: 'Test'}
2_idobj.codeobj.value:number
3
4firstone1
5secondtwo2
6

Sheet1

var spread2json = require('spread2json');

var spreadsheetKye = 'spreadsheetkey';
var worksheetNames = ['Sheet1'];
spread2json.getWorksheetDatas(spreadsheetKey, worksheetNames, function(err, data) {
    console.log(data);
    // [{
    //    name: 'Sheet1',            // sheet name
    //    opts: { name: 'Test' },    // sheet option (A1)
    //    list: [
    //        { _id: 'first', obj: { code: 'one', value: 1 } }, { _id: 'second', obj: { code: 'two', value: 2 } }
    //    ]
    // }]

    spread2json.toJson(data, function(err, json) {
        console.log(json);
        // {
        //    Test: {
        //        first: {
        //            _id: 'first',
        //            obj: { code: 'one', value: 1 }
        //        },
        //        second: {
        //            _id: 'second',
        //            obj: { code: 'two', value: 2 }
        //        }
        //    }
        // }
    });
});

Setup

Setup options.

var spread2json = require('spread2json');

spread2json.setup({
  option_cell: 'A1',  // Cell with a custom sheet option. It is not yet used now. (default: 'A1'
  attr_line: 2,       // Line with a data attribute. (default: 2
  desc_line: 3,       // Line with a attribute description. (default: 3
  data_line: 4,       // Line with a data. (default: 4
  ref_keys: ['_id'],  // ref key. (default: ['_id']
  logger: customLogger, // custom Logger
  api: {
    client_id: 'YOUR CLIENT ID HERE',
    client_secret: 'YOUR CLIENT SECRET HERE',
    redirect_url: 'http://localhost',
    token_file: {
      use: true,
      path: './dist/token.json'
    }
  }
});

Sheet option

sheet option. setting with optionCell (default: 'A1'

  • name
  • type
  • key
  • attr_line
  • data_line
  • ref_keys

Attribute

Specify the key name.

Special character

  • # Use when the array.
  • $ Use when the split array.
  • :number or :num Use when the parameters of type Number.
  • :boolean or :bool Use when the parameters of type Boolean.
  • :date Use when the parameters of unix time.
  • :index Use when the array of array.
ABCDEF
1{}
2_id#arr$sarrnum:numberbool:booleandate:date
3
4normal_stringarray1a,b,c1FALSE2014/08/01 10:00:00
5array2
{
    _id: 'normal_string',
    arr: [ 'array1', 'array2' ],
    sarr: [ 'a', 'b', 'c' ],
    num: 1,
    bool: false,
    date: 1406854800000 // < new Date('2014/08/01 10:00:00').getTime() user env GMT
}

Sample

sample project. spread2json_sample

Contribution

  1. Fork it ( https://github.com/iyu/spread2json/fork )
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the npm test; npm run lint command and confirm that it passes
  6. Create new Pull Request
2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.4.2

5 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

0.4.2

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago