@wener/utils 1.1.6 → 1.1.7
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/README.md +3 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/system/index.js +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/server.js +1 -1
- package/dist/system/server.js.map +1 -1
- package/lib/arrays/MaybeArray.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js +2 -2
- package/lib/asyncs/createLazyPromise.js.map +1 -1
- package/lib/asyncs/timeout.js +1 -1
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/copy.js +2 -3
- package/lib/browsers/copy.js.map +1 -1
- package/lib/browsers/loaders.js +6 -11
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/crypto/{hex.js → base.js} +1 -1
- package/lib/crypto/base.js.map +1 -0
- package/lib/crypto/hashing.js +4 -4
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/i18n/createTranslate.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/io/ArrayBuffers.js +164 -0
- package/lib/io/ArrayBuffers.js.map +1 -0
- package/lib/io/isBuffer.js +1 -1
- package/lib/io/isBuffer.js.map +1 -1
- package/lib/io/isTransferable.js.map +1 -1
- package/lib/isomorphics/structuredClone.js.map +1 -1
- package/lib/langs/deepEqual.js.map +1 -1
- package/lib/langs/shallowEqual.js.map +1 -1
- package/lib/logging/createNoopLogger.js.map +1 -1
- package/lib/modules/isModule.js.map +1 -1
- package/lib/modules/parseModuleId.js +7 -5
- package/lib/modules/parseModuleId.js.map +1 -1
- package/lib/objects/parseObjectPath.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/server/polyfillBrowser.js.map +1 -1
- package/lib/server/polyfillFetch.js.map +1 -1
- package/lib/server/polyfillJsDom.js +1 -1
- package/lib/server/polyfillJsDom.js.map +1 -1
- package/lib/strings/formatBytes.js +1 -1
- package/lib/strings/formatBytes.js.map +1 -1
- package/lib/strings/renderTemplate.js +1 -1
- package/lib/strings/renderTemplate.js.map +1 -1
- package/package.json +10 -2
- package/src/arrays/MaybeArray.ts +1 -1
- package/src/asyncs/createLazyPromise.test.ts +4 -4
- package/src/asyncs/createLazyPromise.ts +2 -2
- package/src/asyncs/generatorOfStream.ts +1 -0
- package/src/asyncs/timeout.ts +1 -1
- package/src/browsers/copy.ts +6 -5
- package/src/browsers/loaders.ts +6 -11
- package/src/crypto/{hex.ts → base.ts} +3 -0
- package/src/crypto/hashing.test.ts +1 -1
- package/src/crypto/hashing.ts +4 -4
- package/src/crypto/randomUUID.ts +3 -0
- package/src/i18n/createTranslate.test.ts +18 -18
- package/src/i18n/createTranslate.ts +1 -1
- package/src/index.ts +3 -2
- package/src/io/AbstractEncoding.ts +21 -0
- package/src/io/ArrayBuffer.test-d.ts +4 -0
- package/src/io/ArrayBuffers.base64.test.ts +61 -0
- package/src/io/ArrayBuffers.test.ts +23 -0
- package/src/io/ArrayBuffers.ts +272 -0
- package/src/io/Buffer.ts +16 -0
- package/src/io/isBuffer.test.ts +2 -0
- package/src/io/isBuffer.ts +3 -8
- package/src/io/isTransferable.ts +1 -1
- package/src/isomorphics/structuredClone.test.ts +1 -1
- package/src/isomorphics/structuredClone.ts +9 -6
- package/src/langs/deepEqual.ts +1 -0
- package/src/langs/shallowEqual.ts +1 -1
- package/src/logging/Logger.ts +6 -0
- package/src/logging/createNoopLogger.ts +1 -1
- package/src/logging/logger.test.ts +3 -3
- package/src/modules/isModule.ts +3 -0
- package/src/modules/parseModuleId.test.ts +7 -2
- package/src/modules/parseModuleId.ts +15 -9
- package/src/objects/get.test-d.ts +51 -0
- package/src/objects/get.test.ts +2 -55
- package/src/objects/parseObjectPath.ts +4 -3
- package/src/objects/set.test.ts +32 -31
- package/src/objects/set.ts +2 -2
- package/src/server/polyfillBrowser.ts +8 -0
- package/src/server/polyfillFetch.ts +0 -1
- package/src/server/polyfillJsDom.ts +3 -2
- package/src/strings/formatBytes.ts +1 -1
- package/src/strings/renderTemplate.test.ts +1 -0
- package/src/strings/renderTemplate.ts +8 -5
- package/src/typedoc.ts +2 -0
- package/tsconfig.json +2 -1
- package/dist/cjs/_commonjsHelpers-dfec268f.js +0 -2
- package/dist/cjs/_commonjsHelpers-dfec268f.js.map +0 -1
- package/dist/cjs/api-7db97ae3.js +0 -1085
- package/dist/cjs/api-7db97ae3.js.map +0 -1
- package/dist/cjs/index-a6d1d653.js +0 -14
- package/dist/cjs/index-a6d1d653.js.map +0 -1
- package/dist/cjs/multipart-parser-141ed517.js +0 -3
- package/dist/cjs/multipart-parser-141ed517.js.map +0 -1
- package/dist/esm/_commonjsHelpers-28e086c5.js +0 -2
- package/dist/esm/_commonjsHelpers-28e086c5.js.map +0 -1
- package/dist/esm/api-3f555472.js +0 -1085
- package/dist/esm/api-3f555472.js.map +0 -1
- package/dist/esm/index-b50fef91.js +0 -14
- package/dist/esm/index-b50fef91.js.map +0 -1
- package/dist/esm/multipart-parser-5c1d6ee9.js +0 -3
- package/dist/esm/multipart-parser-5c1d6ee9.js.map +0 -1
- package/dist/system/_commonjsHelpers-07f370a7.js +0 -2
- package/dist/system/_commonjsHelpers-07f370a7.js.map +0 -1
- package/dist/system/api-dc50ebac.js +0 -1085
- package/dist/system/api-dc50ebac.js.map +0 -1
- package/dist/system/index-8f1807ba.js +0 -14
- package/dist/system/index-8f1807ba.js.map +0 -1
- package/dist/system/multipart-parser-53518ee9.js +0 -3
- package/dist/system/multipart-parser-53518ee9.js.map +0 -1
- package/lib/crypto/hex.js.map +0 -1
- package/lib/shim/urljoin.js +0 -51
- package/lib/shim/urljoin.js.map +0 -1
- package/src/shim/urljoin.test.ts +0 -6
- package/src/shim/urljoin.ts +0 -75
- package/src/types.d.ts +0 -7
|
@@ -5,9 +5,10 @@ export type ObjectPathLike = ObjectKey | ObjectPath;
|
|
|
5
5
|
/**
|
|
6
6
|
* Parse object path
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* @example
|
|
9
|
+
* parseObjectPath('a.b.c') // => ['a', 'b', 'c']
|
|
10
|
+
* parseObjectPath('a[0].b') // => ['a', 0, 'b']
|
|
11
|
+
* parseObjectPath('a[0][1]') // => ['a', 0, 1]
|
|
11
12
|
*
|
|
12
13
|
*/
|
|
13
14
|
export function parseObjectPath(s: ObjectPathLike): ObjectPath {
|
package/src/objects/set.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/* eslint no-proto:0 no-prototype-builtins:0 */
|
|
1
2
|
import test from 'ava';
|
|
2
3
|
import { set } from './set';
|
|
3
4
|
|
|
4
5
|
test('set basics', (t) => {
|
|
5
6
|
t.is(set({}, 'c', 3), undefined, 'should not give return value');
|
|
6
7
|
{
|
|
7
|
-
|
|
8
|
+
const item = { foo: 1 };
|
|
8
9
|
set(item, 'bar', 123);
|
|
9
10
|
t.is(item, item);
|
|
10
11
|
t.deepEqual(
|
|
@@ -30,7 +31,7 @@ test('set objects', (t) => {
|
|
|
30
31
|
const set = (a: any, b: any, c: any) => orig(a, b, c, isMerge);
|
|
31
32
|
const verb = isMerge ? 'merge' : 'overwrite';
|
|
32
33
|
objects(`should ${verb} existing object value :: simple`, () => {
|
|
33
|
-
|
|
34
|
+
const { input } = prepare({
|
|
34
35
|
hello: { a: 1 },
|
|
35
36
|
});
|
|
36
37
|
|
|
@@ -51,7 +52,7 @@ test('set objects', (t) => {
|
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
objects(`should ${verb} existing object value :: nested`, () => {
|
|
54
|
-
|
|
55
|
+
const { input, copy } = prepare({
|
|
55
56
|
a: {
|
|
56
57
|
b: {
|
|
57
58
|
c: 123,
|
|
@@ -71,7 +72,7 @@ test('set objects', (t) => {
|
|
|
71
72
|
});
|
|
72
73
|
|
|
73
74
|
objects(`should ${verb} existing array value :: simple`, () => {
|
|
74
|
-
|
|
75
|
+
const { input } = prepare([{ foo: 1 }]);
|
|
75
76
|
|
|
76
77
|
set(input, '0', { bar: 2 });
|
|
77
78
|
|
|
@@ -83,7 +84,7 @@ test('set objects', (t) => {
|
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
objects(`should ${verb} existing array value :: nested`, () => {
|
|
86
|
-
|
|
87
|
+
const { input } = prepare([
|
|
87
88
|
{ name: 'bob', age: 56, friends: ['foobar'] },
|
|
88
89
|
{ name: 'alice', age: 47, friends: ['mary'] },
|
|
89
90
|
]);
|
|
@@ -118,7 +119,7 @@ test('set arrays', (t) => {
|
|
|
118
119
|
f();
|
|
119
120
|
};
|
|
120
121
|
arrays('should create array instead of object via numeric key :: simple', () => {
|
|
121
|
-
|
|
122
|
+
const input: any = { a: 1 };
|
|
122
123
|
set(input, 'e.0', 2);
|
|
123
124
|
t.true(Array.isArray(input.e));
|
|
124
125
|
t.is(input.e[0], 2);
|
|
@@ -129,7 +130,7 @@ test('set arrays', (t) => {
|
|
|
129
130
|
});
|
|
130
131
|
|
|
131
132
|
arrays('should create array instead of object via numeric key :: nested', () => {
|
|
132
|
-
|
|
133
|
+
const input: any = { a: 1 };
|
|
133
134
|
set(input, 'e.0.0', 123);
|
|
134
135
|
t.true(input.e instanceof Array);
|
|
135
136
|
t.is(input.e[0][0], 123);
|
|
@@ -140,7 +141,7 @@ test('set arrays', (t) => {
|
|
|
140
141
|
});
|
|
141
142
|
|
|
142
143
|
arrays('should be able to create object inside of array', () => {
|
|
143
|
-
|
|
144
|
+
const input: any = {};
|
|
144
145
|
set(input, ['x', '0', 'z'], 123);
|
|
145
146
|
t.true(input.x instanceof Array);
|
|
146
147
|
t.deepEqual(input, {
|
|
@@ -149,16 +150,16 @@ test('set arrays', (t) => {
|
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
arrays('should create arrays with hole(s) if needed', () => {
|
|
152
|
-
|
|
153
|
+
const input: any = {};
|
|
153
154
|
set(input, ['x', '1', 'z'], 123);
|
|
154
155
|
t.true(input.x instanceof Array);
|
|
155
156
|
t.deepEqual(input, {
|
|
156
|
-
x: [, { z: 123 }],
|
|
157
|
+
x: [undefined, { z: 123 }],
|
|
157
158
|
});
|
|
158
159
|
});
|
|
159
160
|
|
|
160
161
|
arrays('should create object from decimal-like key :: array :: zero :: string', () => {
|
|
161
|
-
|
|
162
|
+
const input: any = {};
|
|
162
163
|
set(input, ['x', '10.0', 'z'], 123);
|
|
163
164
|
t.false(input.x instanceof Array);
|
|
164
165
|
t.deepEqual(input, {
|
|
@@ -171,17 +172,17 @@ test('set arrays', (t) => {
|
|
|
171
172
|
});
|
|
172
173
|
|
|
173
174
|
arrays('should create array from decimal-like key :: array :: zero :: number', () => {
|
|
174
|
-
|
|
175
|
+
const input: any = {};
|
|
175
176
|
set(input, ['x', 10.0, 'z'], 123);
|
|
176
177
|
t.true(input.x instanceof Array);
|
|
177
178
|
|
|
178
|
-
|
|
179
|
+
const x = Array(10);
|
|
179
180
|
x.push({ z: 123 });
|
|
180
181
|
t.deepEqual(input, { x });
|
|
181
182
|
});
|
|
182
183
|
|
|
183
184
|
arrays('should create object from decimal-like key :: array :: nonzero', () => {
|
|
184
|
-
|
|
185
|
+
const input: any = {};
|
|
185
186
|
set(input, ['x', '10.2', 'z'], 123);
|
|
186
187
|
t.false(input.x instanceof Array);
|
|
187
188
|
t.deepEqual(input, {
|
|
@@ -200,8 +201,8 @@ test('set pollution', (t) => {
|
|
|
200
201
|
f();
|
|
201
202
|
};
|
|
202
203
|
pollution('should protect against "__proto__" assignment', () => {
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
const input: any = { abc: 123 };
|
|
205
|
+
const before = input.__proto__;
|
|
205
206
|
set(input, '__proto__.hello', 123);
|
|
206
207
|
|
|
207
208
|
t.deepEqual(input.__proto__, before);
|
|
@@ -211,8 +212,8 @@ test('set pollution', (t) => {
|
|
|
211
212
|
});
|
|
212
213
|
|
|
213
214
|
pollution('should protect against "__proto__" assignment :: nested', () => {
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
const input: any = { abc: 123 };
|
|
216
|
+
const before = input.__proto__;
|
|
216
217
|
set(input, ['xyz', '__proto__', 'hello'], 123);
|
|
217
218
|
|
|
218
219
|
t.deepEqual(input.__proto__, before);
|
|
@@ -227,7 +228,7 @@ test('set pollution', (t) => {
|
|
|
227
228
|
});
|
|
228
229
|
|
|
229
230
|
pollution('should ignore "prototype" assignment', () => {
|
|
230
|
-
|
|
231
|
+
const input: any = { a: 123 };
|
|
231
232
|
set(input, 'a.prototype.hello', 'world');
|
|
232
233
|
|
|
233
234
|
t.is(input.a.prototype, undefined);
|
|
@@ -243,7 +244,7 @@ test('set pollution', (t) => {
|
|
|
243
244
|
});
|
|
244
245
|
|
|
245
246
|
pollution('should ignore "constructor" assignment :: direct', () => {
|
|
246
|
-
|
|
247
|
+
const input: any = { a: 123 };
|
|
247
248
|
|
|
248
249
|
function Custom() {
|
|
249
250
|
//
|
|
@@ -259,7 +260,7 @@ test('set pollution', (t) => {
|
|
|
259
260
|
});
|
|
260
261
|
|
|
261
262
|
pollution('should ignore "constructor" assignment :: nested', () => {
|
|
262
|
-
|
|
263
|
+
const input: any = {};
|
|
263
264
|
|
|
264
265
|
set(input, 'constructor.prototype.hello', 'world');
|
|
265
266
|
t.is(input.hasOwnProperty('constructor'), false);
|
|
@@ -272,7 +273,7 @@ test('set pollution', (t) => {
|
|
|
272
273
|
|
|
273
274
|
// Test for CVE-2022-25645 - CWE-1321
|
|
274
275
|
pollution('should ignore JSON.parse crafted object with "__proto__" key', () => {
|
|
275
|
-
|
|
276
|
+
const a: any = { b: { c: 1 } };
|
|
276
277
|
t.is(a.polluted, undefined);
|
|
277
278
|
set(a, 'b', JSON.parse('{"__proto__":{"polluted":"Yes!"}}'));
|
|
278
279
|
t.is(a.polluted, undefined);
|
|
@@ -284,19 +285,19 @@ test('set assigns', (t) => {
|
|
|
284
285
|
f();
|
|
285
286
|
};
|
|
286
287
|
assigns('should add value to key path :: shallow :: string', () => {
|
|
287
|
-
|
|
288
|
+
const input: any = {};
|
|
288
289
|
set(input, 'abc', 123);
|
|
289
290
|
t.deepEqual(input, { abc: 123 });
|
|
290
291
|
});
|
|
291
292
|
|
|
292
293
|
assigns('should add value to key path :: shallow :: array', () => {
|
|
293
|
-
|
|
294
|
+
const input: any = {};
|
|
294
295
|
set(input, ['abc'], 123);
|
|
295
296
|
t.deepEqual(input, { abc: 123 });
|
|
296
297
|
});
|
|
297
298
|
|
|
298
299
|
assigns('should add value to key path :: nested :: string', () => {
|
|
299
|
-
|
|
300
|
+
const input: any = {};
|
|
300
301
|
set(input, 'a.b.c', 123);
|
|
301
302
|
t.deepEqual(input, {
|
|
302
303
|
a: {
|
|
@@ -308,7 +309,7 @@ test('set assigns', (t) => {
|
|
|
308
309
|
});
|
|
309
310
|
|
|
310
311
|
assigns('should add value to key path :: nested :: array', () => {
|
|
311
|
-
|
|
312
|
+
const input: any = {};
|
|
312
313
|
set(input, ['a', 'b', 'c'], 123);
|
|
313
314
|
t.deepEqual(input, {
|
|
314
315
|
a: {
|
|
@@ -320,7 +321,7 @@ test('set assigns', (t) => {
|
|
|
320
321
|
});
|
|
321
322
|
|
|
322
323
|
assigns('should create Array via integer key :: string', () => {
|
|
323
|
-
|
|
324
|
+
const input: any = {};
|
|
324
325
|
set(input, ['foo', '0'], 123);
|
|
325
326
|
t.true(input.foo instanceof Array);
|
|
326
327
|
t.deepEqual(input, {
|
|
@@ -329,7 +330,7 @@ test('set assigns', (t) => {
|
|
|
329
330
|
});
|
|
330
331
|
|
|
331
332
|
assigns('should create Array via integer key :: number', () => {
|
|
332
|
-
|
|
333
|
+
const input: any = {};
|
|
333
334
|
set(input, ['foo', 0], 123);
|
|
334
335
|
t.true(input.foo instanceof Array);
|
|
335
336
|
t.deepEqual(input, {
|
|
@@ -343,7 +344,7 @@ test('set preserves', (t) => {
|
|
|
343
344
|
f();
|
|
344
345
|
};
|
|
345
346
|
preserves('should preserve existing object structure', () => {
|
|
346
|
-
|
|
347
|
+
const input = {
|
|
347
348
|
a: {
|
|
348
349
|
b: {
|
|
349
350
|
c: 123,
|
|
@@ -366,7 +367,7 @@ test('set preserves', (t) => {
|
|
|
366
367
|
});
|
|
367
368
|
|
|
368
369
|
preserves('should overwrite existing non-object values as object', () => {
|
|
369
|
-
|
|
370
|
+
const input = {
|
|
370
371
|
a: {
|
|
371
372
|
b: 123,
|
|
372
373
|
},
|
|
@@ -384,7 +385,7 @@ test('set preserves', (t) => {
|
|
|
384
385
|
});
|
|
385
386
|
|
|
386
387
|
preserves('should preserve existing object tree w/ array value', () => {
|
|
387
|
-
|
|
388
|
+
const input = {
|
|
388
389
|
a: {
|
|
389
390
|
b: {
|
|
390
391
|
c: 123,
|
package/src/objects/set.ts
CHANGED
|
@@ -22,8 +22,8 @@ export function set<T extends object, V>(obj: T, key: ObjectKey | ObjectPath, va
|
|
|
22
22
|
: val
|
|
23
23
|
: typeof (x = current[k]) === typeof path
|
|
24
24
|
? x
|
|
25
|
-
: // @ts-
|
|
26
|
-
path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.')
|
|
25
|
+
: // @ts-expect-error hacky type check
|
|
26
|
+
path[i] * 0 !== 0 || !!~('' + path[i]).indexOf('.') // eslint-disable-line
|
|
27
27
|
? {}
|
|
28
28
|
: [];
|
|
29
29
|
}
|
|
@@ -2,6 +2,14 @@ import { polyfillCrypto } from './polyfillCrypto';
|
|
|
2
2
|
import { polyfillFetch } from './polyfillFetch';
|
|
3
3
|
import { polyfillJsDom } from './polyfillJsDom';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Polyfills the browser environment with the necessary APIs for the server.
|
|
7
|
+
* Currently, this includes:
|
|
8
|
+
* - `window`
|
|
9
|
+
* - `document`
|
|
10
|
+
* - `fetch`
|
|
11
|
+
* - `crypto`
|
|
12
|
+
*/
|
|
5
13
|
export async function polyfillBrowser() {
|
|
6
14
|
await polyfillCrypto();
|
|
7
15
|
await polyfillFetch();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
|
|
1
|
+
import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
|
|
2
2
|
|
|
3
3
|
export async function polyfillJsDom() {
|
|
4
4
|
if (typeof window !== 'undefined') {
|
|
@@ -8,6 +8,7 @@ export async function polyfillJsDom() {
|
|
|
8
8
|
const { ResourceLoader, JSDOM } = await import('jsdom');
|
|
9
9
|
|
|
10
10
|
// https://github.com/lukechilds/window/blob/master/src/index.js
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
11
12
|
class Window {
|
|
12
13
|
constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {
|
|
13
14
|
const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;
|
|
@@ -55,7 +56,7 @@ export async function polyfillJsDom() {
|
|
|
55
56
|
Object.getOwnPropertyNames(window)
|
|
56
57
|
|
|
57
58
|
// Remove protected properties
|
|
58
|
-
.filter((prop) => protectedProperties.
|
|
59
|
+
.filter((prop) => !protectedProperties.includes(prop))
|
|
59
60
|
|
|
60
61
|
// If we're only applying specific required properties remove everything else
|
|
61
62
|
.filter((prop) => !(properties && properties.indexOf(prop) === -1))
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { get } from '../objects/get';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* render template like js template string
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @example
|
|
7
|
+
* renderTemplate('My name is ${name}',{name:'wener'})
|
|
8
|
+
* // 'My name is wener'
|
|
7
9
|
*
|
|
10
|
+
* @param match `js` for `${name}`, common for `{{name}}`
|
|
8
11
|
*/
|
|
9
12
|
export function renderTemplate(
|
|
10
13
|
template: string,
|
|
11
|
-
data: ((v: string) => any) | object,
|
|
14
|
+
data: ((v: string) => any) | object | undefined,
|
|
12
15
|
match: 'js' | 'common' | RegExp = 'js',
|
|
13
16
|
) {
|
|
14
17
|
let getter: Function;
|
|
@@ -21,14 +24,14 @@ export function renderTemplate(
|
|
|
21
24
|
getter = (v: string) => get(data, v);
|
|
22
25
|
}
|
|
23
26
|
if (typeof match === 'string') {
|
|
24
|
-
match = Matches[match] || Matches
|
|
27
|
+
match = Matches[match] || Matches.js;
|
|
25
28
|
}
|
|
26
29
|
return template.replace(match, (_, g) => {
|
|
27
30
|
return getter(g.trim());
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
const Matches = {
|
|
34
|
+
const Matches: Record<string, RegExp> = {
|
|
32
35
|
js: /\${(.*?)}/g,
|
|
33
36
|
common: /{{(.*?)}}/g,
|
|
34
37
|
};
|
package/src/typedoc.ts
ADDED
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers-dfec268f.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|