0.3.5 • Published 6 years ago

xlsx-json-parser v0.3.5

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

xlsx-json-parser

Build Status NPM version Downloads License Issues PRs Welcome dependencies status devDependencies status Codacy Badge

Description and nuances

xlsx to JSON parser. Also support i18next format. Relies on node-xlsx.

Yep, it can append new files to exist now! Cheers 😎

What's new

  • v.0.3.5 - Update Readme.md
  • v.0.3.4 - Improve recursiveSearchValues & update tests
  • v.0.3.3 - Update Readme.md
  • v.0.3.2 - Fix known issues with one level template
  • v.0.3.1 - Update Readme.md
  • v.0.3.0 - Add config tests. Fix parser. Now it's work as NPM module correctly
  • v.0.2.5 - Codystyle fixes
  • v.0.2.4 - Remove async write file & some refactoring
  • v.0.2.3 - Add author's contacts
  • v.0.2.2 - Add jest testing
  • v.0.2.1 - Refactoring
  • v.0.2.0 - Add append to exist files
  • v.0.1.0 - First init

Install

npm i xlsx-json-parser

Then add folder xlsx (you can change it in xlsx-json-parser.config.js) in your project folder

Usage

In command line

node node_modules/xlsx-json-parser

You can add this line to your package.json in scripts section

"scripts": {
    "xlsx-parse": "node node_modules/xlsx-json-parser"
  }

And when you need to parse xlsx type in your console npm run xlsx-parse

Using with arguments

node node_modules/xlsx-json-parser --ln=listNumber --xlsx=xlsxDir --json=jsonDir --wfn
Where

--ln - List number
--xlsx - Path to xlxs --json - Path to json
--wfn - With file names for json files
You can change default arguments in xlsx-json-parser.config.js

Config file

Config file xlsx-json-parser.config.js looks like

const config = {
  xlsxDir: 'xlsx',
  jsonDir: 'json',
  listNumber: 1,
  withFilenames: false,
  fileTemplate(lang, array) {
    return `{
  "${lang}": {
    "translations": ${JSON.stringify(array)}
  }
}`;
  },
};

module.exports = config;

You can overwrite it by put xlsx-json-parser.config.js to your directory

Where

xlsxDir - default folder with xlsx files
jsonDir - default folder for json files
listNumber - Number of needed list in Excel file
withFilenames - Add to json files name of xlsx files if false, json files will be overwritten fileTemplate - method for set how json might looks, where lang - is current language for file, array - items for this langugae

i18next Format

By default keys for all langs parser get value from first lang

{
  "lang": {
    "translations": {
      "key": "value",
      "another_key": "another value"
    }
  }
}

You can change format in xlsx-json-parser.config.js

Files

Parser looks into xlsxDir and parse all xls/xlsx files.
Return filenames looks like {lang}_{xlsxFileName}.json

Xlsx format

To correct parsing you need next format - First row in xlsx file is for languages. Rows are for keys and values.

Append to exist files

Yep! It can be append to exist files if your JSON file format in config equal to your exist JSON view.

Templates

If you write next template

fileTemplate(lang, array) {
    return `{
  "${lang}":  ${JSON.stringify(array)}
}`;
    }

You recieve

{
  "lang": {
      "key": "value",
      "another_key": "another value"
  }
}

If you write next template

fileTemplate(lang, array) {
    return `${JSON.stringify(array)}`;
    }

You recieve

{
  "key": "value",
  "another_key": "another value"
}
0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago