@polkadot/types-codec 8.8.3-5 → 8.8.3-6

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.
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/types-codec',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '8.8.3-5'
14
+ version: '8.8.3-6'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -140,10 +140,7 @@ function removeExtensions(type, isSized) {
140
140
  }
141
141
 
142
142
  function removeColons() {
143
- return function (value) {
144
- let {
145
- allowNamespaces
146
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
143
+ return value => {
147
144
  let index = 0;
148
145
 
149
146
  while (index !== -1) {
@@ -152,10 +149,6 @@ function removeColons() {
152
149
  if (index === 0) {
153
150
  value = value.substring(2);
154
151
  } else if (index !== -1) {
155
- if (allowNamespaces) {
156
- return value;
157
- }
158
-
159
152
  let start = index;
160
153
 
161
154
  while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
@@ -177,7 +170,7 @@ function removeGenerics() {
177
170
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
178
171
  const box = ALLOWED_BOXES.find(box => {
179
172
  const start = index - box.length;
180
- return start >= 0 && value.substring(start, start + box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
173
+ return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
181
174
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
182
175
  }); // we have not found anything, unwrap generic innards
183
176
 
@@ -190,17 +183,13 @@ function removeGenerics() {
190
183
 
191
184
  return value;
192
185
  };
193
- }
194
- /** @internal */
195
-
196
-
197
- function pairOfReplacer(v) {
198
- return `(${v},${v})`;
199
186
  } // remove the PairOf wrappers
200
187
 
201
188
 
202
189
  function removePairOf() {
203
- return value => replaceTagWith(value, 'PairOf<', pairOfReplacer);
190
+ const replacer = v => `(${v},${v})`;
191
+
192
+ return value => replaceTagWith(value, 'PairOf<', replacer);
204
193
  } // remove the type traits
205
194
 
206
195
 
@@ -226,40 +215,31 @@ function removeTraits() {
226
215
  .replace(from5, 'Lookup') // replace `<...>::Type`
227
216
  .replace(from6, '');
228
217
  };
229
- }
230
- /** @internal */
231
-
232
-
233
- function wrapReplacer(v) {
234
- return v;
235
218
  } // remove wrapping values, i.e. Box<Proposal> -> Proposal
236
219
 
237
220
 
238
221
  function removeWrap(check) {
239
- return value => replaceTagWith(value, check, wrapReplacer);
222
+ const replacer = v => v;
223
+
224
+ return value => replaceTagWith(value, check, replacer);
240
225
  }
241
226
 
242
- const sanitizeMap = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types
227
+ const sanitizeMap = new Map();
243
228
 
244
- function sanitize(value, options) {
229
+ function sanitize(value) {
245
230
  const startValue = value.toString();
246
- let result = startValue;
231
+ const memoized = sanitizeMap.get(startValue);
247
232
 
248
- if (!options) {
249
- const memoized = sanitizeMap.get(startValue);
250
-
251
- if (memoized) {
252
- return memoized;
253
- }
233
+ if (memoized) {
234
+ return memoized;
254
235
  }
255
236
 
256
- for (let i = 0; i < mappings.length; i++) {
257
- result = mappings[i](result, options);
258
- }
237
+ let result = startValue;
259
238
 
260
- if (!options) {
261
- sanitizeMap.set(startValue, result);
239
+ for (let i = 0; i < mappings.length; i++) {
240
+ result = mappings[i](result);
262
241
  }
263
242
 
243
+ sanitizeMap.set(startValue, result);
264
244
  return result;
265
245
  }
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.8.3-5",
23
+ "version": "8.8.3-6",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
package/packageInfo.js CHANGED
@@ -5,5 +5,5 @@ export const packageInfo = {
5
5
  name: '@polkadot/types-codec',
6
6
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
7
  type: 'esm',
8
- version: '8.8.3-5'
8
+ version: '8.8.3-6'
9
9
  };
@@ -1,7 +1,5 @@
1
- interface SanitizeOptions {
2
- allowNamespaces?: boolean;
3
- }
4
- declare type Mapper = (value: string, options?: SanitizeOptions) => string;
1
+ import { AnyString } from '../types';
2
+ declare type Mapper = (value: string) => string;
5
3
  export declare function trim(): Mapper;
6
4
  export declare function findClosing(value: string, start: number): number;
7
5
  export declare function alias(src: string, dest: string, withChecks?: boolean): Mapper;
@@ -13,5 +11,5 @@ export declare function removeGenerics(): Mapper;
13
11
  export declare function removePairOf(): Mapper;
14
12
  export declare function removeTraits(): Mapper;
15
13
  export declare function removeWrap(check: string): Mapper;
16
- export declare function sanitize(value: String | string, options?: SanitizeOptions): string;
14
+ export declare function sanitize(value: AnyString): string;
17
15
  export {};
package/utils/sanitize.js CHANGED
@@ -117,9 +117,7 @@ export function removeExtensions(type, isSized) {
117
117
  };
118
118
  }
119
119
  export function removeColons() {
120
- return (value, {
121
- allowNamespaces
122
- } = {}) => {
120
+ return value => {
123
121
  let index = 0;
124
122
 
125
123
  while (index !== -1) {
@@ -128,10 +126,6 @@ export function removeColons() {
128
126
  if (index === 0) {
129
127
  value = value.substring(2);
130
128
  } else if (index !== -1) {
131
- if (allowNamespaces) {
132
- return value;
133
- }
134
-
135
129
  let start = index;
136
130
 
137
131
  while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
@@ -152,7 +146,7 @@ export function removeGenerics() {
152
146
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
153
147
  const box = ALLOWED_BOXES.find(box => {
154
148
  const start = index - box.length;
155
- return start >= 0 && value.substring(start, start + box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
149
+ return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
156
150
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
157
151
  }); // we have not found anything, unwrap generic innards
158
152
 
@@ -165,16 +159,12 @@ export function removeGenerics() {
165
159
 
166
160
  return value;
167
161
  };
168
- }
169
- /** @internal */
170
-
171
- function pairOfReplacer(v) {
172
- return `(${v},${v})`;
173
162
  } // remove the PairOf wrappers
174
163
 
175
-
176
164
  export function removePairOf() {
177
- return value => replaceTagWith(value, 'PairOf<', pairOfReplacer);
165
+ const replacer = v => `(${v},${v})`;
166
+
167
+ return value => replaceTagWith(value, 'PairOf<', replacer);
178
168
  } // remove the type traits
179
169
 
180
170
  export function removeTraits() {
@@ -199,38 +189,28 @@ export function removeTraits() {
199
189
  .replace(from5, 'Lookup') // replace `<...>::Type`
200
190
  .replace(from6, '');
201
191
  };
202
- }
203
- /** @internal */
204
-
205
- function wrapReplacer(v) {
206
- return v;
207
192
  } // remove wrapping values, i.e. Box<Proposal> -> Proposal
208
193
 
209
-
210
194
  export function removeWrap(check) {
211
- return value => replaceTagWith(value, check, wrapReplacer);
212
- }
213
- const sanitizeMap = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types
195
+ const replacer = v => v;
214
196
 
215
- export function sanitize(value, options) {
197
+ return value => replaceTagWith(value, check, replacer);
198
+ }
199
+ const sanitizeMap = new Map();
200
+ export function sanitize(value) {
216
201
  const startValue = value.toString();
217
- let result = startValue;
202
+ const memoized = sanitizeMap.get(startValue);
218
203
 
219
- if (!options) {
220
- const memoized = sanitizeMap.get(startValue);
221
-
222
- if (memoized) {
223
- return memoized;
224
- }
204
+ if (memoized) {
205
+ return memoized;
225
206
  }
226
207
 
227
- for (let i = 0; i < mappings.length; i++) {
228
- result = mappings[i](result, options);
229
- }
208
+ let result = startValue;
230
209
 
231
- if (!options) {
232
- sanitizeMap.set(startValue, result);
210
+ for (let i = 0; i < mappings.length; i++) {
211
+ result = mappings[i](result);
233
212
  }
234
213
 
214
+ sanitizeMap.set(startValue, result);
235
215
  return result;
236
216
  }