@takeshape/util 11.73.0 → 11.76.0

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 (71) hide show
  1. package/package.json +3 -3
  2. package/dist/common/__tests__/arrays.test.d.ts +0 -1
  3. package/dist/common/__tests__/arrays.test.js +0 -43
  4. package/dist/common/__tests__/billing.test.d.ts +0 -1
  5. package/dist/common/__tests__/billing.test.js +0 -27
  6. package/dist/common/__tests__/clone.test.d.ts +0 -1
  7. package/dist/common/__tests__/clone.test.js +0 -128
  8. package/dist/common/__tests__/data/advanced-draftjs-data-from-app.d.ts +0 -114
  9. package/dist/common/__tests__/data/advanced-draftjs-data-from-app.js +0 -316
  10. package/dist/common/__tests__/data/advanced-draftjs-from-markdown-data.d.ts +0 -160
  11. package/dist/common/__tests__/data/advanced-draftjs-from-markdown-data.js +0 -326
  12. package/dist/common/__tests__/data/advanced-draftjs-from-mdx-data.d.ts +0 -215
  13. package/dist/common/__tests__/data/advanced-draftjs-from-mdx-data.js +0 -407
  14. package/dist/common/__tests__/data/advanced-markdown-2nd-pass.d.ts +0 -1
  15. package/dist/common/__tests__/data/advanced-markdown-2nd-pass.js +0 -39
  16. package/dist/common/__tests__/data/advanced-markdown-data.d.ts +0 -1
  17. package/dist/common/__tests__/data/advanced-markdown-data.js +0 -39
  18. package/dist/common/__tests__/data/advanced-mdx-2nd-pass.d.ts +0 -1
  19. package/dist/common/__tests__/data/advanced-mdx-2nd-pass.js +0 -40
  20. package/dist/common/__tests__/data/advanced-mdx-data.d.ts +0 -1
  21. package/dist/common/__tests__/data/advanced-mdx-data.js +0 -40
  22. package/dist/common/__tests__/delay.test.d.ts +0 -1
  23. package/dist/common/__tests__/delay.test.js +0 -22
  24. package/dist/common/__tests__/draftjs.test.d.ts +0 -1
  25. package/dist/common/__tests__/draftjs.test.js +0 -373
  26. package/dist/common/__tests__/empty.test.d.ts +0 -1
  27. package/dist/common/__tests__/empty.test.js +0 -65
  28. package/dist/common/__tests__/http.test.d.ts +0 -1
  29. package/dist/common/__tests__/http.test.js +0 -13
  30. package/dist/common/__tests__/merge.test.d.ts +0 -1
  31. package/dist/common/__tests__/merge.test.js +0 -36
  32. package/dist/common/__tests__/mime.test.d.ts +0 -1
  33. package/dist/common/__tests__/mime.test.js +0 -17
  34. package/dist/common/__tests__/names.test.d.ts +0 -1
  35. package/dist/common/__tests__/names.test.js +0 -22
  36. package/dist/common/__tests__/naming.test.d.ts +0 -1
  37. package/dist/common/__tests__/naming.test.js +0 -98
  38. package/dist/common/__tests__/path-to-string.test.d.ts +0 -1
  39. package/dist/common/__tests__/path-to-string.test.js +0 -7
  40. package/dist/common/__tests__/predicate.test.d.ts +0 -1
  41. package/dist/common/__tests__/predicate.test.js +0 -18
  42. package/dist/common/__tests__/search-params.test.d.ts +0 -1
  43. package/dist/common/__tests__/search-params.test.js +0 -8
  44. package/dist/common/__tests__/sets.test.d.ts +0 -1
  45. package/dist/common/__tests__/sets.test.js +0 -13
  46. package/dist/common/__tests__/sort-object.test.d.ts +0 -1
  47. package/dist/common/__tests__/sort-object.test.js +0 -12
  48. package/dist/common/__tests__/strings.test.d.ts +0 -1
  49. package/dist/common/__tests__/strings.test.js +0 -78
  50. package/dist/common/__tests__/takeshape-id.test.d.ts +0 -1
  51. package/dist/common/__tests__/takeshape-id.test.js +0 -26
  52. package/dist/common/__tests__/templates.test.d.ts +0 -1
  53. package/dist/common/__tests__/templates.test.js +0 -220
  54. package/dist/common/__tests__/timezone.test.d.ts +0 -1
  55. package/dist/common/__tests__/timezone.test.js +0 -8
  56. package/dist/common/__tests__/types.test.d.ts +0 -1
  57. package/dist/common/__tests__/types.test.js +0 -46
  58. package/dist/common/__tests__/unix-to-iso.test.d.ts +0 -1
  59. package/dist/common/__tests__/unix-to-iso.test.js +0 -6
  60. package/dist/common/__tests__/urls.test.d.ts +0 -1
  61. package/dist/common/__tests__/urls.test.js +0 -19
  62. package/dist/common/__tests__/value.test.d.ts +0 -1
  63. package/dist/common/__tests__/value.test.js +0 -6
  64. package/dist/common/__tests__/visit.test.d.ts +0 -1
  65. package/dist/common/__tests__/visit.test.js +0 -112
  66. package/dist/node/__tests__/buffer.test.d.ts +0 -1
  67. package/dist/node/__tests__/buffer.test.js +0 -41
  68. package/dist/node/__tests__/encryption.test.d.ts +0 -1
  69. package/dist/node/__tests__/encryption.test.js +0 -14
  70. package/dist/node/__tests__/gzip.test.d.ts +0 -1
  71. package/dist/node/__tests__/gzip.test.js +0 -59
