@wener/utils 1.1.12 → 1.1.14

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.
Files changed (114) hide show
  1. package/dist/LICENSE.txt +1 -135
  2. package/dist/cjs/globalThis-ee7c1669.js +2 -0
  3. package/dist/cjs/globalThis-ee7c1669.js.map +1 -0
  4. package/dist/cjs/index.cjs +2 -2
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/server.cjs +1 -1
  7. package/dist/cjs/server.cjs.map +1 -1
  8. package/dist/esm/globalThis-000611c3.js +2 -0
  9. package/dist/esm/globalThis-000611c3.js.map +1 -0
  10. package/dist/esm/index.js +4 -4
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/server.js +1 -1
  13. package/dist/esm/server.js.map +1 -1
  14. package/dist/system/globalThis-7bba6592.js +2 -0
  15. package/dist/system/globalThis-7bba6592.js.map +1 -0
  16. package/dist/system/index.js +4 -4
  17. package/dist/system/index.js.map +1 -1
  18. package/dist/system/server.js +1 -1
  19. package/dist/system/server.js.map +1 -1
  20. package/lib/asyncs/timeout.js +3 -1
  21. package/lib/asyncs/timeout.js.map +1 -1
  22. package/lib/browsers/copy.js.map +1 -1
  23. package/lib/browsers/download.js +3 -1
  24. package/lib/browsers/download.js.map +1 -1
  25. package/lib/browsers/loaders.js +6 -2
  26. package/lib/browsers/loaders.js.map +1 -1
  27. package/lib/crypto/getRandomValues.js +1 -0
  28. package/lib/crypto/getRandomValues.js.map +1 -1
  29. package/lib/crypto/randomUUID.js +2 -0
  30. package/lib/crypto/randomUUID.js.map +1 -1
  31. package/lib/i18n/createTranslate.js +2 -1
  32. package/lib/i18n/createTranslate.js.map +1 -1
  33. package/lib/index.js +1 -0
  34. package/lib/index.js.map +1 -1
  35. package/lib/io/ArrayBuffers.js +1 -0
  36. package/lib/io/ArrayBuffers.js.map +1 -1
  37. package/lib/io/isTransferable.js +2 -0
  38. package/lib/io/isTransferable.js.map +1 -1
  39. package/lib/isomorphics/getGlobalThis.js.map +1 -1
  40. package/lib/isomorphics/globalThis.js +6 -0
  41. package/lib/isomorphics/globalThis.js.map +1 -0
  42. package/lib/isomorphics/structuredClone.js +1 -0
  43. package/lib/isomorphics/structuredClone.js.map +1 -1
  44. package/lib/logging/createLogger.js +15 -5
  45. package/lib/logging/createLogger.js.map +1 -1
  46. package/lib/server.js +3 -1
  47. package/lib/server.js.map +1 -1
  48. package/lib/servers/createFetchWithProxy.js +13 -0
  49. package/lib/servers/createFetchWithProxy.js.map +1 -0
  50. package/lib/servers/{createProxyFetch.js → createFetchWithProxyByNodeFetch.js} +8 -3
  51. package/lib/servers/createFetchWithProxyByNodeFetch.js.map +1 -0
  52. package/lib/servers/createFetchWithProxyByUndici.js +28 -0
  53. package/lib/servers/createFetchWithProxyByUndici.js.map +1 -0
  54. package/lib/servers/polyfillCrypto.js +2 -0
  55. package/lib/servers/polyfillCrypto.js.map +1 -1
  56. package/lib/servers/polyfillJsDom.js +2 -0
  57. package/lib/servers/polyfillJsDom.js.map +1 -1
  58. package/package.json +20 -28
  59. package/src/asyncs/createLazyPromise.test.ts +21 -21
  60. package/src/asyncs/timeout.ts +1 -1
  61. package/src/browsers/copy.ts +1 -1
  62. package/src/browsers/download.ts +1 -1
  63. package/src/browsers/loaders.ts +2 -2
  64. package/src/crypto/getRandomValues.ts +1 -0
  65. package/src/crypto/hashing.test.ts +10 -12
  66. package/src/crypto/pem/__snapshots__/pem.test.ts.snap +18 -0
  67. package/src/crypto/pem/pem.test.ts +14 -17
  68. package/src/crypto/randomUUID.ts +2 -0
  69. package/src/crypto/ulid.test.ts +9 -9
  70. package/src/i18n/createTranslate.test.ts +76 -88
  71. package/src/i18n/createTranslate.ts +2 -1
  72. package/src/index.ts +1 -0
  73. package/src/io/ArrayBuffer.test-d.ts +4 -2
  74. package/src/io/ArrayBuffers.base64.test.ts +17 -17
  75. package/src/io/ArrayBuffers.test.ts +8 -8
  76. package/src/io/ArrayBuffers.ts +1 -0
  77. package/src/io/Buffer.test.ts +4 -4
  78. package/src/io/isBuffer.test.ts +4 -4
  79. package/src/io/isTransferable.test.ts +7 -6
  80. package/src/io/isTransferable.ts +2 -0
  81. package/src/isomorphics/getGlobalThis.ts +3 -1
  82. package/src/isomorphics/globalThis.ts +3 -0
  83. package/src/isomorphics/structuredClone.test.ts +4 -4
  84. package/src/isomorphics/structuredClone.ts +1 -0
  85. package/src/langs/deepEqual.test.ts +4 -4
  86. package/src/langs/langs.test.ts +3 -3
  87. package/src/libs/ms.test.ts +311 -0
  88. package/src/logging/createLogger.ts +5 -5
  89. package/src/logging/logger.test.ts +8 -8
  90. package/src/modules/parseModuleId.test.ts +3 -3
  91. package/src/objects/get.test-d.ts +30 -22
  92. package/src/objects/parseObjectPath.test.ts +3 -3
  93. package/src/objects/set.test.ts +98 -117
  94. package/src/server.ts +3 -1
  95. package/src/servers/createFetchWithLogger.ts +75 -0
  96. package/src/servers/createFetchWithProxy.ts +12 -0
  97. package/src/servers/{createProxyFetch.ts → createFetchWithProxyByNodeFetch.ts} +6 -2
  98. package/src/servers/createFetchWithProxyByUndici.ts +36 -0
  99. package/src/servers/polyfillBrowser.test.ts +9 -9
  100. package/src/servers/polyfillCrypto.ts +3 -1
  101. package/src/servers/polyfillJsDom.ts +1 -0
  102. package/src/servers/polyfillWebSocket.ts +1 -0
  103. package/src/strings/renderTemplate.test.ts +6 -9
  104. package/src/validations/parseTimestamp.test.ts +4 -4
  105. package/dist/cjs/index-da9513d6.js +0 -13
  106. package/dist/cjs/index-da9513d6.js.map +0 -1
  107. package/dist/esm/index-c696799a.js +0 -13
  108. package/dist/esm/index-c696799a.js.map +0 -1
  109. package/dist/system/index-2dfef0f3.js +0 -13
  110. package/dist/system/index-2dfef0f3.js.map +0 -1
  111. package/lib/servers/createProxyFetch.js.map +0 -1
  112. package/src/crypto/pem/pem.test.ts.md +0 -24
  113. package/src/crypto/pem/pem.test.ts.snap +0 -0
  114. package/src/objects/get.test.ts +0 -63
