@sean_kenny/eu4-text-file-to-json-parser-js
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -9,3 +9,4 @@ import { ValueOrNestedValue } from "./value-or-nested-value.js"; | ||
export type OutputJSONData = Record<string, ValueOrNestedValue<string>>; | ||
export declare const seperator = "\u0416\u0416\u0416\u0416\u0416\u0416\u0416\u0416\u0416\u0416"; | ||
export declare const parseEu4TextFileToJson: (input: ParseEu4TextFileToJsonInput) => Promise<ParseEu4TextFileToJsonOutput>; | ||
export {}; |
import { readFile } from "fs/promises"; | ||
import { writeValueToOutputJSONData } from "./write-value-to-output-json-data.js"; | ||
// All that really matters is that this value isn't used anywhere in the text file, we're treating it as a special character | ||
export const seperator = 'ЖЖЖЖЖЖЖЖЖЖ'; | ||
export const parseEu4TextFileToJson = async (input) => { | ||
@@ -17,3 +19,3 @@ const rawFileData = await readFile(input.inputFilePath, { encoding: 'utf-8' }); | ||
} | ||
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 = { ... }" | ||
@@ -30,11 +32,11 @@ const splitCleanedRow = cleanedRow.split('=').map((element) => element.trim()); | ||
outputJSONData, | ||
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? '.' : ''}${propertyName}`, | ||
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`, | ||
valueToPush: elements | ||
}); | ||
} | ||
else if (/^([a-zA-Z0-9_])+(\ )*=(\ )*{$/.test(cleanedRow)) { | ||
else if (/^([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]; | ||
currentKeyToPushTo = `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? '.' : ''}${propertyName}`; | ||
currentKeyToPushTo = `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`; | ||
outputJSONData = writeValueToOutputJSONData({ | ||
@@ -52,7 +54,7 @@ outputJSONData, | ||
currentKeyToPushTo = currentKeyToPushTo | ||
.split('.') | ||
.split(seperator) | ||
.slice(0, -1) | ||
.join('.'); | ||
.join(seperator); | ||
} | ||
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 = value" | ||
@@ -64,3 +66,3 @@ const splitCleanedRow = cleanedRow.split('=').map((element) => element.trim()); | ||
outputJSONData, | ||
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? '.' : ''}${propertyName}`, | ||
currentKeyToPushTo: `${currentKeyToPushTo}${currentKeyToPushTo.length > 0 ? seperator : ''}${propertyName}`, | ||
valueToPush: value.at(0) === '"' && value.at(-1) === '"' | ||
@@ -67,0 +69,0 @@ ? value.slice(1, -1) |
@@ -0,5 +1,6 @@ | ||
import { seperator } from "./parse-eu4-text-file-to-json.js"; | ||
import { valueOrNestedValueIsNestedValue, valueOrNestedValueIsNestedValueArray, valueOrNestedValueIsString, valueOrNestedValueIsStringArray } from "./value-or-nested-value.js"; | ||
export const writeValueToOutputJSONData = (input) => { | ||
const { valueToPush } = input; | ||
const splitKey = input.currentKeyToPushTo.split('.'); | ||
const splitKey = input.currentKeyToPushTo.split(seperator); | ||
if (splitKey.length === 1) { | ||
@@ -6,0 +7,0 @@ const key = splitKey[0]; |
{ | ||
"name": "@sean_kenny/eu4-text-file-to-json-parser-js", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "A library for reading text files in the format EU4 encodes it's game data in.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
15568
230