easy-ini
Advanced tools
Comparing version 1.1.0 to 1.1.1
42
index.js
@@ -41,5 +41,4 @@ const _EMPTY_LINE = 0, | ||
} | ||
_findType(line) {for (let t in this._types) {if (this._types[t](line)) {return parseInt(t)}}} | ||
_findType(line) {for (let t in this._types) {if (this._types[t](line)) {return t}}} | ||
_addByType(obj, type, key = '', val = '') { | ||
@@ -92,2 +91,15 @@ if (type == _SECTION) {obj.push({name: key, content: []})} else { | ||
createSimpleObject(includeTypes = [4]) { | ||
const result = {} | ||
for (const sec of this.iniData) { | ||
let ref = includeTypes.includes(3) && sec.name != this._defSecName ? result[sec.name] = {} : result | ||
for (const line of sec.content) { | ||
if(includeTypes.includes(line.type)) { | ||
ref[line.key] = line.val | ||
} | ||
} | ||
} | ||
return result | ||
} | ||
getKeyIfExists(inputKey) { | ||
@@ -265,3 +277,3 @@ for (const sec of this.iniData) { | ||
solveSelfReferences(prefix, suffix) { | ||
const refReg = new RegExp(`${prefix}(.*?)${suffix}`) | ||
const refReg = new RegExp(`${prefix}(.*?)${suffix}`, ['g']) | ||
let result = false | ||
@@ -272,7 +284,9 @@ for (const sec of this.iniData) { | ||
const matchRes = line.val.match(refReg) | ||
if (matchRes && matchRes.length >= 2) { | ||
const suspect = this.getKeyIfExists(matchRes[1]) | ||
if (suspect && suspect.val) { | ||
line.val = line.val.replace(matchRes[0], suspect.val) | ||
result = true | ||
if (matchRes && matchRes.length > 0) { | ||
for (const match of matchRes) { | ||
const suspect = this.getKeyIfExists(match.replace(prefix, '').replace(suffix, '')) | ||
if (suspect && suspect.val) { | ||
line.val = line.val.replace(match, suspect.val) | ||
result = true | ||
} | ||
} | ||
@@ -282,7 +296,9 @@ } | ||
const matchRes = line.key.match(refReg) | ||
if (matchRes && matchRes.length >= 2) { | ||
const suspect = this.getKeyIfExists(matchRes[1]) | ||
if (suspect && suspect.val) { | ||
line.key = line.key.replace(matchRes[0], suspect.val) | ||
result = true | ||
if (matchRes && matchRes.length > 0) { | ||
for (const match of matchRes) { | ||
const suspect = this.getKeyIfExists(match.replace(prefix, '').replace(suffix, '')) | ||
if (suspect && suspect.val) { | ||
line.key = line.key.replace(match, suspect.val) | ||
result = true | ||
} | ||
} | ||
@@ -289,0 +305,0 @@ } |
{ | ||
"name": "easy-ini", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "manage ini files content", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,2 +66,13 @@ | ||
**```createSimpleObject```()** | ||
*Make an Object including only they types that are specified* | ||
- includeTypes = \[4\] | ||
[supported types](#good-to-know) | ||
```javascript | ||
// by passing [3,4] , will also create a level for sections | ||
const newINIString = myINI.createSimpleObject() | ||
``` | ||
<br> | ||
**```getKeyIfExists```()** | ||
@@ -68,0 +79,0 @@ *Get line object by referance {type, key, val}* |
92
test.js
const INI = require('./index') | ||
const myINI = new INI(`[INCLUDES]\n#INCLUDE=config.ini\n\n\n[ok]\nthing=thang\ncool=#thing%\n[WOW]\nname=gal\nthing=111\nOUT_PE=\\Release\\%INST_NAME%_Downloader_v%VI_FILE_VER%_%__cdate%_unsigned.exe\n`) | ||
console.log(myINI.createINIString()) | ||
console.log('111111111122222222233333334444444') | ||
const myINI2 = new INI(`[INCLUDES]\n#INCLUDE=config.ini\n\nxzczxcxzc\n[ok]\nthing=thang\ncool=#thing%\n[WOW]\nname=gal\nthing=111\nOUT_PE=\\Release\\%INST_NAME%_Downloader_v%VI_FILE_VER%_%__cdate%_unsigned.exe\n`) | ||
myINI.mergeWith(myINI2, true) | ||
console.log(myINI.createINIString()) | ||
const path = require('path') | ||
const fs = require('fs') | ||
const mainINI = new INI(fs.readFileSync('./main.ini', 'utf8')) | ||
while (true) { | ||
mainINI.solveDuplicates(false) | ||
mainINI.solveSelfReferences('%','%') | ||
mainINI.findAndReplace('<!appmakerroot!>','Platform\\',true) | ||
let includes = mainINI.getLinesByMatch("#INCLUDE") | ||
mainINI.removeLineByMatch('#INCLUDE', true) | ||
if (includes.length == 0) { break } | ||
for (const include of includes.reverse()) { | ||
const includePath = include.split('=')[1] | ||
const candidate = path.resolve(...includePath.split('\\')) | ||
let fileContent = fs.readFileSync(candidate, { encoding: 'utf8' }) | ||
const tempINI = new INI(fileContent) | ||
mainINI.mergeWith(tempINI, true) | ||
} | ||
} | ||
const simple = mainINI.createSimpleObject() | ||
console.log('simple: ', simple); | ||
// const myINI = new INI(`[INCLUDES]\n#INCLUDE=config.ini\n\n\n[ok]\nthing=thang\ncool=#thing%\n[WOW]\nname=gal\nthing=111\nOUT_PE=\\Release\\%INST_NAME%_Downloader_v%VI_FILE_VER%_%__cdate%_unsigned.exe\n`) | ||
// console.log(myINI.createINIString()) | ||
// console.log('111111111122222222233333334444444') | ||
// const myINI2 = new INI(`[INCLUDES]\n#INCLUDE=config.ini\n\nxzczxcxzc\n[ok]\nthing=thang\ncool=#thing%\n[WOW]\nname=gal\nthing=111\nOUT_PE=\\Release\\%INST_NAME%_Downloader_v%VI_FILE_VER%_%__cdate%_unsigned.exe\n`) | ||
// myINI.mergeWith(myINI2, true) | ||
// console.log(myINI.createINIString()) | ||
/* super_secret_config.ini: | ||
something=whatever | ||
say=ha | ||
dude=%say%%say%%say% %relax% | ||
relax=%something% */ | ||
console.log(myINI.getKeyIfExists('OUT_PE')) | ||
console.log(myINI.findAndRemoveKeyIfExists('OUT_PE')) | ||
console.log(myINI.getKeyIfExists('OUT_PE')) | ||
myINI.findAndRemoveSectionIfExists(['[INCLUDES]']) | ||
myINI.putStringInSection('cool=not') | ||
myINI.putStringInSection('#cool=not') | ||
myINI.putStringInSection('something=whatev1234er','[test]') | ||
myINI.putStringInSection('say=ha','[test]') | ||
myINI.putStringInSection('dude=%say%%say%%say% %relax%','[test]') | ||
myINI.putStringInSection('#dude=%say%%say%%say% %relax%','[test]') | ||
myINI.putStringInSection('relax=%something%','[test]') | ||
myINI.putStringInSection('need=123456789','[CERT SYS]') | ||
myINI.putStringInSection(';cool=not','[CERT SYS]') | ||
myINI.putStringInSection('#c=not','[CERT SYS]') | ||
myINI.putStringInSection('shit=%fuck%','[CERT SYS]') | ||
myINI.putStringInSection('fuck=%need%_%need%','[CERT SYS]') | ||
myINI.findAndReplace('1234', 'XXX', true) | ||
// console.log(myINI.getLinesByMatch('fu')) | ||
// console.log(myINI.removeLineByMatch('fu',true)) | ||
console.log(myINI.solveDuplicates()) | ||
console.log('111111111122222222233333334444444') | ||
myINI.solveSelfReferences('%','%') | ||
console.log(myINI.createINIString({cleanBreakComment:true, cleanEmptyLines:true, noEmptySections:true, shouldTrim:true, shouldFix:true})) | ||
// myINI.findAndRemoveSectionIfExists('SYS', false) | ||
// /* super_secret_config.ini: | ||
// something=whatever | ||
// say=ha | ||
// dude=%say%%say%%say% %relax% | ||
// relax=%something% */ | ||
// console.log(myINI.getKeyIfExists('OUT_PE')) | ||
// console.log(myINI.findAndRemoveKeyIfExists('OUT_PE')) | ||
// console.log(myINI.getKeyIfExists('OUT_PE')) | ||
// myINI.findAndRemoveSectionIfExists(['[INCLUDES]']) | ||
// myINI.putStringInSection('cool=not') | ||
// myINI.putStringInSection('#cool=not') | ||
// myINI.putStringInSection('something=whatev1234er','[test]') | ||
// myINI.putStringInSection('say=ha','[test]') | ||
// myINI.putStringInSection('dude=%say%%say%%say% %relax%','[test]') | ||
// myINI.putStringInSection('#dude=%say%%say%%say% %relax%','[test]') | ||
// myINI.putStringInSection('relax=%something%','[test]') | ||
// myINI.putStringInSection('need=123456789','[CERT SYS]') | ||
// myINI.putStringInSection(';cool=not','[CERT SYS]') | ||
// myINI.putStringInSection('#c=not','[CERT SYS]') | ||
// myINI.putStringInSection('shit=%fuck%','[CERT SYS]') | ||
// myINI.putStringInSection('fuck=%need%_%need%','[CERT SYS]') | ||
// myINI.findAndReplace('1234', 'XXX', true) | ||
// // console.log(myINI.getLinesByMatch('fu')) | ||
// // console.log(myINI.removeLineByMatch('fu',true)) | ||
// console.log(myINI.solveDuplicates()) | ||
// console.log('111111111122222222233333334444444') | ||
// myINI.solveSelfReferences('%','%') | ||
// const simple = myINI.createSimpleObject() | ||
// console.log('simple: ', simple); | ||
// console.log(myINI.createINIString({cleanBreakComment:true, cleanEmptyLines:true, noEmptySections:true, shouldTrim:true, shouldFix:true})) | ||
// // myINI.findAndRemoveSectionIfExists('SYS', false) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
60126
387
289
1