@@ -1,80 +1,83 @@
1
- import test from 'ava';
1
+ import { assert, test } from 'vitest';
2
2
  import { createTranslate } from './createTranslate';
3
3
 
4
- test('exports', (t) => {
5
- const out = createTranslate();
6
- t.is(typeof out, 'object', 'returns an object');
7
- t.is(typeof out.t, 'function', '~> has "t" function');
8
- t.is(typeof out.dict, 'function', '~> has "set" function');
9
- t.is(typeof out.locale, 'function', '~> has "locale" function');
4
+ test('exports', () => {
5
+ assert.equal(typeof createTranslate, 'function', 'exports a function');
6
+
7
+ let out = createTranslate();
8
+ assert.equal(typeof out, 'object', 'returns an object');
9
+ assert.equal(typeof out.t, 'function', '~> has "t" function');
10
+ assert.equal(typeof out.dict, 'function', '~> has "dict" function');
11
+ assert.equal(typeof out.locale, 'function', '~> has "locale" function');
10
12
  });
11
13
 
12
- test('usage', (t) => {
13
- const ctx = createTranslate({
14
+ test('usage', () => {
15
+ let ctx = createTranslate({
14
16
  en: { hello: 'Hello, {{name}}!' },
15
17
  es: { hello: 'Hola {{name}}!' },
16
18
  pt: { foo: 'foo {{name}}~!' },
17
19
  });
18
20
 
19
- t.deepEqual(ctx.dict('en'), { hello: 'Hello, {{name}}!' });
21
+ assert.deepEqual(ctx.dict('en'), { hello: 'Hello, {{name}}!' });
22
+
23
+ assert.equal(ctx.dict('foobar'), undefined);
20
24
 
21
- t.true(ctx.dict('foobar') === undefined);
25
+ let foo = ctx.t('hello');
26
+ assert.equal(foo, '', '~> "" w/o locale');
22
27
 
23
- const foo = ctx.t('hello');
24
- t.is(foo, '', '~> "" w/o locale');
28
+ assert.equal(ctx.locale('en'), 'en', '>>> ctx.locale()');
25
29
 
26
- t.is(ctx.locale('en'), 'en', '>>> ctx.locale()');
30
+ assert.equal(ctx.locale(), 'en');
27
31
 
28
- t.is(ctx.locale(), 'en');
32
+ let bar = ctx.t('hello');
29
33
 
30
- const bar = ctx.t('hello');
31
- t.not(bar, '', '(en) found "hello" key');
32
- t.is(bar, 'Hello, !', '~> interpolations empty if missing param');
34
+ assert.notEqual(bar, '', '(en) found "hello" key');
35
+ assert.equal(bar, 'Hello, !', '~> interpolations empty if missing param');
33
36
 
34
- const baz = ctx.t('hello', { name: 'world' });
35
- t.is(baz, 'Hello, world!', '~> interpolations successful');
37
+ let baz = ctx.t('hello', { name: 'world' });
38
+ assert.equal(baz, 'Hello, world!', '~> interpolations successful');
36
39
 
37
- const bat = ctx.t('hello', { name: 'world' }, 'es');
38
- t.not(bat, '', '(es) found "hello" key');
39
- t.is(bat, 'Hola world!', '~> success');
40
+ let bat = ctx.t('hello', { name: 'world' }, 'es');
41
+ assert.notEqual(bat, '', '(es) found "hello" key');
42
+ assert.equal(bat, 'Hola world!', '~> success');
40
43
 
41
- t.is(ctx.t('hello', { name: 'world' }, 'pt'), '', '(pt) did NOT find "hello" key');
44
+ assert.equal(ctx.t('hello', { name: 'world' }, 'pt'), '', '(pt) did NOT find "hello" key');
42
45
 
43
- t.is(ctx.dict('pt', { hello: 'Oí {{name}}!' }), undefined, '>>> ctx.dict()');
46
+ assert.equal(ctx.dict('pt', { hello: 'Oí {{name}}!' }), undefined, '>>> ctx.set()');
44
47
 
45
- const quz = ctx.t('hello', { name: 'world' }, 'pt');
46
- t.not(quz, '', '(pt) found "hello" key');
47
- t.is(quz, 'Oí world!', '~> success');
48
+ let quz = ctx.t('hello', { name: 'world' }, 'pt');
49
+ assert.notEqual(quz, '', '(pt) found "hello" key');
50
+ assert.equal(quz, 'Oí world!', '~> success');
48
51
 
49
- const qut = ctx.t('foo', { name: 'bar' }, 'pt');
50
- t.not(qut, '', '(pt) found "foo" key');
51
- t.is(qut, 'foo bar~!', '~> success');
52
+ let qut = ctx.t('foo', { name: 'bar' }, 'pt');
53
+ assert.notEqual(qut, '', '(pt) found "foo" key');
54
+ assert.equal(qut, 'foo bar~!', '~> success');
52
55
 
53
- t.is(ctx.locale('es'), 'es', '>>> ctx.locale()');
56
+ assert.equal(ctx.locale('es'), 'es', '>>> ctx.locale()');
54
57
 
55
- t.is(ctx.locale(), 'es');
56
- t.is(ctx.locale(''), 'es');
57
- t.is(ctx.locale(false as any), 'es');
58
- t.is(ctx.locale(null as any), 'es');
59
- t.is(ctx.locale(0 as any), 'es');
58
+ assert.equal(ctx.locale(), 'es');
59
+ assert.equal(ctx.locale(''), 'es');
60
+ assert.equal(ctx.locale(false as any), 'es');
61
+ assert.equal(ctx.locale(null as any), 'es');
62
+ assert.equal(ctx.locale(0 as any), 'es');
60
63
 
61
- const qux = ctx.t('hello', { name: 'default' });
62
- t.not(qux, '', '(es) found "hello" key');
63
- t.is(qux, 'Hola default!', '~> success');
64
+ let qux = ctx.t('hello', { name: 'default' });
65
+ assert.notEqual(qux, '', '(es) found "hello" key');
66
+ assert.equal(qux, 'Hola default!', '~> success');
64
67
 
65
- t.is(ctx.t('hello', { name: 'world' }, 'de'), '', '(de) did NOT find "hello" key');
68
+ assert.equal(ctx.t('hello', { name: 'world' }, 'de'), '', '(de) did NOT find "hello" key');
66
69
 
67
- t.is(ctx.dict('de', { hello: 'Hallo {{name}}!' }), undefined, '>>> ctx.dict(de)');
70
+ assert.equal(ctx.dict('de', { hello: 'Hallo {{name}}!' }), undefined, '>>> ctx.set(de)');
68
71
 
69
- const qar = ctx.t('hello', { name: 'world' }, 'de');
70
- t.not(qar, '', '(de) found "hello" key');
71
- t.is(qar, 'Hallo world!', '~> success');
72
+ let qar = ctx.t('hello', { name: 'world' }, 'de');
73
+ assert.notEqual(qar, '', '(de) found "hello" key');
74
+ assert.equal(qar, 'Hallo world!', '~> success');
72
75
  });
73
76
 
74
- test('functional', (t) => {
75
- const ctx = createTranslate({
77
+ test('functional', () => {
78
+ let ctx = createTranslate({
76
79
  en: {
77
- hello(value: any) {
80
+ hello(value: string) {
78
81
  return `hello ${value || 'stranger'}~!`;
79
82
  },
80
83
  },
@@ -82,18 +85,18 @@ test('functional', (t) => {
82
85
 
83
86
  ctx.locale('en');
84
87
 
85
- const foo = ctx.t('hello');
86
- t.is(foo, 'hello stranger~!', '~> called function w/o param');
88
+ let foo = ctx.t('hello');
89
+ assert.equal(foo, 'hello stranger~!', '~> called function w/o param');
87
90
 
88
- const bar = ctx.t('hello', 'world' as any);
89
- t.is(bar, 'hello world~!', '~> called function w/ param (string)');
91
+ let bar = ctx.t('hello', 'world' as any);
92
+ assert.equal(bar, 'hello world~!', '~> called function w/ param (string)');
90
93
 
91
- const baz = ctx.t('hello', [1, 2, 3]);
92
- t.is(baz, 'hello 1,2,3~!', '~> called function w/ param (array)');
94
+ let baz = ctx.t('hello', [1, 2, 3]);
95
+ assert.equal(baz, 'hello 1,2,3~!', '~> called function w/ param (array)');
93
96
  });
94
97
 
95
- test('nested', (t) => {
96
- const ctx = createTranslate({
98
+ test('nested', () => {
99
+ let ctx = createTranslate({
97
100
  en: {
98
101
  fruits: {
99
102
  apple: 'apple',
@@ -111,22 +114,22 @@ test('nested', (t) => {
111
114
  });
112
115
 
113
116
  ctx.locale('en');
114
- t.is(ctx.t('fruits.apple'), 'apple', '(en) fruits.apple');
115
- t.is(ctx.t('fruits.orange'), 'orange', '(en) fruits.orange');
116
- t.is(ctx.t(['fruits', 'grape']), 'grape', '(en) ["fruits","grape"]');
117
- t.is(ctx.t('fruits.404'), '', '(en) fruits.404 ~> ""');
118
- t.is(ctx.t('error.404'), '', '(en) error.404 ~> ""');
117
+ assert.equal(ctx.t('fruits.apple'), 'apple', '(en) fruits.apple');
118
+ assert.equal(ctx.t('fruits.orange'), 'orange', '(en) fruits.orange');
119
+ assert.equal(ctx.t(['fruits', 'grape']), 'grape', '(en) ["fruits","grape"]');
120
+ assert.equal(ctx.t('fruits.404'), '', '(en) fruits.404 ~> ""');
121
+ assert.equal(ctx.t('error.404'), '', '(en) error.404 ~> ""');
119
122
 
120
123
  ctx.locale('es');
121
- t.is(ctx.t('fruits.apple'), 'manzana', '(es) fruits.apple');
122
- t.is(ctx.t('fruits.orange'), 'naranja', '(es) fruits.orange');
123
- t.is(ctx.t(['fruits', 'grape']), 'uva', '(es) ["fruits","grape"]');
124
- t.is(ctx.t('fruits.404'), '', '(es) fruits.404 ~> ""');
125
- t.is(ctx.t('error.404'), '', '(es) error.404 ~> ""');
124
+ assert.equal(ctx.t('fruits.apple'), 'manzana', '(es) fruits.apple');
125
+ assert.equal(ctx.t('fruits.orange'), 'naranja', '(es) fruits.orange');
126
+ assert.equal(ctx.t(['fruits', 'grape']), 'uva', '(es) ["fruits","grape"]');
127
+ assert.equal(ctx.t('fruits.404'), '', '(es) fruits.404 ~> ""');
128
+ assert.equal(ctx.t('error.404'), '', '(es) error.404 ~> ""');
126
129
  });
127
130
 
128
- test('arrays', (t) => {
129
- const ctx = createTranslate({
131
+ test('arrays', () => {
132
+ let ctx = createTranslate({
130
133
  en: {
131
134
  foo: '{{0}} + {{1}} = {{2}}',
132
135
  bar: [
@@ -139,32 +142,17 @@ test('arrays', (t) => {
139
142
 
140
143
  ctx.locale('en');
141
144
 
142
- t.is(ctx.t('foo', [1, 2, 3]), '1 + 2 = 3', '~> foo');
145
+ assert.equal(ctx.t('foo', [1, 2, 3]), '1 + 2 = 3', '~> foo');
143
146
 
144
- t.is(ctx.t('bar.0.baz', { colors: ['red', 'blue'] }), 'roses are red, violets are blue', '~> bar.0.baz');
147
+ assert.equal(ctx.t('bar.0.baz', { colors: ['red', 'blue'] }), 'roses are red, violets are blue', '~> bar.0.baz');
145
148
  });
146
149
 
147
- test('invalid value', (t) => {
148
- const ctx = createTranslate({
150
+ test('invalid value', () => {
151
+ let ctx = createTranslate({
149
152
  en: {
150
153
  foo: ['bar'],
151
154
  },
152
155
  });
153
156
 
154
- t.deepEqual(ctx.t('foo', null as any, 'en'), ['bar']);
155
- });
156
-
157
- test('fallback', (t) => {
158
- const ctx = createTranslate({
159
- en: {
160
- a: 'a',
161
- },
162
- 'en-US': {
163
- a: 'a-US',
164
- },
165
- });
166
-
167
- // t.deepEqual(ctx.t('a', undefined, 'en'), 'a');
168
- // t.deepEqual(ctx.t('a', undefined, 'en-US'), 'a-US');
169
- t.deepEqual(ctx.t('a', undefined, 'en-UK'), 'a');
157
+ assert.deepEqual(ctx.t('foo', null as never, 'en'), ['bar'] as any);
170
158
  });
@@ -53,11 +53,12 @@ export function createTranslate<T extends object>(obj?: Record<string, T>): Tran
53
53
  }
54
54
  if (process.env.NODE_ENV === 'development') {
55
55
  if (val == null) {
56
- return console.error(
56
+ console.error(
57
57
  `[Translate] Missing the "${[].concat(key as any).join('.')}" key within the "${
58
58
  lang || locale
59
59
  }" dictionary`,
60
60
  );
61
+ return;
61
62
  }
62
63
  }
63
64
  if (typeof val === 'function') return val(params);
package/src/index.ts CHANGED
@@ -72,6 +72,7 @@ export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
72
72
 
73
73
  // polyfills
74
74
  export { getGlobalThis } from './isomorphics/getGlobalThis';
75
+ export { globalThis } from './isomorphics/globalThis';
75
76
  export { structuredClone } from './isomorphics/structuredClone';
76
77
 
77
78
  // crypto
@@ -1,4 +1,6 @@
1
- import { expectType } from 'tsd';
1
+ import { expectTypeOf, test } from 'vitest';
2
2
  import { ArrayBuffers } from './ArrayBuffers';
3
3
 
4
- expectType<Buffer>(ArrayBuffers.asView(Buffer, new Uint8Array()));
4
+ test('my types work properly', () => {
5
+ expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).toMatchTypeOf<Buffer>();
6
+ });
@@ -1,23 +1,23 @@
1
- import test from 'ava';
1
+ import { test, beforeAll, assert, expect } from 'vitest';
2
2
  import { ArrayBuffers } from './ArrayBuffers';
3
3
 
4
- test.before((t) => {
5
- t.true(ArrayBuffers.isNativeBufferAvailable());
4
+ beforeAll(() => {
5
+ expect(ArrayBuffers.isNativeBufferAvailable()).toBeTruthy();
6
6
  ArrayBuffers.setNativeBufferAllowed(false);
7
7
  });
8
8
 
9
- test('base64: ignore whitespace', function (t) {
9
+ test('base64: ignore whitespace', function () {
10
10
  const text = '\n YW9ldQ== ';
11
11
  const buf = ArrayBuffers.from(text, 'base64');
12
- t.is(ArrayBuffers.toString(buf), 'aoeu');
12
+ expect(ArrayBuffers.toString(buf)).toBe('aoeu');
13
13
  });
14
14
 
15
- test('base64: strings without padding', function (t) {
16
- t.is(ArrayBuffers.toString(ArrayBuffers.from('YW9ldQ', 'base64')), 'aoeu');
15
+ test('base64: strings without padding', function () {
16
+ expect(ArrayBuffers.toString(ArrayBuffers.from('YW9ldQ', 'base64'))).toBe('aoeu');
17
17
  });
18
18
 
19
- test('base64: newline in utf8 -- should not be an issue', function (t) {
20
- t.is(
19
+ test('base64: newline in utf8 -- should not be an issue', function () {
20
+ assert.equal(
21
21
  ArrayBuffers.toString(
22
22
  ArrayBuffers.from('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK', 'base64'),
23
23
  'utf8',
@@ -26,8 +26,8 @@ test('base64: newline in utf8 -- should not be an issue', function (t) {
26
26
  );
27
27
  });
28
28
 
29
- test('base64: newline in base64 -- should get stripped', function (t) {
30
- t.is(
29
+ test('base64: newline in base64 -- should get stripped', function () {
30
+ assert.equal(
31
31
  ArrayBuffers.toString(
32
32
  ArrayBuffers.from(
33
33
  'LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt',
@@ -39,8 +39,8 @@ test('base64: newline in base64 -- should get stripped', function (t) {
39
39
  );
40
40
  });
41
41
 
42
- test('base64: tab characters in base64 - should get stripped', function (t) {
43
- t.is(
42
+ test('base64: tab characters in base64 - should get stripped', function () {
43
+ assert.equal(
44
44
  ArrayBuffers.toString(
45
45
  ArrayBuffers.from(
46
46
  'LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt',
@@ -52,11 +52,11 @@ test('base64: tab characters in base64 - should get stripped', function (t) {
52
52
  );
53
53
  });
54
54
 
55
- test('base64: invalid non-alphanumeric characters -- should be stripped', function (t) {
56
- t.is(ArrayBuffers.toString(ArrayBuffers.from('!"#$%&\'()*,.:;<=>?@[\\]^`{|}~', 'base64'), 'utf8'), '');
55
+ test('base64: invalid non-alphanumeric characters -- should be stripped', function () {
56
+ expect(ArrayBuffers.toString(ArrayBuffers.from('!"#$%&\'()*,.:;<=>?@[\\]^`{|}~', 'base64'), 'utf8')).toBe('');
57
57
  });
58
58
 
59
- test('base64: high byte', function (t) {
59
+ test('base64: high byte', function () {
60
60
  const highByte = ArrayBuffers.from([128]);
61
- t.deepEqual(ArrayBuffers.alloc(1, ArrayBuffers.toString(highByte, 'base64'), 'base64'), highByte);
61
+ assert.deepEqual(ArrayBuffers.alloc(1, ArrayBuffers.toString(highByte, 'base64'), 'base64'), highByte);
62
62
  });
@@ -1,23 +1,23 @@
1
- import test from 'ava';
1
+ import { test, expect } from 'vitest';
2
2
  import { ArrayBuffers } from './ArrayBuffers';
3
3
 
4
- test('concat', (t) => {
4
+ test('concat', () => {
5
5
  const check = (Type: any = Uint8Array, va = [1, 2, 3], vb = [4, 5, 6]) => {
6
6
  const a = new Type(va);
7
7
  const b = new Type(vb);
8
- t.deepEqual(ArrayBuffers.concat([a, b]), new Type([...va, ...vb]).buffer, `should concat ${Type}`);
8
+ expect(ArrayBuffers.concat([a, b]), `should concat ${Type}`).toStrictEqual(new Type([...va, ...vb]).buffer);
9
9
  };
10
10
  check(Uint8Array);
11
11
  check(Uint16Array, [0xff, 0xffff]);
12
12
  check(Uint32Array, [0xfffffff]);
13
13
  });
14
14
 
15
- test('asView for Buffer', (t) => {
15
+ test('asView for Buffer', () => {
16
16
  const buf = Buffer.from([1, 2, 3, 4, 5]);
17
- t.is(ArrayBuffers.asView(Buffer, buf), buf);
17
+ expect(ArrayBuffers.asView(Buffer, buf)).toBe(buf);
18
18
  const uint8 = ArrayBuffers.asView(Uint8Array, buf);
19
- t.is(ArrayBuffers.asView(Buffer, uint8).buffer, buf.buffer);
19
+ expect(ArrayBuffers.asView(Buffer, uint8).buffer).toBe(buf.buffer);
20
20
 
21
- t.deepEqual(uint8, buf);
22
- t.deepEqual(ArrayBuffers.asView(Buffer, uint8), buf);
21
+ expect(uint8).toEqual(buf);
22
+ expect(ArrayBuffers.asView(Buffer, uint8)).toEqual(buf);
23
23
  });
@@ -1,3 +1,4 @@
1
+ import { globalThis } from '../isomorphics/globalThis';
1
2
  import { classOf } from '../langs/classOf';
2
3
  import { decodeBase64ToArrayBuffer, encodeArrayBufferToBase64 } from './base64';
3
4
  import { isBuffer } from './isBuffer';
@@ -1,12 +1,12 @@
1
- import test from 'ava';
1
+ import { test, expect } from 'vitest';
2
2
  import { Buffer } from './Buffer';
3
3
  import { isBuffer } from './isBuffer';
4
4
 
5
- test('basic', (t) => {
5
+ test('basic', () => {
6
6
  {
7
7
  const buf = new Buffer(0);
8
- t.true(Buffer.isBuffer(buf));
9
- t.true(isBuffer(buf));
8
+ expect(Buffer.isBuffer(buf)).toBeTruthy();
9
+ expect(isBuffer(buf)).toBeTruthy();
10
10
  }
11
11
  // const b = new Buffer(10)
12
12
  // t.is(b.length,10)
@@ -1,9 +1,9 @@
1
- import test from 'ava';
2
1
  import { Buffer } from 'node:buffer';
2
+ import { expect, test } from 'vitest';
3
3
  import { classOf } from '../langs/classOf';
4
4
  import { isBuffer } from './isBuffer';
5
5
 
6
- test('isBuffer', (t) => {
7
- t.true(isBuffer(Buffer.from('')));
8
- t.is(classOf(Buffer), 'Function');
6
+ test('isBuffer', () => {
7
+ expect(isBuffer(Buffer.from(''))).toBeTruthy();
8
+ expect(classOf(Buffer)).toBe('Function');
9
9
  });
@@ -1,10 +1,11 @@
1
- import test from 'ava';
2
1
  import { Buffer } from 'node:buffer';
2
+ import { expect, test } from 'vitest';
3
3
  import { isTransferable } from './isTransferable';
4
4
 
5
- test('isTransferable', (t) => {
6
- t.false(isTransferable(0));
7
- t.false(isTransferable(Buffer.from('')));
8
- t.true(new ArrayBuffer(0) instanceof ArrayBuffer);
9
- t.true(isTransferable(new ArrayBuffer(0)));
5
+ test('isTransferable', () => {
6
+ expect(isTransferable(0)).toBeFalsy();
7
+ expect(isTransferable(Buffer.from(''))).toBeFalsy();
8
+
9
+ expect(new ArrayBuffer(0) instanceof ArrayBuffer).toBeTruthy();
10
+ expect(isTransferable(new ArrayBuffer(0))).toBeTruthy();
10
11
  });
@@ -1,3 +1,5 @@
1
+ import { globalThis } from '../isomorphics/globalThis';
2
+
1
3
  /**
2
4
  * transferable object pass between workers, can work with structuredClone
3
5
  *
@@ -5,6 +5,8 @@ declare const global: typeof globalThis;
5
5
  *
6
6
  * globalThis supported by ff 65, Chrome 71, Node 12, babel
7
7
  *
8
+ * non-standard globalThis supported for Alipay Miniprogram
9
+ *
8
10
  * @see https://caniuse.com/#search=globalThis
9
11
  * @see https://v8.dev/features/globalthis
10
12
  */
@@ -13,6 +15,6 @@ export const getGlobalThis = (): typeof globalThis => {
13
15
  if (typeof self !== 'undefined') return self;
14
16
  if (typeof window !== 'undefined') return window;
15
17
  if (typeof global !== 'undefined') return global as any;
16
- // if (typeof this !== 'undefined') return this;
18
+ if (typeof this !== 'undefined') return this as any;
17
19
  throw new Error('Unable to locate global `this`');
18
20
  };
@@ -0,0 +1,3 @@
1
+ import { getGlobalThis } from './getGlobalThis';
2
+
3
+ export const globalThis = getGlobalThis();
@@ -1,14 +1,14 @@
1
- import test from 'ava';
1
+ import { expect, test } from 'vitest';
2
2
  import { classOf } from '../langs/classOf';
3
3
  import { _clone } from './structuredClone';
4
4
 
5
- test('structuredClone', (t) => {
5
+ test('structuredClone', () => {
6
6
  for (const [k, v] of [
7
7
  ['', ''],
8
8
  [Number(1), 1],
9
9
  ]) {
10
10
  const c = _clone(k);
11
- t.deepEqual(c, v);
12
- t.is(classOf(c), classOf(v));
11
+ expect(c).toEqual(v);
12
+ expect(classOf(c)).toBe(classOf(v));
13
13
  }
14
14
  });
@@ -1,5 +1,6 @@
1
1
  /* eslint no-proto:0 */
2
2
  import { classOf } from '../langs/classOf';
3
+ import { globalThis } from './globalThis';
3
4
 
4
5
  /**
5
6
  * Clone an object using structured cloning algorithm
@@ -1,8 +1,8 @@
1
- import test from 'ava';
1
+ import { expect, test } from 'vitest';
2
2
  import { deepEqual } from './deepEqual';
3
3
 
4
- test('deep equal', (t) => {
5
- t.true(
4
+ test('deep equal', () => {
5
+ expect(
6
6
  deepEqual(
7
7
  {
8
8
  a: null,
@@ -13,5 +13,5 @@ test('deep equal', (t) => {
13
13
  b: Infinity,
14
14
  },
15
15
  ),
16
- );
16
+ ).toBeTruthy();
17
17
  });
@@ -1,7 +1,7 @@
1
- import test from 'ava';
1
+ import { expect, test } from 'vitest';
2
2
  import { classOf } from './classOf';
3
3
 
4
- test('classOf', (t) => {
4
+ test('classOf', () => {
5
5
  for (const [k, v] of [
6
6
  [0, 'Number'],
7
7
  ['', 'String'],
@@ -18,6 +18,6 @@ test('classOf', (t) => {
18
18
  [new DataView(new ArrayBuffer(0)), 'DataView'],
19
19
  [new Int8Array(0), 'Int8Array'],
20
20
  ]) {
21
- t.is(classOf(k), v as any);
21
+ expect(classOf(k)).toBe(v);
22
22
  }
23
23
  });