Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sean_kenny/eu4-text-file-to-json-parser-js

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sean_kenny/eu4-text-file-to-json-parser-js - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

71

build/parse-eu4-text-file-to-json.js

@@ -19,17 +19,62 @@ import { readFile } from "fs/promises";

}
else if (/^([a-zA-Z0-9_\.-])+(\ )*=(\ )*{([a-zA-Z0-9_\ /".\-'])*}$/.test(cleanedRow)) {
else if (/^([a-zA-Z0-9_\.-])+(\ )*=(\ )*{([a-zA-Z0-9_\ /".\-='])*}$/.test(cleanedRow)) {
// This is in the format "property_name = { ... }"
const splitCleanedRow = cleanedRow.split('=').map((element) => element.trim());
const propertyName = splitCleanedRow[0];
const elements = splitCleanedRow[1]
.slice(1, -1)
.split("\"")
.flatMap((element, index) => index % 2 === 0 ? element.split(" ") : [element])
.map((element) => element.trim())
.filter((element) => element !== '');
outputJSONData = writeValueToOutputJSONData({
outputJSONData,
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`,
valueToPush: elements
});
const propertyName = splitCleanedRow[0].trim();
const propertyValue = splitCleanedRow.slice(1).join('=').trim();
if (/^({)?(\ )*([a-zA-Z0-9_\.-])+(\ )*=(\ )*(.)*$/.test(propertyValue)) {
// This is in the format "property_name = { inner_property_name = 123456 }" OR
// This is in the format "property_name = { inner_property_name = { inner_inner_property_name = 1000 }}"
// In that second example, we need to have some kind of loop here to keep digging deeper into the since inner_inner_property_name could
// also have a json object as a key.
currentKeyToPushTo = `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`;
let currentKeyValuePairToEvaluate = propertyValue;
let currentKeyToEvaluate = currentKeyValuePairToEvaluate
.split('=')[0]
.trim()
.replace(/^{/, '')
.trim();
let currentValueToEvaluate = currentKeyValuePairToEvaluate
.split('=')
.slice(1)
.join('=')
.trim()
.replace(/}$/, '')
.trim();
while (/^{(.)*}$/.test(currentValueToEvaluate)) {
currentKeyToPushTo = `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${currentKeyToEvaluate}`;
currentKeyValuePairToEvaluate = currentValueToEvaluate;
currentKeyToEvaluate = currentKeyValuePairToEvaluate
.split('=')[0]
.trim()
.replace(/^{/, '')
.trim();
currentValueToEvaluate = currentKeyValuePairToEvaluate
.split('=')
.slice(1)
.join('=')
.trim()
.replace(/}$/, '')
.trim();
}
outputJSONData = writeValueToOutputJSONData({
outputJSONData,
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${currentKeyToEvaluate}`,
valueToPush: currentValueToEvaluate
});
}
else {
// This is in the format "property_name = { 1 2 3 4 }"
const elements = propertyValue
.slice(1, -1)
.split("\"")
.flatMap((element, index) => index % 2 === 0 ? element.split(" ") : [element])
.map((element) => element.trim())
.filter((element) => element !== '');
outputJSONData = writeValueToOutputJSONData({
outputJSONData,
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`,
valueToPush: elements
});
}
}

@@ -36,0 +81,0 @@ else if (/^([a-zA-Z0-9_\.-])+(\ )*=(\ )*{$/.test(cleanedRow)) {

2

package.json
{
"name": "@sean_kenny/eu4-text-file-to-json-parser-js",
"version": "0.1.8",
"version": "0.1.9",
"description": "A library for reading text files in the format EU4 encodes it's game data in.",

@@ -5,0 +5,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc