@solana/codecs-strings 2.0.0-experimental.85b7dfe → 2.0.0-experimental.8618508

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,23 +21,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
21
21
  throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
22
22
  }
23
23
  }
24
- var mergeBytes = (byteArrays) => {
25
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
26
- if (nonEmptyByteArrays.length === 0) {
27
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
28
- }
29
- if (nonEmptyByteArrays.length === 1) {
30
- return nonEmptyByteArrays[0];
31
- }
32
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
33
- const result = new Uint8Array(totalLength);
34
- let offset = 0;
35
- nonEmptyByteArrays.forEach((arr) => {
36
- result.set(arr, offset);
37
- offset += arr.length;
38
- });
39
- return result;
40
- };
41
24
  var padBytes = (bytes, length) => {
42
25
  if (bytes.length >= length)
43
26
  return bytes;
@@ -46,99 +29,113 @@ this.globalThis.solanaWeb3 = (function (exports) {
46
29
  return paddedBytes;
47
30
  };
48
31
  var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
49
- function combineCodec(encoder, decoder, description) {
50
- if (encoder.fixedSize !== decoder.fixedSize) {
32
+ function getEncodedSize(value, encoder) {
33
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
34
+ }
35
+ function createEncoder(encoder) {
36
+ return Object.freeze({
37
+ ...encoder,
38
+ encode: (value) => {
39
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
40
+ encoder.write(value, bytes, 0);
41
+ return bytes;
42
+ }
43
+ });
44
+ }
45
+ function createDecoder(decoder) {
46
+ return Object.freeze({
47
+ ...decoder,
48
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
49
+ });
50
+ }
51
+ function isFixedSize(codec) {
52
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
53
+ }
54
+ function combineCodec(encoder, decoder) {
55
+ if (isFixedSize(encoder) !== isFixedSize(decoder)) {
56
+ throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
57
+ }
58
+ if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
51
59
  throw new Error(
52
60
  `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
53
61
  );
54
62
  }
55
- if (encoder.maxSize !== decoder.maxSize) {
63
+ if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
56
64
  throw new Error(
57
65
  `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
58
66
  );
59
67
  }
60
- if (description === void 0 && encoder.description !== decoder.description) {
61
- throw new Error(
62
- `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
63
- );
64
- }
65
68
  return {
69
+ ...decoder,
70
+ ...encoder,
66
71
  decode: decoder.decode,
67
- description: description != null ? description : encoder.description,
68
72
  encode: encoder.encode,
69
- fixedSize: encoder.fixedSize,
70
- maxSize: encoder.maxSize
73
+ read: decoder.read,
74
+ write: encoder.write
71
75
  };
72
76
  }
73
- function fixCodecHelper(data, fixedBytes, description) {
74
- return {
75
- description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
77
+ function fixEncoder(encoder, fixedBytes) {
78
+ return createEncoder({
76
79
  fixedSize: fixedBytes,
77
- maxSize: fixedBytes
78
- };
79
- }
80
- function fixEncoder(encoder, fixedBytes, description) {
81
- return {
82
- ...fixCodecHelper(encoder, fixedBytes, description),
83
- encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
84
- };
80
+ write: (value, bytes, offset) => {
81
+ const variableByteArray = encoder.encode(value);
82
+ const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
83
+ bytes.set(fixedByteArray, offset);
84
+ return offset + fixedBytes;
85
+ }
86
+ });
85
87
  }
86
- function fixDecoder(decoder, fixedBytes, description) {
87
- return {
88
- ...fixCodecHelper(decoder, fixedBytes, description),
89
- decode: (bytes, offset = 0) => {
88
+ function fixDecoder(decoder, fixedBytes) {
89
+ return createDecoder({
90
+ fixedSize: fixedBytes,
91
+ read: (bytes, offset) => {
90
92
  assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
91
93
  if (offset > 0 || bytes.length > fixedBytes) {
92
94
  bytes = bytes.slice(offset, offset + fixedBytes);
93
95
  }
94
- if (decoder.fixedSize !== null) {
96
+ if (isFixedSize(decoder)) {
95
97
  bytes = fixBytes(bytes, decoder.fixedSize);
96
98
  }
97
- const [value] = decoder.decode(bytes, 0);
99
+ const [value] = decoder.read(bytes, 0);
98
100
  return [value, offset + fixedBytes];
99
101
  }
100
- };
102
+ });
101
103
  }
102
104
 
103
105
  // src/baseX.ts
104
106
  var getBaseXEncoder = (alphabet4) => {
105
- const base = alphabet4.length;
106
- const baseBigInt = BigInt(base);
107
- return {
108
- description: `base${base}`,
109
- encode(value) {
107
+ return createEncoder({
108
+ getSizeFromValue: (value) => {
109
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
110
+ if (tailChars === "")
111
+ return value.length;
112
+ const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
113
+ return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
114
+ },
115
+ write(value, bytes, offset) {
110
116
  assertValidBaseString(alphabet4, value);
111
117
  if (value === "")
112
- return new Uint8Array();
113
- const chars = [...value];
114
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
115
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
116
- const leadingZeroes = Array(trailIndex).fill(0);
117
- if (trailIndex === chars.length)
118
- return Uint8Array.from(leadingZeroes);
119
- const tailChars = chars.slice(trailIndex);
120
- let base10Number = 0n;
121
- let baseXPower = 1n;
122
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
123
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
124
- baseXPower *= baseBigInt;
118
+ return offset;
119
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
120
+ if (tailChars === "") {
121
+ bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
122
+ return offset + leadingZeroes.length;
125
123
  }
124
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
126
125
  const tailBytes = [];
127
126
  while (base10Number > 0n) {
128
127
  tailBytes.unshift(Number(base10Number % 256n));
129
128
  base10Number /= 256n;
130
129
  }
131
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
132
- },
133
- fixedSize: null,
134
- maxSize: null
135
- };
130
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
131
+ bytes.set(bytesToAdd, offset);
132
+ return offset + bytesToAdd.length;
133
+ }
134
+ });
136
135
  };
137
136
  var getBaseXDecoder = (alphabet4) => {
138
- const base = alphabet4.length;
139
- const baseBigInt = BigInt(base);
140
- return {
141
- decode(rawBytes, offset = 0) {
137
+ return createDecoder({
138
+ read(rawBytes, offset) {
142
139
  const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
143
140
  if (bytes.length === 0)
144
141
  return ["", 0];
@@ -147,20 +144,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
147
144
  const leadingZeroes = alphabet4[0].repeat(trailIndex);
148
145
  if (trailIndex === bytes.length)
149
146
  return [leadingZeroes, rawBytes.length];
150
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
151
- const tailChars = [];
152
- while (base10Number > 0n) {
153
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
154
- base10Number /= baseBigInt;
155
- }
156
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
157
- },
158
- description: `base${base}`,
159
- fixedSize: null,
160
- maxSize: null
161
- };
147
+ const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
148
+ const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
149
+ return [leadingZeroes + tailChars, rawBytes.length];
150
+ }
151
+ });
162
152
  };
163
153
  var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
154
+ function partitionLeadingZeroes(value, zeroCharacter) {
155
+ const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
156
+ return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
157
+ }
158
+ function getBigIntFromBaseX(value, alphabet4) {
159
+ const base = BigInt(alphabet4.length);
160
+ return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
161
+ }
162
+ function getBaseXFromBigInt(value, alphabet4) {
163
+ const base = BigInt(alphabet4.length);
164
+ const tailChars = [];
165
+ while (value > 0n) {
166
+ tailChars.unshift(alphabet4[Number(value % base)]);
167
+ value /= base;
168
+ }
169
+ return tailChars.join("");
170
+ }
164
171
 
165
172
  // src/base10.ts
166
173
  var alphabet = "0123456789";
@@ -169,25 +176,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
169
176
  var getBase10Codec = () => getBaseXCodec(alphabet);
170
177
 
171
178
  // src/base16.ts
172
- var getBase16Encoder = () => ({
173
- description: "base16",
174
- encode(value) {
179
+ var getBase16Encoder = () => createEncoder({
180
+ getSizeFromValue: (value) => Math.ceil(value.length / 2),
181
+ write(value, bytes, offset) {
175
182
  const lowercaseValue = value.toLowerCase();
176
183
  assertValidBaseString("0123456789abcdef", lowercaseValue, value);
177
184
  const matches = lowercaseValue.match(/.{1,2}/g);
178
- return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
179
- },
180
- fixedSize: null,
181
- maxSize: null
185
+ const hexBytes = matches ? matches.map((byte) => parseInt(byte, 16)) : [];
186
+ bytes.set(hexBytes, offset);
187
+ return hexBytes.length + offset;
188
+ }
182
189
  });
183
- var getBase16Decoder = () => ({
184
- decode(bytes, offset = 0) {
190
+ var getBase16Decoder = () => createDecoder({
191
+ read(bytes, offset) {
185
192
  const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
186
193
  return [value, bytes.length];
187
- },
188
- description: "base16",
189
- fixedSize: null,
190
- maxSize: null
194
+ }
191
195
  });
192
196
  var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());
193
197
 
@@ -198,29 +202,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
198
202
  var getBase58Codec = () => getBaseXCodec(alphabet2);
199
203
 
200
204
  // src/baseX-reslice.ts
201
- var getBaseXResliceEncoder = (alphabet4, bits) => ({
202
- description: `base${alphabet4.length}`,
203
- encode(value) {
205
+ var getBaseXResliceEncoder = (alphabet4, bits) => createEncoder({
206
+ getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
207
+ write(value, bytes, offset) {
204
208
  assertValidBaseString(alphabet4, value);
205
209
  if (value === "")
206
- return new Uint8Array();
210
+ return offset;
207
211
  const charIndices = [...value].map((c) => alphabet4.indexOf(c));
208
- return new Uint8Array(reslice(charIndices, bits, 8, false));
209
- },
210
- fixedSize: null,
211
- maxSize: null
212
+ const reslicedBytes = reslice(charIndices, bits, 8, false);
213
+ bytes.set(reslicedBytes, offset);
214
+ return reslicedBytes.length + offset;
215
+ }
212
216
  });
213
- var getBaseXResliceDecoder = (alphabet4, bits) => ({
214
- decode(rawBytes, offset = 0) {
217
+ var getBaseXResliceDecoder = (alphabet4, bits) => createDecoder({
218
+ read(rawBytes, offset = 0) {
215
219
  const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
216
220
  if (bytes.length === 0)
217
221
  return ["", rawBytes.length];
218
222
  const charIndices = reslice([...bytes], 8, bits, true);
219
223
  return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
220
- },
221
- description: `base${alphabet4.length}`,
222
- fixedSize: null,
223
- maxSize: null
224
+ }
224
225
  });
225
226
  var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));
226
227
  function reslice(input, inputBits, outputBits, useRemainder) {
@@ -243,33 +244,35 @@ this.globalThis.solanaWeb3 = (function (exports) {
243
244
  }
244
245
  var getBase64Encoder = () => {
245
246
  {
246
- return {
247
- description: `base64`,
248
- encode(value) {
247
+ return createEncoder({
248
+ getSizeFromValue: (value) => {
249
249
  try {
250
- const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
251
- return new Uint8Array(bytes);
250
+ return atob(value).length;
252
251
  } catch (e2) {
253
252
  throw new Error(`Expected a string of base 64, got [${value}].`);
254
253
  }
255
254
  },
256
- fixedSize: null,
257
- maxSize: null
258
- };
255
+ write(value, bytes, offset) {
256
+ try {
257
+ const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
258
+ bytes.set(bytesToAdd, offset);
259
+ return bytesToAdd.length + offset;
260
+ } catch (e2) {
261
+ throw new Error(`Expected a string of base 64, got [${value}].`);
262
+ }
263
+ }
264
+ });
259
265
  }
260
266
  };
261
267
  var getBase64Decoder = () => {
262
268
  {
263
- return {
264
- decode(bytes, offset = 0) {
269
+ return createDecoder({
270
+ read(bytes, offset = 0) {
265
271
  const slice = bytes.slice(offset);
266
272
  const value = btoa(String.fromCharCode(...slice));
267
273
  return [value, bytes.length];
268
- },
269
- description: `base64`,
270
- fixedSize: null,
271
- maxSize: null
272
- };
274
+ }
275
+ });
273
276
  }
274
277
  };
275
278
  var getBase64Codec = () => combineCodec(getBase64Encoder(), getBase64Decoder());
@@ -289,50 +292,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
289
292
  );
290
293
  }
291
294
  }
292
- function sharedNumberFactory(input) {
293
- var _a;
294
- let littleEndian;
295
- let defaultDescription = input.name;
296
- if (input.size > 1) {
297
- littleEndian = !("endian" in input.config) || input.config.endian === 0;
298
- defaultDescription += littleEndian ? "(le)" : "(be)";
299
- }
300
- return {
301
- description: (_a = input.config.description) != null ? _a : defaultDescription,
302
- fixedSize: input.size,
303
- littleEndian,
304
- maxSize: input.size
305
- };
295
+ function isLittleEndian(config) {
296
+ return (config == null ? void 0 : config.endian) === 1 ? false : true;
306
297
  }
307
298
  function numberEncoderFactory(input) {
308
- const codecData = sharedNumberFactory(input);
309
- return {
310
- description: codecData.description,
311
- encode(value) {
299
+ return createEncoder({
300
+ fixedSize: input.size,
301
+ write(value, bytes, offset) {
312
302
  if (input.range) {
313
303
  assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
314
304
  }
315
305
  const arrayBuffer = new ArrayBuffer(input.size);
316
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
317
- return new Uint8Array(arrayBuffer);
318
- },
319
- fixedSize: codecData.fixedSize,
320
- maxSize: codecData.maxSize
321
- };
306
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
307
+ bytes.set(new Uint8Array(arrayBuffer), offset);
308
+ return offset + input.size;
309
+ }
310
+ });
322
311
  }
323
312
  function numberDecoderFactory(input) {
324
- const codecData = sharedNumberFactory(input);
325
- return {
326
- decode(bytes, offset = 0) {
327
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
328
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
313
+ return createDecoder({
314
+ fixedSize: input.size,
315
+ read(bytes, offset = 0) {
316
+ assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
317
+ assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
329
318
  const view = new DataView(toArrayBuffer(bytes, offset, input.size));
330
- return [input.get(view, codecData.littleEndian), offset + input.size];
331
- },
332
- description: codecData.description,
333
- fixedSize: codecData.fixedSize,
334
- maxSize: codecData.maxSize
335
- };
319
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
320
+ }
321
+ });
336
322
  }
337
323
  function toArrayBuffer(bytes, offset, length) {
338
324
  const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
@@ -360,81 +346,75 @@ this.globalThis.solanaWeb3 = (function (exports) {
360
346
  // src/utf8.ts
361
347
  var getUtf8Encoder = () => {
362
348
  let textEncoder;
363
- return {
364
- description: "utf8",
365
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
366
- fixedSize: null,
367
- maxSize: null
368
- };
349
+ return createEncoder({
350
+ getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
351
+ write: (value, bytes, offset) => {
352
+ const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
353
+ bytes.set(bytesToAdd, offset);
354
+ return offset + bytesToAdd.length;
355
+ }
356
+ });
369
357
  };
370
358
  var getUtf8Decoder = () => {
371
359
  let textDecoder;
372
- return {
373
- decode(bytes, offset = 0) {
360
+ return createDecoder({
361
+ read(bytes, offset) {
374
362
  const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
375
363
  return [removeNullCharacters(value), bytes.length];
376
- },
377
- description: "utf8",
378
- fixedSize: null,
379
- maxSize: null
380
- };
364
+ }
365
+ });
381
366
  };
382
367
  var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());
383
368
 
384
369
  // src/string.ts
385
- var getStringEncoder = (config = {}) => {
386
- var _a, _b, _c;
370
+ function getStringEncoder(config = {}) {
371
+ var _a, _b;
387
372
  const size = (_a = config.size) != null ? _a : getU32Encoder();
388
373
  const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
389
- const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
390
374
  if (size === "variable") {
391
- return { ...encoding, description };
375
+ return encoding;
392
376
  }
393
377
  if (typeof size === "number") {
394
- return fixEncoder(encoding, size, description);
378
+ return fixEncoder(encoding, size);
395
379
  }
396
- return {
397
- description,
398
- encode: (value) => {
399
- const contentBytes = encoding.encode(value);
400
- const lengthBytes = size.encode(contentBytes.length);
401
- return mergeBytes([lengthBytes, contentBytes]);
380
+ return createEncoder({
381
+ getSizeFromValue: (value) => {
382
+ const contentSize = getEncodedSize(value, encoding);
383
+ return getEncodedSize(contentSize, size) + contentSize;
402
384
  },
403
- fixedSize: null,
404
- maxSize: null
405
- };
406
- };
407
- var getStringDecoder = (config = {}) => {
408
- var _a, _b, _c;
385
+ write: (value, bytes, offset) => {
386
+ const contentSize = getEncodedSize(value, encoding);
387
+ offset = size.write(contentSize, bytes, offset);
388
+ return encoding.write(value, bytes, offset);
389
+ }
390
+ });
391
+ }
392
+ function getStringDecoder(config = {}) {
393
+ var _a, _b;
409
394
  const size = (_a = config.size) != null ? _a : getU32Decoder();
410
395
  const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
411
- const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
412
396
  if (size === "variable") {
413
- return { ...encoding, description };
397
+ return encoding;
414
398
  }
415
399
  if (typeof size === "number") {
416
- return fixDecoder(encoding, size, description);
400
+ return fixDecoder(encoding, size);
417
401
  }
418
- return {
419
- decode: (bytes, offset = 0) => {
402
+ return createDecoder({
403
+ read: (bytes, offset = 0) => {
420
404
  assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
421
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
405
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
422
406
  const length = Number(lengthBigInt);
423
407
  offset = lengthOffset;
424
408
  const contentBytes = bytes.slice(offset, offset + length);
425
409
  assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
426
- const [value, contentOffset] = encoding.decode(contentBytes);
410
+ const [value, contentOffset] = encoding.read(contentBytes, 0);
427
411
  offset += contentOffset;
428
412
  return [value, offset];
429
- },
430
- description,
431
- fixedSize: null,
432
- maxSize: null
433
- };
434
- };
435
- var getStringCodec = (config = {}) => combineCodec(getStringEncoder(config), getStringDecoder(config));
436
- function getSizeDescription(size) {
437
- return typeof size === "object" ? size.description : `${size}`;
413
+ }
414
+ });
415
+ }
416
+ function getStringCodec(config = {}) {
417
+ return combineCodec(getStringEncoder(config), getStringDecoder(config));
438
418
  }
439
419
 
440
420
  exports.assertValidBaseString = assertValidBaseString;