From c55f2c8c7c608918beaa2fb0cd2f26daa4c57ec6 Mon Sep 17 00:00:00 2001 From: mirtyl-wacdec Date: Wed, 30 Nov 2022 23:14:41 +0900 Subject: [PATCH] added function to paima concise consume for ease of iteration --- paima-concise/.gitignore | 4 +++- paima-concise/src/consumer.ts | 17 ++++++++++------- paima-concise/src/types.ts | 9 ++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/paima-concise/.gitignore b/paima-concise/.gitignore index be5514c33..2c12247ef 100644 --- a/paima-concise/.gitignore +++ b/paima-concise/.gitignore @@ -1,4 +1,6 @@ build/ node_modules *.tsbuildinfo -cache/ \ No newline at end of file +cache/ +*.js +*.d.ts \ No newline at end of file diff --git a/paima-concise/src/consumer.ts b/paima-concise/src/consumer.ts index 8935e9494..7fa327a5c 100644 --- a/paima-concise/src/consumer.ts +++ b/paima-concise/src/consumer.ts @@ -28,27 +28,30 @@ const initialize = (input: string, version = EncodingVersion.V1): ConciseConsume initialInput(_decompress = false): string { return this.conciseInput; }, - nextValue(): ConciseValue | '' { + nextValue(): ConciseValue | null { const [nextValue] = conciseValues.splice(0, 1); - return nextValue ?? ''; + return nextValue ?? null; }, - popValue(): ConciseValue | '' { + remainingValues(): ConciseValue[] { + return this.conciseValues + }, + popValue(): ConciseValue | null { const nextValue = conciseValues.pop(); - return nextValue ?? ''; + return nextValue ?? null; }, prefix(): string { return this.concisePrefix; }, - readValue(position: number): ConciseValue | '' { + readValue(position: number): ConciseValue | null { const index = position - 1; - return this.conciseValues[index] ?? ''; + return this.conciseValues[index] ?? null; }, stateIdentifiers(): ConciseValue[] { return this.conciseValues.filter(value => value.isStateIdentifier); }, valueCount(): number { return this.conciseValues.length; - }, + } }; }; diff --git a/paima-concise/src/types.ts b/paima-concise/src/types.ts index 292ee21d8..b79456245 100644 --- a/paima-concise/src/types.ts +++ b/paima-concise/src/types.ts @@ -38,14 +38,13 @@ export type ConciseConsumer = { conciseInput: string; concisePrefix: string; conciseValues: ConciseValue[]; - prefix: () => string; stateIdentifiers: () => ConciseValue[]; - nextValue: () => ConciseValue | ''; - - popValue: () => ConciseValue | ''; + nextValue: () => ConciseValue | null; + remainingValues: () => ConciseValue[]; + popValue: () => ConciseValue | null; initialInput: (decompress?: boolean) => UTF8String; // Positions start at 1 - readValue: (position: number) => ConciseValue | ''; + readValue: (position: number) => ConciseValue | null; valueCount: () => number; };