From cc3f618375761122e3921aea74d1f388627a993f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 18 Dec 2023 11:47:21 +0100 Subject: [PATCH] feat(jslib): implement toString for UpObject also minor stylistic refactor --- tools/upend_js/index.ts | 18 ++++++++++++------ tools/upend_js/package.json | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/upend_js/index.ts b/tools/upend_js/index.ts index 8be1915..429a8ba 100644 --- a/tools/upend_js/index.ts +++ b/tools/upend_js/index.ts @@ -1,4 +1,5 @@ import type { IEntry, IValue, ListingResult } from "./types"; + export { UpEndApi } from "./api"; export { Query } from "./query"; @@ -8,7 +9,7 @@ export class UpListing { constructor(listing: ListingResult) { this.entries = Object.entries(listing).map( - (lr) => new UpEntry(...lr, this) + (lr) => new UpEntry(...lr, this), ); } @@ -16,7 +17,7 @@ export class UpListing { const allEntities = new Set(this.entries.map((e) => e.entity)); const result: { [key: string]: UpObject } = {}; Array.from(allEntities).forEach( - (entity) => (result[entity] = new UpObject(entity, this)) + (entity) => (result[entity] = new UpObject(entity, this)), ); return result; } @@ -56,13 +57,13 @@ export class UpObject { public get attributes() { return (this.listing?.entries || []).filter( - (e) => e.entity === this.address + (e) => e.entity === this.address, ); } public get backlinks() { return (this.listing?.entries || []).filter( - (e) => e.value.c === this.address + (e) => e.value.c === this.address, ); } @@ -98,8 +99,13 @@ export class UpObject { } public identify(): string[] { - const lblValues = (this.attr["LBL"] || []).map((e) => String(e.value.c)); - return lblValues; + return (this.attr["LBL"] || []).map((e) => String(e.value.c)); + } + + public toString(): string { + return [`@${this.address}`, this.identify().join(", ")] + .filter(Boolean) + .join(" | "); } public asDict() { diff --git a/tools/upend_js/package.json b/tools/upend_js/package.json index e78964f..b97de58 100644 --- a/tools/upend_js/package.json +++ b/tools/upend_js/package.json @@ -1,6 +1,6 @@ { "name": "@upnd/upend", - "version": "0.2.1", + "version": "0.2.2", "description": "Client library to interact with the UpEnd system.", "scripts": { "build": "tsc --build --verbose",