Skip to content

Commit ad54369

Browse files
committed
Other - Reduce package size
1 parent 9b42840 commit ad54369

File tree

6 files changed

+242
-75166
lines changed

6 files changed

+242
-75166
lines changed

convert-json.cjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// convert-json.js
2+
const fs = require('fs');
3+
const util = require('util');
4+
5+
/**
6+
* Converts a JSON file to a JS file that declares a const variable
7+
* and exports it as default, formatting as JS code.
8+
*
9+
* @example
10+
* // From the command line, run:
11+
* // $ node convert-json.cjs src/resources/worldGeo.json src/resources/worldGeo.js worldGeo
12+
*
13+
* // This will read 'src/resources/worldGeo.json', generate:
14+
* // const worldGeo = { ... };
15+
* // export default worldGeo;
16+
* // and write it to 'src/resources/worldGeo.js'
17+
*
18+
* @param {string} inputJSONPath
19+
* @param {string} outputJSPath
20+
* @param {string} [variableName='data']
21+
*/
22+
function convertJSON(inputJSONPath, outputJSPath, variableName = 'data') {
23+
const jsonContent = fs.readFileSync(inputJSONPath, 'utf-8');
24+
const parsed = JSON.parse(jsonContent);
25+
26+
const jsLikeString = util.inspect(parsed, {
27+
depth: null,
28+
compact: true,
29+
maxArrayLength: null,
30+
breakLength: 1000000,
31+
sorted: false,
32+
colors: false,
33+
quoteStyle: 'single',
34+
});
35+
36+
const jsContent =
37+
`const ${variableName} = ${jsLikeString};\n\nexport default ${variableName};\n`;
38+
39+
fs.writeFileSync(outputJSPath, jsContent, 'utf-8');
40+
}
41+
42+
if (require.main === module) {
43+
const [, , inputJSONPath, outputJSPath, variableName = 'data'] = process.argv;
44+
45+
if (!inputJSONPath || !outputJSPath) {
46+
console.log('Usage: node convert-json.js <input.json> <output.js> [variableName]');
47+
process.exit(1);
48+
}
49+
50+
convertJSON(inputJSONPath, outputJSPath, variableName);
51+
}
52+
53+
module.exports = { convertJSON };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@
110110
"vitest": "^3.1.1",
111111
"vue": "^3.5.14"
112112
}
113-
}
113+
}

src/components/vue-ui-table.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@
517517
</div>
518518
<div v-if="currentSelectionSpan.rows.length >= 2" class="chart-trend"
519519
:style="`color:${FINAL_CONFIG.style.chart.modal.color}`">
520-
<span>---</span> Trend: {{ ((chartData.progression.trend) * 100).toFixed(1) }} %
520+
<span>---</span> Trend: {{ dataLabel({
521+
v: chartData.progression.trend,
522+
s: '%',
523+
r: 1
524+
}) }}
521525
</div>
522526
</template>
523527

src/components/vue-ui-world.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup>
22
import { ref, computed, watch, nextTick } from 'vue';
3-
import WORLD_DATA from "../resources/worldGeo.json"
3+
import WORLD_DATA from "../resources/worldGeo.js"
44
import { useConfig } from '../useConfig';
55
import { applyDataLabel, convertColorToHex, convertCustomPalette, createCsvContent, createUid, darkenHexColor, dataLabel, downloadCsv, hasDeepProperty, interpolateColorHex, isFunction, lightenHexColor, palette, XMLNS } from '../lib';
66
import { useNestedProp } from '../useNestedProp';
@@ -204,7 +204,7 @@ function geoToPath(geometry) {
204204
// return pathGen(geometry);
205205
// }
206206
//----------------------------------------------------------------------------------------------
207-
207+
208208
const drawPoly = coords =>
209209
coords.map(
210210
ring => {

0 commit comments

Comments
 (0)