« get me outta code hell

data: artist: custom util.inspect (show alias info) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/artist.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 10:47:33 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:02:22 -0400
commit78fa1765e28152b94062c43776b2de937d0ea08f (patch)
treef17bfc52ee951f396c644218a91a4ef8f06b17b2 /src/data/things/artist.js
parent0ff3e151785a6bc016c29973c38a773efc4a7ce1 (diff)
data: artist: custom util.inspect (show alias info)
Diffstat (limited to 'src/data/things/artist.js')
-rw-r--r--src/data/things/artist.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/data/things/artist.js b/src/data/things/artist.js
index a3766f0..5e12f38 100644
--- a/src/data/things/artist.js
+++ b/src/data/things/artist.js
@@ -1,5 +1,9 @@
 export const ARTIST_DATA_FILE = 'artists.yaml';
 
+import {inspect} from 'node:util';
+
+import CacheableObject from '#cacheable-object';
+import {colors} from '#cli';
 import {input} from '#composite';
 import find from '#find';
 import {unique} from '#sugar';
@@ -294,4 +298,25 @@ export class Artist extends Thing {
       sortAlphabetically(artistAliasData);
     },
   });
+
+  [inspect.custom]() {
+    const parts = [];
+
+    parts.push(Thing.prototype[inspect.custom].apply(this));
+
+    if (CacheableObject.getUpdateValue(this, 'isAlias')) {
+      parts.unshift(`${colors.yellow('[alias]')} `);
+
+      let aliasedArtist;
+      try {
+        aliasedArtist = this.aliasedArtist.name;
+      } catch (_error) {
+        aliasedArtist = CacheableObject.getUpdateValue(this, 'aliasedArtist');
+      }
+
+      parts.push(` ${colors.yellow(`[of ${aliasedArtist}]`)}`);
+    }
+
+    return parts.join('');
+  }
 }