Food-Static-Data / food-static-files-generator

Module that help to generate static JSON files with complex structure
3 stars 13 forks source link
complex-structures generator npm

Generator module for food tech static files

Build Status

Maintainability

Test Coverage

Quick Start

Several quick start options are available:


How to split json into single elements

To split json file you will require sd/generator/writeFile.js . Call the function split() with parameters path(as string),filename(as string) and a flag(0 or 1). Flag=0 means splitted elements are to be name after the name attribute and if flag=1 then elements will be give named by a number with removed whitespaces and in lowercase to maintain uniformity. The splitted elements will be stored at the given path/filename_elements.

split

split('path_of_directory','fileName',0) - split files by their name attribute.

split('path_of_directory','fileName',1) - split files by indexing them from 0.

Checkout the folder fileName_elements in the path_of_directory to see files or you can use function getFileInfo().

To call the function getFileInfo(path,flag,fileName) you will require sd/src/utils.js. It can be invoked with 3 parameteres and 2 of them are optional depending on task. First parameter is path and it is required for functionality. The second and third parameters are flag and fileName.

If flag=1 it will return the content of all files present in the path else if fileName is given then it will return the content of the specified file.

If there is only one parameter that is path or with flag=0 it will return list of all files present in the directory.

You can combine objects by calling function combine() from writeFile.js. It takes 2 parameters path and list of keys_to_be_removed.

combine

combine(path, keys_to_be_removed) - This will read all files in the given path and remove the keys given the list of keys_to_be_removed and saves it into a new file in the given path as name <dirName>_combined.json.

Example: combine('/abc/pqr/', ['id', 'img'])

If you want to modify the json structure of splitted files and combine them again to a single file then you can call splitObject with a call back function.


at jsonlint we should check only new generated json files. and we need to clean up a lot of things here are not necessary. let's discuss it as well


Table of Contents

Synopsis

This is a module for using generator functions as a seperate module to generate static food data files The functions granted by this module are as follows:

//@TODO update this section

//@TODO we need to update this section

How to generate additional files

To run generator (it will run in writeFile.js function writeFiles()) npm run generateFiles to know if writing is success in console you will see file generated successfully! it will write multiple files.

In function writeFiles() should be array of files. In array config of objects. First property in object should be name and value filename, the second data and in value set function that returns data.

Also you can write one file using function writeFile() just give it two parameters first - path, second data that will need to write. Data should be object and JSON format.

Generate Array API

generateArrWithId(data, idName) - return an array of objects, where each object has autogenerated ID. Output:

[
  {
    ...item,
    id: __generatedID
  },
]

getKeyArrayDepAndIng() - returns an array of objects, where each object stores ingredient key as department key

[
  {
    key:String
  }
]

Additional information

xxx

Installation

npm install @groceristar/static-data-generator

or

yarn add @groceristar/static-data-generator

Code Example

xxx


Tests

npm test

Contributors

@vadim9999, @atherdon, @AndrewSerra, @amogh-jrules, @svr8, @Edebo

ESLint fix

npm run code-fix or yarn code-fix

List of plugins related to this universe:


"files": [
   "dist/*.js",
   "dist/*.d.ts",
   "bin/rollup"
 ]

https://www.npmjs.com/package/type-detect