| root = true | ||
| [*] | ||
| indent_style = tab | ||
| end_of_line = lf | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
| [*.yml] | ||
| indent_style = space | ||
| indent_size = 2 |
| { | ||
| "cSpell.words": [ | ||
| "configstore", | ||
| "cosmiconfig", | ||
| "islocal", | ||
| "mkdirs", | ||
| "papaparse", | ||
| "serializer", | ||
| "unparse" | ||
| ] | ||
| } |
+81
-60
@@ -1,2 +0,1 @@ | ||
| const path = require('path'); | ||
@@ -15,59 +14,83 @@ const fs = require('fs-extra'); | ||
| function CsvConfig(name,islocal){ | ||
| function CsvConfig(name, islocal) { | ||
| if(globalSymbols.indexOf(OBJ_KEY) < 0){ | ||
| global[OBJ_KEY] = CONFIG; | ||
| } | ||
| else{ | ||
| CONFIG = global[OBJ_KEY]; | ||
| return CONFIG; | ||
| } | ||
| if (globalSymbols.indexOf(OBJ_KEY) < 0) { | ||
| global[OBJ_KEY] = CONFIG; | ||
| } else { | ||
| CONFIG = global[OBJ_KEY]; | ||
| return CONFIG; | ||
| } | ||
| if(typeof name == "undefined") name = "csv-config"; | ||
| if(typeof islocal == "undefined") islocal = false; | ||
| if (typeof name == "undefined") name = "csv-config"; | ||
| if (typeof islocal == "undefined") islocal = false; | ||
| let cfgPathLocal = path.resolve(process.cwd(), name);; | ||
| let cfgPathHome = path.resolve(userHome, name); | ||
| if(islocal){ | ||
| CONFIG['current-config-dir'] = cfgPathLocal; | ||
| } | ||
| else{ | ||
| CONFIG['current-config-dir'] = cfgPathHome; | ||
| let cfgPathLocal = path.resolve(process.cwd(), name);; | ||
| let cfgPathHome = path.resolve(userHome, name); | ||
| if( ! fs.pathExistsSync(cfgPathHome)){ | ||
| fs.mkdirsSync(cfgPathHome); | ||
| if(fs.pathExistsSync(cfgPathLocal)){ | ||
| fs.copySync(cfgPathLocal,cfgPathHome,{overwrite:true}); | ||
| } | ||
| } | ||
| } | ||
| if (islocal) { | ||
| CONFIG['current-config-dir'] = cfgPathLocal; | ||
| } else { | ||
| CONFIG['current-config-dir'] = cfgPathHome; | ||
| let parse_config = {delimiter:";",skipEmptyLines:true}; | ||
| let unparse_config = {quotes: false,quoteChar: '"',delimiter:";",header:false,newline: "\r\n"}; | ||
| if (!fs.pathExistsSync(cfgPathHome)) { | ||
| fs.mkdirsSync(cfgPathHome); | ||
| if (fs.pathExistsSync(cfgPathLocal)) { | ||
| fs.copySync(cfgPathLocal, cfgPathHome, { | ||
| overwrite: true | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| var files = fs.readdirSync( CONFIG['current-config-dir']); | ||
| let parse_config = { | ||
| delimiter: ";", | ||
| skipEmptyLines: true, | ||
| header: false | ||
| }; | ||
| for(var i in files) { | ||
| let ext_name = path.extname(files[i]); | ||
| if( ext_name === ".csv") { | ||
| let base_name = path.basename(files[i],ext_name); | ||
| let file_path = path.resolve(CONFIG['current-config-dir'],files[i]); | ||
| let file_text = fs.readFileSync(file_path,'utf8'); | ||
| CONFIG[base_name] = papa.parse(file_text,parse_config); | ||
| } | ||
| } | ||
| CONFIG['save'] = function (){ | ||
| for (const [key, value] of Object.entries(CONFIG)) | ||
| { | ||
| if(typeof(value) !== 'function' && key != 'current-config-dir') | ||
| { | ||
| let text = papa.unparse(CONFIG[key].data,unparse_config); | ||
| let file_path = path.resolve( CONFIG['current-config-dir'] ,`${key}.csv`); | ||
| fs.writeFileSync(file_path,text,'utf8'); | ||
| } | ||
| } | ||
| }; | ||
| return CONFIG; | ||
| let unparse_config = { | ||
| quotes: false, | ||
| quoteChar: '"', | ||
| delimiter: ";", | ||
| header: false, | ||
| newline: "\r\n", | ||
| header: false | ||
| }; | ||
| var files = fs.readdirSync(CONFIG['current-config-dir']); | ||
| for (var i in files) { | ||
| let ext_name = path.extname(files[i]); | ||
| if (ext_name === ".csv") { | ||
| let base_name = path.basename(files[i], ext_name); | ||
| let file_path = path.resolve(CONFIG['current-config-dir'], files[i]); | ||
| let file_text = fs.readFileSync(file_path, 'utf8'); | ||
| if (/^((#[^;\n\r]+)[;]?)+/.test(file_text)) { | ||
| debugger; | ||
| parse_config.header = true; | ||
| } else { | ||
| debugger; | ||
| parse_config.header = false; | ||
| } | ||
| CONFIG[base_name] = papa.parse(file_text, parse_config); | ||
| CONFIG[base_name].header = parse_config.header; | ||
| } | ||
| } | ||
| CONFIG['save'] = function () { | ||
| for (const [key, value] of Object.entries(CONFIG)) { | ||
| if (typeof (value) !== 'function' && key != 'current-config-dir') { | ||
| unparse_config.header = CONFIG[key].header; | ||
| let text = papa.unparse(CONFIG[key].data, unparse_config); | ||
| let file_path = path.resolve(CONFIG['current-config-dir'], `${key}.csv`); | ||
| fs.writeFileSync(file_path, text, 'utf8'); | ||
| } | ||
| } | ||
| }; | ||
| return CONFIG; | ||
| }; | ||
@@ -78,11 +101,9 @@ | ||
| //for testing purpose | ||
| if (!module.parent) | ||
| { | ||
| let config = CsvConfig("CsvConfig",true); | ||
| config['atwords'].data[0][1] ++; | ||
| config['dotwords'].data[0][1] ++; | ||
| config['blacklist'].data[0][1] ++; | ||
| config.save(); | ||
| if (!module.parent) { | ||
| let config = CsvConfig("CsvConfig", true); | ||
| debugger; | ||
| //config['atwords'].data[0][1]++; | ||
| //config['dotwords'].data[0][1]++; | ||
| //config['blacklist'].data[0][1]++; | ||
| //config.save(); | ||
| } | ||
+47
-47
| { | ||
| "name": "csv-config", | ||
| "version": "1.1.4", | ||
| "description": "A `CSV` config parser and serializer for node.", | ||
| "main": "csv-config.js", | ||
| "keywords": [ | ||
| "csv-config", | ||
| "config", | ||
| "csv", | ||
| "parser", | ||
| "serializer", | ||
| "ini", | ||
| "conf", | ||
| "configuration", | ||
| "configstore", | ||
| "cosmiconfig", | ||
| "cfg", | ||
| "winston-cfg", | ||
| "parse-config-file" | ||
| ], | ||
| "dependencies": { | ||
| "path": "^0.12.7", | ||
| "fs-extra": "^4.0.3", | ||
| "user-home": "^2.0.0", | ||
| "papaparse": "^4.3.6" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "^4.0.1", | ||
| "path": "^0.12.7" | ||
| }, | ||
| "scripts": { | ||
| "start": "node csv-config.js", | ||
| "test": "mocha --recursive" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://gitlab.com/autokent/csv-config/issues", | ||
| "email": "mehmet.kozan@live.com" | ||
| }, | ||
| "homepage": "https://gitlab.com/autokent/csv-config", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://gitlab.com/autokent/csv-config.git" | ||
| }, | ||
| "author": "Mehmet Kozan <mehmet.kozan@live.com>", | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=6.8.1" | ||
| } | ||
| "name": "csv-config", | ||
| "version": "1.1.5", | ||
| "description": "A `CSV` config parser and serializer for node.", | ||
| "main": "csv-config.js", | ||
| "keywords": [ | ||
| "csv-config", | ||
| "config", | ||
| "csv", | ||
| "parser", | ||
| "serializer", | ||
| "ini", | ||
| "conf", | ||
| "configuration", | ||
| "configstore", | ||
| "cosmiconfig", | ||
| "cfg", | ||
| "winston-cfg", | ||
| "parse-config-file" | ||
| ], | ||
| "dependencies": { | ||
| "path": "^0.12.7", | ||
| "fs-extra": "^4.0.3", | ||
| "user-home": "^2.0.0", | ||
| "papaparse": "^4.3.6" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "^4.0.1", | ||
| "path": "^0.12.7" | ||
| }, | ||
| "scripts": { | ||
| "start": "node csv-config.js", | ||
| "test": "mocha --recursive" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://gitlab.com/autokent/csv-config/issues", | ||
| "email": "mehmet.kozan@live.com" | ||
| }, | ||
| "homepage": "https://gitlab.com/autokent/csv-config", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://gitlab.com/autokent/csv-config.git" | ||
| }, | ||
| "author": "Mehmet Kozan <mehmet.kozan@live.com>", | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=6.8.1" | ||
| } | ||
| } |
+1
-3
| # csv-config | ||
| > **A `CSV` config parser and serializer for node** | ||
| **A `CSV` config parser and serializer for node** | ||
|  | ||
| [](https://www.npmjs.org/package/csv-config) | ||
@@ -8,0 +6,0 @@ [](https://www.npmjs.org/package/csv-config) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11508
2.18%16
14.29%151
22.76%58
-3.33%