@thi.ng/bencode 2.1.121 → 2.1.123

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:17Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.1.123](https://github.com/thi-ng/umbrella/tree/@thi.ng/bencode@2.1.123) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [2.1.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/bencode@2.1.6) (2022-04-07)
13
19
 
14
20
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -86,7 +86,7 @@ For Node.js REPL:
86
86
  const bc = await import("@thi.ng/bencode");
87
87
  ```
88
88
 
89
- Package sizes (brotli'd, pre-treeshake): ESM: 1.17 KB
89
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.18 KB
90
90
 
91
91
  ## Dependencies
92
92
 
@@ -94,6 +94,7 @@ Package sizes (brotli'd, pre-treeshake): ESM: 1.17 KB
94
94
  - [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
95
95
  - [@thi.ng/defmulti](https://github.com/thi-ng/umbrella/tree/develop/packages/defmulti)
96
96
  - [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
97
+ - [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
97
98
  - [@thi.ng/transducers](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers)
98
99
  - [@thi.ng/transducers-binary](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers-binary)
99
100
 
package/decode.js CHANGED
@@ -34,21 +34,21 @@ const decode = (buf, utf8 = true) => {
34
34
  x = i.value;
35
35
  switch (x) {
36
36
  case 100 /* DICT */:
37
- ensureNotKey(stack, "dict");
37
+ __ensureNotKey(stack, "dict");
38
38
  stack.push({ type: 4 /* DICT */, val: {} });
39
39
  break;
40
40
  case 108 /* LIST */:
41
- ensureNotKey(stack, "list");
41
+ __ensureNotKey(stack, "list");
42
42
  stack.push({ type: 5 /* LIST */, val: [] });
43
43
  break;
44
44
  case 105 /* INT */:
45
- x = collect(stack, readInt(iter, 0));
45
+ x = __collect(stack, __readInt(iter, 0));
46
46
  if (x !== void 0) {
47
47
  return x;
48
48
  }
49
49
  break;
50
50
  case 102 /* FLOAT */:
51
- x = collect(stack, readFloat(iter));
51
+ x = __collect(stack, __readFloat(iter));
52
52
  if (x !== void 0) {
53
53
  return x;
54
54
  }
@@ -73,11 +73,11 @@ const decode = (buf, utf8 = true) => {
73
73
  break;
74
74
  default:
75
75
  if (x >= 48 /* ZERO */ && x <= 57 /* NINE */) {
76
- x = readBytes(
76
+ x = __readBytes(
77
77
  iter,
78
- readInt(iter, x - 48 /* ZERO */, 58 /* COLON */)
78
+ __readInt(iter, x - 48 /* ZERO */, 58 /* COLON */)
79
79
  );
80
- x = collect(stack, x, utf8);
80
+ x = __collect(stack, x, utf8);
81
81
  if (x !== void 0) {
82
82
  return x;
83
83
  }
@@ -90,17 +90,16 @@ const decode = (buf, utf8 = true) => {
90
90
  }
91
91
  return peek(stack).val;
92
92
  };
93
- const ensureNotKey = (stack, type) => {
93
+ const __ensureNotKey = (stack, type) => {
94
94
  const x = peek(stack);
95
95
  assert(
96
96
  !x || x.type !== 4 /* DICT */ || x.key,
97
97
  type + " not supported as dict key"
98
98
  );
99
99
  };
100
- const collect = (stack, x, utf8 = false) => {
100
+ const __collect = (stack, x, utf8 = false) => {
101
101
  const parent = peek(stack);
102
- if (!parent)
103
- return x;
102
+ if (!parent) return x;
104
103
  if (parent.type === 5 /* LIST */) {
105
104
  parent.val.push(utf8 && isArray(x) ? utf8Decode(x) : x);
106
105
  } else {
@@ -112,7 +111,7 @@ const collect = (stack, x, utf8 = false) => {
112
111
  }
113
112
  }
114
113
  };
115
- const readInt = (iter, acc, end = 101 /* END */) => {
114
+ const __readInt = (iter, acc, end = 101 /* END */) => {
116
115
  let i;
117
116
  let x;
118
117
  let isSigned = false;
@@ -131,7 +130,7 @@ const readInt = (iter, acc, end = 101 /* END */) => {
131
130
  }
132
131
  illegalState(`incomplete int`);
133
132
  };
134
- const readFloat = (iter) => {
133
+ const __readFloat = (iter) => {
135
134
  let i;
136
135
  let x;
137
136
  let acc = "";
@@ -147,7 +146,7 @@ const readFloat = (iter) => {
147
146
  }
148
147
  illegalState(`incomplete float`);
149
148
  };
150
- const readBytes = (iter, len) => {
149
+ const __readBytes = (iter, len) => {
151
150
  let i;
152
151
  let buf = [];
153
152
  while (len-- > 0 && !(i = iter.next()).done) {
package/encode.js CHANGED
@@ -6,8 +6,8 @@ import { isString } from "@thi.ng/checks/is-string";
6
6
  import { defmulti } from "@thi.ng/defmulti/defmulti";
7
7
  import { assert } from "@thi.ng/errors/assert";
8
8
  import { unsupported } from "@thi.ng/errors/unsupported";
9
+ import { utf8Length } from "@thi.ng/strings/utf8";
9
10
  import { bytes, str, u8, u8array } from "@thi.ng/transducers-binary/bytes";
10
- import { utf8Length } from "@thi.ng/transducers-binary/utf8";
11
11
  import { mapcat } from "@thi.ng/transducers/mapcat";
12
12
  var Type = /* @__PURE__ */ ((Type2) => {
13
13
  Type2[Type2["INT"] = 0] = "INT";
@@ -25,8 +25,8 @@ var Lit = /* @__PURE__ */ ((Lit2) => {
25
25
  return Lit2;
26
26
  })(Lit || {});
27
27
  const FLOAT_RE = /^[0-9.-]+$/;
28
- const encode = (x, cap = 1024) => bytes(cap, encodeBin(x));
29
- const encodeBin = defmulti(
28
+ const encode = (x, cap = 1024) => bytes(cap, __encodeBin(x));
29
+ const __encodeBin = defmulti(
30
30
  (x) => isNumber(x) ? Math.floor(x) !== x ? 1 /* FLOAT */ : 0 /* INT */ : isBoolean(x) ? 0 /* INT */ : isString(x) ? 2 /* STR */ : x instanceof Uint8Array ? 3 /* BINARY */ : isArrayLike(x) ? 5 /* LIST */ : isPlainObject(x) ? 4 /* DICT */ : unsupported(`unsupported data type: ${x}`),
31
31
  {},
32
32
  {
@@ -49,13 +49,13 @@ const encodeBin = defmulti(
49
49
  [2 /* STR */]: (x) => [str(utf8Length(x) + ":" + x)],
50
50
  [5 /* LIST */]: (x) => [
51
51
  u8(108 /* LIST */),
52
- ...mapcat(encodeBin, x),
52
+ ...mapcat(__encodeBin, x),
53
53
  u8(101 /* END */)
54
54
  ],
55
55
  [4 /* DICT */]: (x) => [
56
56
  u8(100 /* DICT */),
57
57
  ...mapcat(
58
- (k) => encodeBin(k).concat(encodeBin(x[k])),
58
+ (k) => __encodeBin(k).concat(__encodeBin(x[k])),
59
59
  Object.keys(x).sort()
60
60
  ),
61
61
  u8(101 /* END */)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/bencode",
3
- "version": "2.1.121",
3
+ "version": "2.1.123",
4
4
  "description": "Bencode binary encoder / decoder with optional UTF8 encoding & floating point support",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/bencode#readme",
13
+ "homepage": "https://thi.ng/bencode",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,18 +36,19 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/arrays": "^2.9.5",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/defmulti": "^3.0.38",
42
- "@thi.ng/errors": "^2.5.6",
43
- "@thi.ng/transducers": "^9.0.4",
44
- "@thi.ng/transducers-binary": "^2.1.119"
39
+ "@thi.ng/arrays": "^2.9.7",
40
+ "@thi.ng/checks": "^3.6.5",
41
+ "@thi.ng/defmulti": "^3.0.40",
42
+ "@thi.ng/errors": "^2.5.8",
43
+ "@thi.ng/strings": "^3.7.34",
44
+ "@thi.ng/transducers": "^9.0.6",
45
+ "@thi.ng/transducers-binary": "^2.1.121"
45
46
  },
46
47
  "devDependencies": {
47
- "@microsoft/api-extractor": "^7.43.0",
48
- "esbuild": "^0.20.2",
49
- "typedoc": "^0.25.12",
50
- "typescript": "^5.4.3"
48
+ "@microsoft/api-extractor": "^7.47.0",
49
+ "esbuild": "^0.21.5",
50
+ "typedoc": "^0.25.13",
51
+ "typescript": "^5.5.2"
51
52
  },
52
53
  "keywords": [
53
54
  "array",
@@ -82,5 +83,5 @@
82
83
  "thi.ng": {
83
84
  "alias": "bc"
84
85
  },
85
- "gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
86
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
86
87
  }