From 8d7b171d02e0ab4d5da7dc81eaea6c27106dbc57 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 12 Aug 2020 16:02:58 +0530 Subject: rename for consistency --- packages/taler-wallet-core/src/util/codec.ts | 76 +++++++++++++++------------- 1 file changed, 40 insertions(+), 36 deletions(-) (limited to 'packages/taler-wallet-core/src/util/codec.ts') diff --git a/packages/taler-wallet-core/src/util/codec.ts b/packages/taler-wallet-core/src/util/codec.ts index 2ce3c2cba..111abc38c 100644 --- a/packages/taler-wallet-core/src/util/codec.ts +++ b/packages/taler-wallet-core/src/util/codec.ts @@ -221,18 +221,18 @@ export class UnionCodecPreBuilder { /** * Return a builder for a codec that decodes an object with properties. */ -export function makeCodecForObject(): ObjectCodecBuilder { +export function buildCodecForObject(): ObjectCodecBuilder { return new ObjectCodecBuilder(); } -export function makeCodecForUnion(): UnionCodecPreBuilder { +export function buildCodecForUnion(): UnionCodecPreBuilder { return new UnionCodecPreBuilder(); } /** * Return a codec for a mapping from a string to values described by the inner codec. */ -export function makeCodecForMap( +export function codecForMap( innerCodec: Codec, ): Codec<{ [x: string]: T }> { if (!innerCodec) { @@ -255,7 +255,7 @@ export function makeCodecForMap( /** * Return a codec for a list, containing values described by the inner codec. */ -export function makeCodecForList(innerCodec: Codec): Codec { +export function codecForList(innerCodec: Codec): Codec { if (!innerCodec) { throw Error("inner codec must be defined"); } @@ -276,16 +276,18 @@ export function makeCodecForList(innerCodec: Codec): Codec { /** * Return a codec for a value that must be a number. */ -export const codecForNumber: Codec = { - decode(x: any, c?: Context): number { - if (typeof x === "number") { - return x; - } - throw new DecodingError( - `expected number at ${renderContext(c)} but got ${typeof x}`, - ); - }, -}; +export function codecForNumber(): Codec { + return { + decode(x: any, c?: Context): number { + if (typeof x === "number") { + return x; + } + throw new DecodingError( + `expected number at ${renderContext(c)} but got ${typeof x}`, + ); + }, + }; +} /** * Return a codec for a value that must be a number. @@ -304,30 +306,34 @@ export const codecForBoolean: Codec = { /** * Return a codec for a value that must be a string. */ -export const codecForString: Codec = { - decode(x: any, c?: Context): string { - if (typeof x === "string") { - return x; - } - throw new DecodingError( - `expected string at ${renderContext(c)} but got ${typeof x}`, - ); - }, -}; +export function codecForString(): Codec { + return { + decode(x: any, c?: Context): string { + if (typeof x === "string") { + return x; + } + throw new DecodingError( + `expected string at ${renderContext(c)} but got ${typeof x}`, + ); + }, + }; +} /** * Codec that allows any value. */ -export const codecForAny: Codec = { - decode(x: any, c?: Context): any { - return x; - }, -}; +export function codecForAny(): Codec { + return { + decode(x: any, c?: Context): any { + return x; + }, + }; +} /** * Return a codec for a value that must be a string. */ -export function makeCodecForConstString(s: V): Codec { +export function codecForConstString(s: V): Codec { return { decode(x: any, c?: Context): V { if (x === s) { @@ -345,7 +351,7 @@ export function makeCodecForConstString(s: V): Codec { /** * Return a codec for a boolean true constant. */ -export function makeCodecForConstTrue(): Codec { +export function codecForConstTrue(): Codec { return { decode(x: any, c?: Context): true { if (x === true) { @@ -361,7 +367,7 @@ export function makeCodecForConstTrue(): Codec { /** * Return a codec for a boolean true constant. */ -export function makeCodecForConstFalse(): Codec { +export function codecForConstFalse(): Codec { return { decode(x: any, c?: Context): false { if (x === false) { @@ -377,7 +383,7 @@ export function makeCodecForConstFalse(): Codec { /** * Return a codec for a value that must be a constant number. */ -export function makeCodecForConstNumber(n: V): Codec { +export function codecForConstNumber(n: V): Codec { return { decode(x: any, c?: Context): V { if (x === n) { @@ -392,9 +398,7 @@ export function makeCodecForConstNumber(n: V): Codec { }; } -export function makeCodecOptional( - innerCodec: Codec, -): Codec { +export function codecOptional(innerCodec: Codec): Codec { return { decode(x: any, c?: Context): V | undefined { if (x === undefined || x === null) { -- cgit v1.2.3