« get me outta code hell

cli, thumbs: factor out stringifyCache - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/gen-thumbs.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-21 07:26:41 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-21 07:26:41 -0400
commit35b3b4f4876804fed9542d8d04e93425a96e1fa1 (patch)
tree45bcac379e22068bc1b8065a6e633e26419bc60d /src/gen-thumbs.js
parent288715112687d33c3193ebae469aaf7d01a52b6d (diff)
cli, thumbs: factor out stringifyCache
Diffstat (limited to 'src/gen-thumbs.js')
-rw-r--r--src/gen-thumbs.js23
1 files changed, 1 insertions, 22 deletions
diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js
index 6c82761f..3ccd8ce2 100644
--- a/src/gen-thumbs.js
+++ b/src/gen-thumbs.js
@@ -163,6 +163,7 @@ import {
 import dimensionsOf from 'image-size';
 
 import CacheableObject from '#cacheable-object';
+import {stringifyCache} from '#cli';
 import {commandExists, isMain, promisifyProcess, traverse} from '#node-utils';
 import {sortByName} from '#sort';
 
@@ -346,28 +347,6 @@ export function getThumbnailsAvailableForDimensions([width, height]) {
   ];
 }
 
-function stringifyCache(cache) {
-  if (Object.keys(cache).length === 0) {
-    return `{}`;
-  }
-
-  const entries = Object.entries(cache);
-  sortByName(entries, {getName: entry => entry[0]});
-
-  return [
-    `{`,
-    entries
-      .map(([key, value]) => [JSON.stringify(key), JSON.stringify(value)])
-      .map(([key, value]) => `${key}: ${value}`)
-      .map((line, index, array) =>
-        (index < array.length - 1
-          ? `${line},`
-          : line))
-      .map(line => `  ${line}`),
-    `}`,
-  ].flat().join('\n');
-}
-
 getThumbnailsAvailableForDimensions.all =
   Object.entries(thumbnailSpec)
     .map(([name, {size}]) => [name, size])