@@ -1,7 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { pathToString } from "../path-to-string.js";
3
- describe('pathToString', () => {
4
- it('path with array', () => {
5
- expect(pathToString(['apples', 2, 'color'])).toEqual('apples[2].color');
6
- });
7
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { equals, falsy, not } from "../predicate.js";
3
- test('equals', () => {
4
- const predicate = equals('foo');
5
- expect(predicate('foo')).toBe(true);
6
- expect(predicate('bar')).toBe(false);
7
- });
8
- test('not', () => {
9
- const predicate = not(equals('foo'));
10
- expect(predicate('foo')).toBe(false);
11
- expect(predicate('bar')).toBe(true);
12
- });
13
- test('falsy', () => {
14
- expect(falsy('foo')).toBe(false);
15
- expect(falsy(1)).toBe(false);
16
- expect(falsy(0)).toBe(true);
17
- expect(falsy(false)).toBe(true);
18
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { concatURLSearchParams } from "../search-params.js";
3
- test('concatURLSearchParams - concats a variety of values with ease', () => {
4
- const result = concatURLSearchParams('foo=FOO', new URLSearchParams([['bar', 'BAR']]), undefined, { baz: 'BAZ' }, [
5
- ['key', 'VALUE']
6
- ]);
7
- expect(result.toString()).toEqual('foo=FOO&bar=BAR&baz=BAZ&key=VALUE');
8
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { addAll, mapSet } from "../sets.js";
3
- test('addAll', () => {
4
- const result = new Set();
5
- addAll(result, ['a', 'b']);
6
- addAll(result, new Set(['c']));
7
- expect(result).toEqual(new Set(['a', 'b', 'c']));
8
- });
9
- test('mapSet', () => {
10
- const result = new Set(['a', 'b', 'c']);
11
- let i = 1;
12
- expect(mapSet(result, (value) => `${value}${i++}`)).toEqual(['a1', 'b2', 'c3']);
13
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { sortObject } from "../sort-object.js";
3
- describe('sortObject', () => {
4
- test('it works', () => {
5
- expect(Object.keys(sortObject({
6
- c: 1,
7
- b: 1,
8
- a: 1,
9
- d: 1
10
- }))).toEqual(['a', 'b', 'c', 'd']);
11
- });
12
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,78 +0,0 @@
1
- import { describe, expect, it, test, vi } from 'vitest';
2
- import { base64Decode, base64Encode, camelCase, encodePropertyName, formatShapeName, isIntegerLike, isUuid, pascalCase } from "../strings.js";
3
- test('camelCase - string', () => {
4
- expect(camelCase('hello world')).toBe('helloWorld');
5
- expect(camelCase('hello_world')).toBe('helloWorld');
6
- });
7
- test('camelCase - array', () => {
8
- expect(camelCase(['hello', 'world'])).toBe('helloWorld');
9
- expect(camelCase(['hello', '_world'])).toBe('helloWorld');
10
- });
11
- test('pascalCase', () => {
12
- expect(pascalCase('createPostInput')).toBe('CreatePostInput');
13
- expect(pascalCase('create_post_input')).toBe('CreatePostInput');
14
- expect(pascalCase(['create', 'post', 'input'])).toBe('CreatePostInput');
15
- // Namespace is not preserved
16
- expect(pascalCase(['create', 'TSShape', 'input'])).toBe('CreateTsShapeInput');
17
- });
18
- test('formatShapeName', () => {
19
- // Same output, non-namespaced shape name
20
- expect(formatShapeName(['create', 'post', 'input'], { shapeNameIndex: 1 })).toBe('CreatePostInput');
21
- // Non-namespaced shape name that is more complex
22
- expect(formatShapeName(['create', 'Shopify_Post', 'input'], { shapeNameIndex: 1 })).toBe('CreateShopifyPostInput');
23
- // Same output, non-namespaced shape name that is more complex
24
- expect(formatShapeName(['create', 'Shopify_Post', 'input'], { shapeNameIndex: 1 })).toBe('CreateShopifyPostInput');
25
- // Namespace is preserved
26
- expect(formatShapeName(['create', 'TSShape', 'input'], { shapeNameIndex: 1 })).toBe('CreateTSShapeInput');
27
- // Namespace is preserved when casing only a shapeName
28
- expect(formatShapeName(['TSShapeName'], { shapeNameIndex: 0 })).toBe('TSShapeName');
29
- // No change with only a shapeName, no namespace
30
- expect(formatShapeName(['ShapeName'], { shapeNameIndex: 0 })).toBe('ShapeName');
31
- // Namespace is preserved when casing only a shapeName
32
- expect(formatShapeName('TSShapeName')).toBe('TSShapeName');
33
- });
34
- test('isUuid', () => {
35
- expect(isUuid('c7522e4f-ba4e-4526-947b-49724a071e1b')).toEqual(true);
36
- expect(isUuid('bak/sql.sql')).toEqual(false);
37
- });
38
- test('isIntegerLike', () => {
39
- expect(isIntegerLike(1)).toEqual(true);
40
- expect(isIntegerLike('1')).toEqual(true);
41
- expect(isIntegerLike('a1')).toEqual(false);
42
- });
43
- describe('base64Encode', () => {
44
- it('should encode a string to base64', () => {
45
- vi.mock('browser-or-node', () => ({ isBrowser: false }));
46
- expect(base64Encode('Hello World!')).toBe('SGVsbG8gV29ybGQh');
47
- });
48
- it('should handle empty strings', () => {
49
- expect(base64Encode('')).toBe('');
50
- });
51
- });
52
- describe('base64Decode', () => {
53
- it('should decode a base64 encoded string', () => {
54
- // Mock isBrowser for consistent testing
55
- // In a real browser environment, this would not be necessary
56
- vi.mock('browser-or-node', () => ({ isBrowser: false }));
57
- expect(base64Decode('SGVsbG8gV29ybGQh')).toBe('Hello World!');
58
- });
59
- it('should handle empty strings', () => {
60
- expect(base64Decode('')).toBe('');
61
- });
62
- });
63
- describe('encodePropertyName', () => {
64
- it('should encode special characters', () => {
65
- expect(encodePropertyName('hello/world')).toBe('hello%2fworld');
66
- expect(encodePropertyName('hello world')).toBe('hello%20world');
67
- expect(encodePropertyName('hello.world')).toBe('hello%2eworld');
68
- expect(encodePropertyName('hello-world')).toBe('hello%2dworld');
69
- expect(encodePropertyName('hello_world?')).toBe('hello%5fworld%3f');
70
- expect(encodePropertyName('hello&world')).toBe('hello%26world');
71
- });
72
- it('should not encode alphanumeric characters', () => {
73
- expect(encodePropertyName('helloWorld123')).toBe('helloWorld123');
74
- });
75
- it('should handle empty strings', () => {
76
- expect(encodePropertyName('')).toBe('');
77
- });
78
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { extractTakeShapeIDs, parseTakeShapeID } from "../takeshape-id.js";
3
- describe('parseTakeShapeID', () => {
4
- test('simple example', () => {
5
- expect(parseTakeShapeID('tid:rick:Character:1')).toEqual({
6
- service: 'rick',
7
- shapeName: 'Character',
8
- id: '1'
9
- });
10
- });
11
- test('colon in the id is allowed', () => {
12
- expect(parseTakeShapeID('tid:shopify:Product:gid://shopify/Product/12345')).toEqual({
13
- service: 'shopify',
14
- shapeName: 'Product',
15
- id: 'gid://shopify/Product/12345'
16
- });
17
- });
18
- });
19
- describe('extractTakeShapeIDs', () => {
20
- test('simple example', () => {
21
- expect(extractTakeShapeIDs('Here is a cool character:\n\ntid:rick:Character:1\n\nAnd another is tid:rick:Character:2')).toEqual(['tid:rick:Character:1', 'tid:rick:Character:2']);
22
- });
23
- test('colons in the id part are allowed', () => {
24
- expect(extractTakeShapeIDs('Here is a nice product: tid:shopify:Product:gid://shopify/Product/12345\n\nHope you like it')).toEqual(['tid:shopify:Product:gid://shopify/Product/12345']);
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,220 +0,0 @@
1
- import { describe, expect, it, test } from 'vitest';
2
- import { codeTemplate, getApplyPrefix, imageTemplate, jsonTemplate, oembedTemplate } from "../templates.js";
3
- test('getApplyPrefix', () => {
4
- const applyPrefix = getApplyPrefix('prefix-');
5
- expect(applyPrefix('suffix')).toBe('prefix-suffix');
6
- expect(applyPrefix('')).toBe('');
7
- });
8
- const applyPrefix = getApplyPrefix('test-');
9
- test('imageTemplate', () => {
10
- const data = {
11
- asset: {
12
- _id: 'asset-id',
13
- path: 'path/to/image.jpg'
14
- }
15
- };
16
- const html = imageTemplate(applyPrefix, data);
17
- expect(html).toMatchSnapshot();
18
- });
19
- test('imageTemplate - no asset', () => {
20
- const data = {};
21
- const html = imageTemplate(applyPrefix, data);
22
- expect(html).toBe('');
23
- });
24
- test('imageTemplate - caption', () => {
25
- const data = {
26
- caption: 'image caption',
27
- asset: {
28
- _id: 'asset-id',
29
- path: 'path/to/image.jpg'
30
- }
31
- };
32
- const html = imageTemplate(applyPrefix, data);
33
- expect(html).toMatchSnapshot();
34
- });
35
- test('imageTemplate - credit', () => {
36
- const data = {
37
- credit: 'image credit',
38
- asset: {
39
- _id: 'asset-id',
40
- path: 'path/to/image.jpg'
41
- }
42
- };
43
- const html = imageTemplate(applyPrefix, data);
44
- expect(html).toMatchSnapshot();
45
- });
46
- test('imageTemplate - alignment', () => {
47
- const data = {
48
- alignment: 'left',
49
- asset: {
50
- _id: 'asset-id',
51
- path: 'path/to/image.jpg'
52
- }
53
- };
54
- const html = imageTemplate(applyPrefix, data);
55
- expect(html).toMatchSnapshot();
56
- });
57
- test('imageTemplate - default size', () => {
58
- const data = {
59
- asset: {
60
- _id: 'asset-id',
61
- path: 'path/to/image.jpg'
62
- },
63
- imageParams: {
64
- w: 640
65
- }
66
- };
67
- const html = imageTemplate(applyPrefix, data);
68
- expect(html).toMatchSnapshot();
69
- });
70
- test('imageTemplate - title description', () => {
71
- const data = {
72
- asset: {
73
- _id: 'asset-id',
74
- path: 'path/to/image.jpg',
75
- title: 'Title',
76
- description: '"Description"'
77
- }
78
- };
79
- const html = imageTemplate(applyPrefix, data);
80
- expect(html).toMatchSnapshot();
81
- });
82
- test('imageTemplate - link', () => {
83
- const data = {
84
- link: {
85
- url: 'https://www.google.com/',
86
- external: false
87
- },
88
- asset: {
89
- _id: 'asset-id',
90
- path: 'path/to/image.jpg'
91
- }
92
- };
93
- const html = imageTemplate(applyPrefix, data);
94
- expect(html).toMatchSnapshot();
95
- });
96
- test('imageTemplate - link external', () => {
97
- const data = {
98
- link: {
99
- url: 'https://www.google.com/',
100
- external: true
101
- },
102
- asset: {
103
- _id: 'asset-id',
104
- path: 'path/to/image.jpg'
105
- }
106
- };
107
- const html = imageTemplate(applyPrefix, data);
108
- expect(html).toMatchSnapshot();
109
- });
110
- test('oembedTemplate', () => {
111
- const data = {
112
- html: '<h1>Hello World</h1>'
113
- };
114
- const html = oembedTemplate(applyPrefix, data);
115
- expect(html).toMatchSnapshot();
116
- });
117
- test('codeTemplate', () => {
118
- const data = {
119
- text: '<h1>Hello World</h1>',
120
- lang: 'html'
121
- };
122
- const html = codeTemplate(applyPrefix, data);
123
- expect(html).toMatchSnapshot();
124
- });
125
- test('codeTemplate - no language', () => {
126
- const data = {
127
- text: '<h1>Hello World</h1>'
128
- };
129
- const html = codeTemplate(applyPrefix, data);
130
- expect(html).toMatchSnapshot();
131
- });
132
- test('codeTemplate - no language with all escaped characters', () => {
133
- const data = {
134
- text: '<script> alert("double quote"); alert(\'single quote\'); & </script>'
135
- };
136
- const html = codeTemplate(applyPrefix, data);
137
- expect(html).toMatchSnapshot();
138
- });
139
- describe('jsonTemplate', () => {
140
- it('should replace placeholders with values from context', () => {
141
- const template = {
142
- '{{name}}': '{{value}}'
143
- };
144
- const context = {
145
- name: 'foo',
146
- value: 'bar'
147
- };
148
- const result = jsonTemplate(template, context);
149
- expect(result).toEqual({ foo: 'bar' });
150
- });
151
- it('should handle nested objects and arrays', () => {
152
- const template = {
153
- '{{name}}': ['{{value}}', { nested: '{{nested}}' }],
154
- other: '{{other}}'
155
- };
156
- const context = {
157
- name: 'foo',
158
- value: 'bar',
159
- nested: 'baz',
160
- other: 'qux'
161
- };
162
- const result = jsonTemplate(template, context);
163
- expect(result).toEqual({
164
- foo: ['bar', { nested: 'baz' }],
165
- other: 'qux'
166
- });
167
- });
168
- it('should handle missing values in context', () => {
169
- const template = {
170
- '{{name}}': '{{value}}'
171
- };
172
- const context = {
173
- name: 'foo'
174
- };
175
- const result = jsonTemplate(template, context);
176
- expect(result).toEqual({ foo: '' });
177
- });
178
- it('should not modify non-string values', () => {
179
- const template = {
180
- '{{name}}': 123
181
- };
182
- const context = {
183
- name: 'foo'
184
- };
185
- const result = jsonTemplate(template, context);
186
- expect(result).toEqual({ foo: 123 });
187
- });
188
- it('should handle complex nested structures', () => {
189
- const template = {
190
- '{{name}}': [
191
- '{{value}}',
192
- {
193
- nested: {
194
- '{{deep}}': true,
195
- array: ['{{item1}}', '{{item2}}']
196
- }
197
- }
198
- ]
199
- };
200
- const context = {
201
- name: 'foo',
202
- value: 'bar',
203
- deep: 'very',
204
- item1: 'one',
205
- item2: 'two'
206
- };
207
- const result = jsonTemplate(template, context);
208
- expect(result).toEqual({
209
- foo: [
210
- 'bar',
211
- {
212
- nested: {
213
- very: true,
214
- array: ['one', 'two']
215
- }
216
- }
217
- ]
218
- });
219
- });
220
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { guessTimeZone, timeZoneList } from "../timezone.js";
3
- test('timeZoneList', () => {
4
- expect(typeof guessTimeZone()).toBe('string');
5
- });
6
- test('timeZoneList', () => {
7
- expect(timeZoneList).toMatchSnapshot();
8
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,46 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { getSingle, isNumericString, isPrimitive, isRecord, isScalar } from "../types.js";
3
- test('isRecord validates plain objects', () => {
4
- expect(isRecord({ foo: 'FOO' })).toEqual(true);
5
- expect(isRecord(['foo'])).toEqual(false);
6
- expect(isRecord(false)).toEqual(false);
7
- expect(isRecord(new Date())).toEqual(false);
8
- expect(isRecord(new Boolean(true))).toEqual(false);
9
- expect(isRecord(new Number(1))).toEqual(false);
10
- expect(isRecord(new String('abc'))).toEqual(false);
11
- });
12
- test('isPrimitive validates primitive values', () => {
13
- expect(isPrimitive(1)).toEqual(true);
14
- expect(isPrimitive(1n)).toEqual(true);
15
- expect(isPrimitive('foo')).toEqual(true);
16
- expect(isPrimitive(true)).toEqual(true);
17
- expect(isPrimitive(null)).toEqual(true);
18
- expect(isPrimitive(undefined)).toEqual(true);
19
- expect(isPrimitive(Symbol('foo'))).toEqual(true);
20
- expect(isPrimitive({ foo: 'FOO' })).toEqual(false);
21
- expect(isPrimitive(['foo'])).toEqual(false);
22
- });
23
- test('isScalar validates scalar values', () => {
24
- expect(isScalar(1)).toEqual(true);
25
- expect(isScalar(1n)).toEqual(true);
26
- expect(isScalar('foo')).toEqual(true);
27
- expect(isScalar(true)).toEqual(true);
28
- expect(isScalar(null)).toEqual(false);
29
- expect(isScalar(undefined)).toEqual(false);
30
- expect(isScalar(Symbol('foo'))).toEqual(false);
31
- expect(isScalar({ foo: 'FOO' })).toEqual(false);
32
- expect(isScalar(['foo'])).toEqual(false);
33
- });
34
- test('getSingle returns a single item', () => {
35
- expect(getSingle(1)).toEqual(1);
36
- expect(getSingle([1, 2, 3])).toEqual(1);
37
- expect(getSingle('foo')).toEqual('foo');
38
- expect(getSingle(['foo', 'bar'])).toEqual('foo');
39
- expect(getSingle()).toBeUndefined();
40
- });
41
- test('isNumericString validates numeric strings', () => {
42
- expect(isNumericString('9')).toEqual(true);
43
- expect(isNumericString('9.9')).toEqual(true);
44
- expect(isNumericString('nine')).toEqual(false);
45
- expect(isNumericString('nine9')).toEqual(false);
46
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { unixToISO } from "../unix-to-iso.js";
3
- test('unixToISO', () => {
4
- expect(unixToISO(1594657725)).toEqual('2020-07-13T16:28:45.000Z');
5
- expect(unixToISO(0)).toEqual('1970-01-01T00:00:00.000Z');
6
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { getFileName } from "../urls.js";
3
- describe('getFileName', () => {
4
- test('http url', () => {
5
- expect(getFileName('https://example.com/path/to/file.txt')).toBe('file.txt');
6
- });
7
- test('http url with hash', () => {
8
- expect(getFileName('https://example.com/path/to/file.txt#foo')).toBe('file.txt');
9
- });
10
- test('s3 url', () => {
11
- expect(getFileName('s3://path/to/file.txt')).toBe('file.txt');
12
- });
13
- test('path', () => {
14
- expect(getFileName('foo/bar/baz/file.txt')).toBe('file.txt');
15
- });
16
- test('filename', () => {
17
- expect(getFileName('file.txt')).toBe('file.txt');
18
- });
19
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { value } from "../value.js";
3
- test('value', () => {
4
- const expected = 'abc';
5
- expect(value(expected)()).toBe(expected);
6
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,112 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { visit, visitJsonPath } from "../visit.js";
3
- test('visit - can visit deeply nested objects and arrays', () => {
4
- const tree = {
5
- a: {
6
- b: {
7
- ignore: 'me',
8
- c: {
9
- d: [{ name: 'foo' }, { '@name': 'bar' }],
10
- e: {
11
- name: 'baz'
12
- }
13
- }
14
- }
15
- }
16
- };
17
- const results = [];
18
- visit(tree, ['name', '@name'], (val, path) => {
19
- results.push([val, path]);
20
- });
21
- expect(results).toEqual([
22
- ['foo', ['a', 'b', 'c', 'd', '0', 'name']],
23
- ['bar', ['a', 'b', 'c', 'd', '1', '@name']],
24
- ['baz', ['a', 'b', 'c', 'e', 'name']]
25
- ]);
26
- });
27
- describe('visitJsonPath', () => {
28
- const tree = {
29
- a: {
30
- b: {
31
- c: {
32
- d: [{ name: 'foo' }, { '@name': 'kitty' }],
33
- e: {
34
- name: 'tag',
35
- id: 1
36
- }
37
- }
38
- }
39
- },
40
- b: {
41
- b: {
42
- c: {
43
- z: [{ name: 'bar' }, { '@name': 'puppy' }],
44
- e: {
45
- name: 'tag',
46
- id: 2
47
- }
48
- }
49
- }
50
- },
51
- c: {
52
- b: {
53
- c: {
54
- d: [{ name: 'baz' }, { '@name': 'bunny' }],
55
- e: {
56
- name: 'tag',
57
- id: 3
58
- }
59
- }
60
- },
61
- d: {
62
- z: {
63
- '@name': 'alsomatches'
64
- }
65
- }
66
- }
67
- };
68
- test('callback called with multiple JSONPath-like paths, including wildcards', () => {
69
- const results = [];
70
- visitJsonPath(tree, ['c.z.*.name', 'c.d.*.@name'], (val, path, foundIndex) => {
71
- results.push([val, path, foundIndex]);
72
- });
73
- expect(results).toEqual([
74
- ['kitty', ['a', 'b', 'c', 'd', '1', '@name'], 1],
75
- ['bar', ['b', 'b', 'c', 'z', '0', 'name'], 0],
76
- ['bunny', ['c', 'b', 'c', 'd', '1', '@name'], 1],
77
- ['alsomatches', ['c', 'd', 'z', '@name'], 1]
78
- ]);
79
- });
80
- test('callback called three times without root-anchored paths', () => {
81
- const results = [];
82
- visitJsonPath(tree, ['c.d'], (val, path, foundIndex) => {
83
- results.push([val, path, foundIndex]);
84
- });
85
- expect(results).toEqual([
86
- [[{ name: 'foo' }, { '@name': 'kitty' }], ['a', 'b', 'c', 'd'], 0],
87
- [[{ name: 'baz' }, { '@name': 'bunny' }], ['c', 'b', 'c', 'd'], 0],
88
- [{ z: { '@name': 'alsomatches' } }, ['c', 'd'], 0]
89
- ]);
90
- });
91
- test('callback called once with root-anchored paths', () => {
92
- const results = [];
93
- visitJsonPath(tree, ['$.c.d'], (val, path, foundIndex) => {
94
- results.push([val, path, foundIndex]);
95
- });
96
- expect(results).toEqual([[{ z: { '@name': 'alsomatches' } }, ['c', 'd'], 0]]);
97
- });
98
- test('callback called with a short path and terminal wildcard', () => {
99
- const results = [];
100
- visitJsonPath(tree, ['e.*'], (val, path, foundIndex) => {
101
- results.push([val, path, foundIndex]);
102
- });
103
- expect(results).toEqual([
104
- ['tag', ['a', 'b', 'c', 'e', 'name'], 0],
105
- [1, ['a', 'b', 'c', 'e', 'id'], 0],
106
- ['tag', ['b', 'b', 'c', 'e', 'name'], 0],
107
- [2, ['b', 'b', 'c', 'e', 'id'], 0],
108
- ['tag', ['c', 'b', 'c', 'e', 'name'], 0],
109
- [3, ['c', 'b', 'c', 'e', 'id'], 0]
110
- ]);
111
- });
112
- });
@@ -1 +0,0 @@
1
- export {};