@leofcoin/codec-format-interface 1.6.9 → 1.6.11

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.
@@ -30,8 +30,4 @@ export default class BasicInterface {
30
30
  * @return {String} encoded
31
31
  */
32
32
  toBs58(): base58String;
33
- /**
34
- * @param {Object} data
35
- */
36
- create(data: object): Uint8Array;
37
33
  }
@@ -25,4 +25,8 @@ export default class FormatInterface extends BasicInterface implements FormatInt
25
25
  hash(): Promise<any>;
26
26
  fromUint8Array(buffer: any): object;
27
27
  fromArrayBuffer(buffer: any): object;
28
+ /**
29
+ * @param {Object} data
30
+ */
31
+ create(data: object): Uint8Array;
28
32
  }
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import basicInterface from './basic-interface.js';
2
2
  import formatInterface from './codec-format-interface.js';
3
3
  import codecHash from './codec-hash.js';
4
4
  import codec from './codec.js';
5
+ export { codecs } from '@leofcoin/codecs';
5
6
  export declare const BasicInterface: typeof basicInterface;
6
7
  export declare const FormatInterface: typeof formatInterface;
7
8
  export declare const CodecHash: typeof codecHash;
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { fromBase58, fromHex, toHex, toBase32, toBase58 } from '@vandeurenglenn/
5
5
  import { createKeccak } from 'hash-wasm';
6
6
  import varint from 'varint';
7
7
  import { utils } from '@leofcoin/codecs';
8
+ export { codecs } from '@leofcoin/codecs';
8
9
 
9
10
  /**
10
11
  * @param {string}
@@ -103,26 +104,6 @@ let BasicInterface$1 = class BasicInterface {
103
104
  this.encode();
104
105
  return toBase58(this.encoded);
105
106
  }
106
- /**
107
- * @param {Object} data
108
- */
109
- create(data) {
110
- const decoded = {};
111
- if (this.keys?.length > 0) {
112
- for (const key of this.keys) {
113
- Object.defineProperties(decoded, {
114
- [key]: {
115
- enumerable: true,
116
- configurable: true,
117
- set: (value) => data[key],
118
- get: () => data[key]
119
- }
120
- });
121
- }
122
- this.decoded = decoded;
123
- return this.encode(decoded);
124
- }
125
- }
126
107
  };
127
108
 
128
109
  let Codec$1 = class Codec extends BasicInterface$1 {
@@ -141,7 +122,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
141
122
  this.decode(buffer);
142
123
  }
143
124
  else {
144
- this.encode(buffer);
125
+ this.encode(Number(new TextDecoder().decode(buffer)));
145
126
  }
146
127
  }
147
128
  else if (buffer instanceof ArrayBuffer) {
@@ -152,7 +133,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
152
133
  this.decode(buffer);
153
134
  }
154
135
  else {
155
- this.encode(buffer);
136
+ this.encode(Number(new TextDecoder().decode(new Uint8Array(buffer))));
156
137
  }
157
138
  }
158
139
  else if (typeof buffer === 'string') {
@@ -165,7 +146,7 @@ let Codec$1 = class Codec extends BasicInterface$1 {
165
146
  else if (this.isBase58(buffer))
166
147
  this.fromBs58(buffer);
167
148
  else
168
- throw new Error(`unsupported string ${buffer}`);
149
+ this.fromString(buffer);
169
150
  }
170
151
  if (!isNaN(buffer))
171
152
  if (utils.getCodec(buffer))
@@ -192,14 +173,14 @@ let Codec$1 = class Codec extends BasicInterface$1 {
192
173
  this.name = this.getCodecName(codec);
193
174
  this.hashAlg = this.getHashAlg(this.name);
194
175
  this.codec = this.getCodec(this.name);
195
- this.codecBuffer = varint.encode(codec);
176
+ this.codecBuffer = varint.encode(this.codec);
196
177
  }
197
178
  fromName(name) {
198
179
  const codec = this.getCodec(name);
199
180
  this.name = name;
200
181
  this.codec = codec;
201
182
  this.hashAlg = this.getHashAlg(name);
202
- this.codecBuffer = varint.encode(codec);
183
+ this.codecBuffer = varint.encode(this.codec);
203
184
  }
204
185
  decode(encoded) {
205
186
  encoded = encoded || this.encoded;
@@ -353,7 +334,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
353
334
  this.fromArrayBuffer(buffer);
354
335
  else if (buffer instanceof FormatInterface$1 && buffer?.name === this.name)
355
336
  return buffer;
356
- else if (buffer instanceof String) {
337
+ else if (typeof buffer === 'string') {
357
338
  if (this.isHex(buffer))
358
339
  this.fromHex(buffer);
359
340
  else if (this.isBase58(buffer))
@@ -361,7 +342,7 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
361
342
  else if (this.isBase32(buffer))
362
343
  this.fromBs32(buffer);
363
344
  else
364
- throw new Error(`unsupported ${buffer}`);
345
+ this.fromString(buffer);
365
346
  }
366
347
  else {
367
348
  this.create(buffer);
@@ -447,6 +428,26 @@ let FormatInterface$1 = class FormatInterface extends BasicInterface$1 {
447
428
  this.encoded = new Uint8Array(buffer, buffer.byteOffset, buffer.byteLength);
448
429
  return this.hasCodec() ? this.decode() : this.create(JSON.parse(new TextDecoder().decode(this.encoded)));
449
430
  }
431
+ /**
432
+ * @param {Object} data
433
+ */
434
+ create(data) {
435
+ const decoded = {};
436
+ if (this.keys?.length > 0) {
437
+ for (const key of this.keys) {
438
+ Object.defineProperties(decoded, {
439
+ [key]: {
440
+ enumerable: true,
441
+ configurable: true,
442
+ set: (value) => data[key],
443
+ get: () => data[key]
444
+ }
445
+ });
446
+ }
447
+ this.decoded = decoded;
448
+ return this.encode(decoded);
449
+ }
450
+ }
450
451
  };
451
452
 
452
453
  const BasicInterface = BasicInterface$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/codec-format-interface",
3
- "version": "1.6.9",
3
+ "version": "1.6.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {