From 78fa1765e28152b94062c43776b2de937d0ea08f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 30 Jan 2024 10:47:33 -0400 Subject: data: artist: custom util.inspect (show alias info) --- src/data/things/artist.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/data/things/artist.js b/src/data/things/artist.js index a3766f00..5e12f389 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(''); + } } -- cgit 1.3.0-6-gf8a5