From d3626f8a4392e3c3dce49a4ececa8109f8940a60 Mon Sep 17 00:00:00 2001 From: wes-smith Date: Thu, 11 Jul 2024 23:12:25 -0400 Subject: [PATCH] Improve formatting and style. --- lib/Compressor.js | 14 +++++--------- lib/Decompressor.js | 13 +++++-------- lib/Transformer.js | 2 -- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/Compressor.js b/lib/Compressor.js index 12d0164b..80fa7d70 100644 --- a/lib/Compressor.js +++ b/lib/Compressor.js @@ -192,18 +192,15 @@ export class Compressor extends Transformer { } _transformTypedValue({entries, termType, value, termInfo}) { - let encoder; - - encoder = TypedLiteralEncoder.createEncoder({ + const encoder = TypedLiteralEncoder.createEncoder({ value, transformer: this, termType + }) || TYPE_ENCODERS.get(termType)?.createEncoder({ + value, + transformer: this, + termInfo }); - if(!encoder) { - const EncoderClass = TYPE_ENCODERS.get(termType); - encoder = EncoderClass && EncoderClass.createEncoder( - {value, transformer: this, termInfo}); - } if(encoder) { entries.push(encoder); return true; @@ -240,7 +237,6 @@ export class Compressor extends Transformer { const {termId, plural} = termInfo; transformMap.set(termId, plural ? entries : entries[0]); } - } /** diff --git a/lib/Decompressor.js b/lib/Decompressor.js index a5b41f29..730bb3ff 100644 --- a/lib/Decompressor.js +++ b/lib/Decompressor.js @@ -70,7 +70,7 @@ export class Decompressor extends Transformer { this.reverseStringTable = _reverseMap(stringTable); this.reverseUrlSchemeTable = _reverseMap(urlSchemeTable); - //typed literal table is map of maps, process inner map not outer + // typed literal table is map of maps, process inner map not outer this.reverseTypedLiteralTable = new Map(); if(typedLiteralTable) { for(const [k, map] of typedLiteralTable) { @@ -259,17 +259,14 @@ export class Decompressor extends Transformer { } _transformTypedValue({entries, termType, value}) { - let decoder; - decoder = TypedLiteralDecoder.createDecoder({ + const decoder = TypedLiteralDecoder.createDecoder({ value, transformer: this, termType + }) || TYPE_DECODERS.get(termType)?.createDecoder({ + value, + transformer: this }); - if(!decoder) { - const DecoderClass = TYPE_DECODERS.get(termType); - decoder = DecoderClass && DecoderClass.createDecoder( - {value, transformer: this}); - } if(decoder) { entries.push(decoder.decode({value})); diff --git a/lib/Transformer.js b/lib/Transformer.js index 34d4c01a..ab9aed3e 100644 --- a/lib/Transformer.js +++ b/lib/Transformer.js @@ -474,10 +474,8 @@ export class Transformer { } _getIdForTerm({term, plural}) { - // check term to id table const id = this.termToId.get(term); - if(id === undefined) { /* throw new CborldError(