@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,373 +0,0 @@
1
- import { beforeEach, describe, expect, test, vi } from 'vitest';
2
- import { adjustRanges, draftjsToMd, draftjsToMdx, encodeHtmlEntities, insertBreaksAroundBlocks, mdToDraftjs, mdxToDraftjs } from "../draftjs.js";
3
- import { data as originalDraftjs } from "./data/advanced-draftjs-data-from-app.js";
4
- import { data as draftjsFromMarkdown } from "./data/advanced-draftjs-from-markdown-data.js";
5
- import { data as draftjsFromMdx } from "./data/advanced-draftjs-from-mdx-data.js";
6
- import { data as markdown2 } from "./data/advanced-markdown-2nd-pass.js";
7
- import { data as markdown } from "./data/advanced-markdown-data.js";
8
- import { data as mdx2 } from "./data/advanced-mdx-2nd-pass.js";
9
- import { data as mdx } from "./data/advanced-mdx-data.js";
10
- let mockId = 0;
11
- vi.mock('shortid', () => ({
12
- __esModule: true,
13
- default: {
14
- generate() {
15
- mockId++;
16
- return `shortid${mockId}`;
17
- }
18
- }
19
- }));
20
- beforeEach(() => {
21
- mockId = 0;
22
- });
23
- const assets = {
24
- '92d98a89-52c1-4761-a4f5-1cc3463f3c0f': {
25
- _id: '92d98a89-52c1-4761-a4f5-1cc3463f3c0f',
26
- title: null,
27
- description: null,
28
- path: '7b508a95-738b-4a65-9567-1c8d98009888/dev/92d98a89-52c1-4761-a4f5-1cc3463f3c0f/file.png'
29
- },
30
- '885f34b5-8dea-483a-8909-c50b9932862c': {
31
- _id: '92d98a89-52c1-4761-a4f5-1cc3463f3c0f',
32
- title: null,
33
- description: null,
34
- path: '7b508a95-738b-4a65-9567-1c8d98009888/dev/885f34b5-8dea-483a-8909-c50b9932862c/file.png'
35
- },
36
- 'a251340c-e8c0-4df7-b38b-51dc7a9d6a44': {
37
- _id: '92d98a89-52c1-4761-a4f5-1cc3463f3c0f',
38
- title: null,
39
- description: null,
40
- path: '7b508a95-738b-4a65-9567-1c8d98009888/dev/a251340c-e8c0-4df7-b38b-51dc7a9d6a44/file.png',
41
- caption: {
42
- blocks: [
43
- {
44
- key: '8mtik',
45
- text: 'Asset Caption',
46
- type: 'unstyled',
47
- depth: 0,
48
- inlineStyleRanges: [],
49
- entityRanges: [],
50
- data: {}
51
- }
52
- ],
53
- entityMap: {}
54
- },
55
- credit: {
56
- blocks: [
57
- {
58
- key: 'b0f5b',
59
- text: 'Asset Credit',
60
- type: 'unstyled',
61
- depth: 0,
62
- inlineStyleRanges: [],
63
- entityRanges: [],
64
- data: {}
65
- }
66
- ],
67
- entityMap: {}
68
- }
69
- }
70
- };
71
- describe('converting back and forth', () => {
72
- // The input for these is the draftjs generated by our app
73
- test('draftjs to md', () => {
74
- expect(draftjsToMd(originalDraftjs, assets)).toEqual(markdown);
75
- });
76
- test('draftjs to mdx', () => {
77
- expect(draftjsToMdx(originalDraftjs, assets)).toEqual(mdx);
78
- });
79
- // These do not recreate the original draftjs exactly, but it should be equivalent
80
- test('md to draftjs', () => {
81
- // Uncomment to regenerate draftjs
82
- // console.log(JSON.stringify(mdToDraftjs(markdown), null, 2));
83
- expect(mdToDraftjs(markdown)).toEqual(draftjsFromMarkdown);
84
- });
85
- test('mdx to draftjs', () => {
86
- // Uncomment to regenerate draftjs
87
- // console.log(JSON.stringify(mdxToDraftjs(mdx), null, 2));
88
- expect(mdxToDraftjs(mdx)).toEqual(draftjsFromMdx);
89
- });
90
- // If you convert back again, you get the same thing but with captions from the asset data
91
- test('generating markdown from draftjs that was generated from markdown', () => {
92
- expect(draftjsToMd(draftjsFromMarkdown, assets)).toEqual(markdown2);
93
- });
94
- test('generating mdx from draftjs that was generated from mdx', () => {
95
- expect(draftjsToMdx(draftjsFromMdx, assets)).toEqual(mdx2);
96
- });
97
- // Now if you convert back again you get the same thing, closing the loop
98
- test('generating draftjs from markdown generated from draftjs', () => {
99
- expect(mdToDraftjs(markdown2)).toEqual(draftjsFromMarkdown);
100
- });
101
- test('generating draftjs from mdx generated from draftjs', () => {
102
- expect(mdxToDraftjs(mdx2)).toEqual(draftjsFromMdx);
103
- });
104
- });
105
- describe('draftjsToMd', () => {
106
- test('Mystery html is stripped from md', () => {
107
- expect(draftjsToMd(mdToDraftjs('<canvas>text</canvas>'), {})).toEqual('');
108
- });
109
- test('Text-like html in md is output as text', () => {
110
- expect(draftjsToMd(mdToDraftjs('<span>text</span>'), {})).toEqual('text');
111
- });
112
- test('Figures in md that do not match our image html are stripped', () => {
113
- expect(draftjsToMd(mdToDraftjs('<figure></figure>'), {})).toEqual('');
114
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#">hi :)</a></figure>`), {})).toEqual('');
115
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#"><h1>Hello</h1></a><figcaption>Nice image!</figcaption></figure>`), {})).toEqual('');
116
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#"><img src="https://images.dev.takeshape.io/7b508a95-738b-4a65-9567-1c8d98009888/dev/a251340c-e8c0-4df7-b38b-51dc7a9d6a44/file.png"/></a><figcaption>Nice image!</figcaption></figure>`), {})).toEqual(' ');
117
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#"><img src="https://images.dev.takeshape.io/7b508a95-738b-4a65-9567-1c8d98009888/dev/a251340c-e8c0-4df7-b38b-51dc7a9d6a44/file.png"/></a><figcaption><span class="caption">Nice image!</span></figcaption></figure>`), {})).toEqual(' ');
118
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#"><img src="https://images.dev.takeshape.io/7b508a95-738b-4a65-9567-1c8d98009888/dev/a251340c-e8c0-4df7-b38b-51dc7a9d6a44/file.png"/></a><figcaption><span class="caption"><p>Nice image!</p></span></figcaption></figure>`), {})).toEqual(' ');
119
- expect(draftjsToMd(mdToDraftjs(`<figure><a href="#"><img src="https://images.dev.takeshape.io/7b508a95-738b-4a65-9567-1c8d98009888/dev/a251340c-e8c0-4df7-b38b-51dc7a9d6a44/file.png"/></a><figcaption><span class="caption"><p>Nice image!</p></span> <span class="credit">You</span></figcaption></figure>`), {})).toEqual(' ');
120
- });
121
- test('Alleged oembeds in md that do not match known ombed html are stripped', () => {
122
- expect(draftjsToMd(mdToDraftjs(`<div class="oembed"></div>`), {})).toEqual('');
123
- expect(draftjsToMd(mdToDraftjs(`<div class="oembed"><blockquote>content</blockquote></div>`), {})).toEqual('');
124
- });
125
- test('Pullquote without text in md is stripped', () => {
126
- expect(draftjsToMd(mdToDraftjs(`<aside style="font-style: italic; margin: 2em 2.5em;"></aside>`), {})).toEqual('');
127
- });
128
- });
129
- describe('insertBreaksAroundBlocks', () => {
130
- test('two hrs', () => {
131
- expect(insertBreaksAroundBlocks(`***
132
-
133
- ***
134
-
135
- `)).toEqual(`<br/>
136
-
137
- ***
138
-
139
- <br/>
140
-
141
- ***
142
-
143
- <br/>`);
144
- });
145
- test('two images', () => {
146
- expect(insertBreaksAroundBlocks(` <TSImage id="dd9a8fee-31f8-4922-a940-4e17f21a6add" caption="Asset Caption" credit="Asset Credit" link="" linkIsExternal="" alignment="" size="" src="https://images.dev.takeshape.io/09525fbb-a270-4970-bfd0-3f8c727f8a5c/dev/dd9a8fee-31f8-4922-a940-4e17f21a6add/Screen%20Shot%202021-07-20%20at%2011.57.30%20AM.png"/>
147
-
148
- <TSImage id="dd9a8fee-31f8-4922-a940-4e17f21a6add" caption="" credit="" link="" linkIsExternal="" alignment="" size="" src="https://images.dev.takeshape.io/09525fbb-a270-4970-bfd0-3f8c727f8a5c/dev/dd9a8fee-31f8-4922-a940-4e17f21a6add/Screen%20Shot%202021-07-20%20at%2011.57.30%20AM.png"/>
149
-
150
- `)).toEqual(`<br/>
151
-
152
- <TSImage id="dd9a8fee-31f8-4922-a940-4e17f21a6add" caption="Asset Caption" credit="Asset Credit" link="" linkIsExternal="" alignment="" size="" src="https://images.dev.takeshape.io/09525fbb-a270-4970-bfd0-3f8c727f8a5c/dev/dd9a8fee-31f8-4922-a940-4e17f21a6add/Screen%20Shot%202021-07-20%20at%2011.57.30%20AM.png"/>
153
-
154
- <br/>
155
-
156
- <TSImage id="dd9a8fee-31f8-4922-a940-4e17f21a6add" caption="" credit="" link="" linkIsExternal="" alignment="" size="" src="https://images.dev.takeshape.io/09525fbb-a270-4970-bfd0-3f8c727f8a5c/dev/dd9a8fee-31f8-4922-a940-4e17f21a6add/Screen%20Shot%202021-07-20%20at%2011.57.30%20AM.png"/>
157
-
158
- <br/>`);
159
- });
160
- test('two oembeds', () => {
161
- expect(insertBreaksAroundBlocks(` <TSOembed url="https://twitter.com/DailyGuineaLips/status/1457772592027238407" author_name="Guinea Pig Lips" author_url="https://twitter.com/DailyGuineaLips" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
162
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Someone… please… rub my snoot 😭 <br><br>Pic sent by <a href="https://twitter.com/maisonDesChons?ref_src=twsrc%5Etfw">@maisonDesChons</a> <a href="https://twitter.com/hashtag/guineapig?src=hash&amp;ref_src=twsrc%5Etfw">#guineapig</a> <a href="https://twitter.com/hashtag/cavy?src=hash&amp;ref_src=twsrc%5Etfw">#cavy</a> <a href="https://twitter.com/hashtag/guineapiglips?src=hash&amp;ref_src=twsrc%5Etfw">#guineapiglips</a> <a href="https://t.co/qAA1xuxqwi">pic.twitter.com/qAA1xuxqwi</a></p>&mdash; Guinea Pig Lips (@DailyGuineaLips) <a href="https://twitter.com/DailyGuineaLips/status/1457772592027238407?ref_src=twsrc%5Etfw">November 8, 2021</a></blockquote>
163
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
164
- </TSOembed>
165
-
166
- <TSOembed url="https://twitter.com/DailyGuineaLips/status/1457772592027238407" author_name="Guinea Pig Lips" author_url="https://twitter.com/DailyGuineaLips" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
167
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Someone… please… rub my snoot 😭 <br><br>Pic sent by <a href="https://twitter.com/maisonDesChons?ref_src=twsrc%5Etfw">@maisonDesChons</a> <a href="https://twitter.com/hashtag/guineapig?src=hash&amp;ref_src=twsrc%5Etfw">#guineapig</a> <a href="https://twitter.com/hashtag/cavy?src=hash&amp;ref_src=twsrc%5Etfw">#cavy</a> <a href="https://twitter.com/hashtag/guineapiglips?src=hash&amp;ref_src=twsrc%5Etfw">#guineapiglips</a> <a href="https://t.co/qAA1xuxqwi">pic.twitter.com/qAA1xuxqwi</a></p>&mdash; Guinea Pig Lips (@DailyGuineaLips) <a href="https://twitter.com/DailyGuineaLips/status/1457772592027238407?ref_src=twsrc%5Etfw">November 8, 2021</a></blockquote>
168
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
169
- </TSOembed>
170
-
171
- `)).toEqual(`<br/>
172
-
173
- <TSOembed url="https://twitter.com/DailyGuineaLips/status/1457772592027238407" author_name="Guinea Pig Lips" author_url="https://twitter.com/DailyGuineaLips" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
174
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Someone… please… rub my snoot 😭 <br><br>Pic sent by <a href="https://twitter.com/maisonDesChons?ref_src=twsrc%5Etfw">@maisonDesChons</a> <a href="https://twitter.com/hashtag/guineapig?src=hash&amp;ref_src=twsrc%5Etfw">#guineapig</a> <a href="https://twitter.com/hashtag/cavy?src=hash&amp;ref_src=twsrc%5Etfw">#cavy</a> <a href="https://twitter.com/hashtag/guineapiglips?src=hash&amp;ref_src=twsrc%5Etfw">#guineapiglips</a> <a href="https://t.co/qAA1xuxqwi">pic.twitter.com/qAA1xuxqwi</a></p>&mdash; Guinea Pig Lips (@DailyGuineaLips) <a href="https://twitter.com/DailyGuineaLips/status/1457772592027238407?ref_src=twsrc%5Etfw">November 8, 2021</a></blockquote>
175
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
176
- </TSOembed>
177
-
178
- <br/>
179
-
180
- <TSOembed url="https://twitter.com/DailyGuineaLips/status/1457772592027238407" author_name="Guinea Pig Lips" author_url="https://twitter.com/DailyGuineaLips" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
181
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Someone… please… rub my snoot 😭 <br><br>Pic sent by <a href="https://twitter.com/maisonDesChons?ref_src=twsrc%5Etfw">@maisonDesChons</a> <a href="https://twitter.com/hashtag/guineapig?src=hash&amp;ref_src=twsrc%5Etfw">#guineapig</a> <a href="https://twitter.com/hashtag/cavy?src=hash&amp;ref_src=twsrc%5Etfw">#cavy</a> <a href="https://twitter.com/hashtag/guineapiglips?src=hash&amp;ref_src=twsrc%5Etfw">#guineapiglips</a> <a href="https://t.co/qAA1xuxqwi">pic.twitter.com/qAA1xuxqwi</a></p>&mdash; Guinea Pig Lips (@DailyGuineaLips) <a href="https://twitter.com/DailyGuineaLips/status/1457772592027238407?ref_src=twsrc%5Etfw">November 8, 2021</a></blockquote>
182
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
183
- </TSOembed>
184
-
185
- <br/>`);
186
- });
187
- test('oembed then code block', () => {
188
- expect(insertBreaksAroundBlocks(` <TSOembed url="https://twitter.com/LOLPigs/status/1438916810582155271" author_name="Guinea Pigs" author_url="https://twitter.com/LOLPigs" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
189
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">&quot;Was that the fridge?&quot;🍅🥒🥕🫑 <a href="https://twitter.com/hashtag/Snacks?src=hash&amp;ref_src=twsrc%5Etfw">#Snacks</a> <a href="https://twitter.com/hashtag/FridayFeeling?src=hash&amp;ref_src=twsrc%5Etfw">#FridayFeeling</a> <a href="https://twitter.com/hashtag/FridayVibes?src=hash&amp;ref_src=twsrc%5Etfw">#FridayVibes</a> <a href="https://twitter.com/hashtag/guineapigs?src=hash&amp;ref_src=twsrc%5Etfw">#guineapigs</a> <a href="https://t.co/6fYafcaQyb">pic.twitter.com/6fYafcaQyb</a></p>&mdash; Guinea Pigs (@LOLPigs) <a href="https://twitter.com/LOLPigs/status/1438916810582155271?ref_src=twsrc%5Etfw">September 17, 2021</a></blockquote>
190
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
191
- </TSOembed>
192
-
193
- \`\`\`javascript
194
- const foo = 5;
195
- \`\`\``)).toEqual(`<br/>
196
-
197
- <TSOembed url="https://twitter.com/LOLPigs/status/1438916810582155271" author_name="Guinea Pigs" author_url="https://twitter.com/LOLPigs" width="550" height="" type="rich" cache_age="3153600000" provider_name="Twitter" version="1.0">
198
- <blockquote class="twitter-tweet"><p lang="en" dir="ltr">&quot;Was that the fridge?&quot;🍅🥒🥕🫑 <a href="https://twitter.com/hashtag/Snacks?src=hash&amp;ref_src=twsrc%5Etfw">#Snacks</a> <a href="https://twitter.com/hashtag/FridayFeeling?src=hash&amp;ref_src=twsrc%5Etfw">#FridayFeeling</a> <a href="https://twitter.com/hashtag/FridayVibes?src=hash&amp;ref_src=twsrc%5Etfw">#FridayVibes</a> <a href="https://twitter.com/hashtag/guineapigs?src=hash&amp;ref_src=twsrc%5Etfw">#guineapigs</a> <a href="https://t.co/6fYafcaQyb">pic.twitter.com/6fYafcaQyb</a></p>&mdash; Guinea Pigs (@LOLPigs) <a href="https://twitter.com/LOLPigs/status/1438916810582155271?ref_src=twsrc%5Etfw">September 17, 2021</a></blockquote>
199
- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
200
- </TSOembed>
201
-
202
- <br/>
203
-
204
- \`\`\`javascript
205
- const foo = 5;
206
- \`\`\`
207
-
208
- <br/>`);
209
- });
210
- });
211
- describe('adjustEntityRanges', () => {
212
- test('it works', () => {
213
- expect(adjustRanges([
214
- {
215
- offset: 5,
216
- length: 2,
217
- key: 0
218
- },
219
- {
220
- offset: 10,
221
- length: 2,
222
- key: 0
223
- },
224
- {
225
- offset: 15,
226
- length: 2,
227
- key: 0
228
- }
229
- ], 11, 2)).toEqual([
230
- {
231
- offset: 5,
232
- length: 2,
233
- key: 0
234
- },
235
- {
236
- offset: 10,
237
- length: 4,
238
- key: 0
239
- },
240
- {
241
- offset: 17,
242
- length: 2,
243
- key: 0
244
- }
245
- ]);
246
- });
247
- });
248
- describe('encodeHtmlEntities', () => {
249
- const createEntities = (text, offset, length) => ({
250
- blocks: [
251
- {
252
- key: '8vpit',
253
- text,
254
- type: 'unstyled',
255
- depth: 0,
256
- inlineStyleRanges: [],
257
- entityRanges: [
258
- {
259
- offset,
260
- length,
261
- key: 0
262
- }
263
- ],
264
- data: {}
265
- }
266
- ],
267
- entityMap: {
268
- '0': {
269
- type: 'LINK',
270
- mutability: 'MUTABLE',
271
- data: {
272
- url: 'https://example.com',
273
- target: '_blank'
274
- }
275
- }
276
- }
277
- });
278
- test('apostraphes around link', () => {
279
- expect(encodeHtmlEntities(createEntities("Dog's Cat's LINK Dog's Cat's", 12, 4)).blocks).toEqual([
280
- {
281
- key: '8vpit',
282
- text: 'Dog&#x27;s Cat&#x27;s LINK Dog&#x27;s Cat&#x27;s',
283
- type: 'unstyled',
284
- depth: 0,
285
- inlineStyleRanges: [],
286
- entityRanges: [
287
- {
288
- offset: 22,
289
- length: 4,
290
- key: 0
291
- }
292
- ],
293
- data: {}
294
- }
295
- ]);
296
- });
297
- test('apostraphe in link as well as around', () => {
298
- expect(encodeHtmlEntities(createEntities("Dog's Cat's LI'NK Dog's Cat's", 12, 5)).blocks).toEqual([
299
- {
300
- key: '8vpit',
301
- text: 'Dog&#x27;s Cat&#x27;s LI&#x27;NK Dog&#x27;s Cat&#x27;s',
302
- type: 'unstyled',
303
- depth: 0,
304
- inlineStyleRanges: [],
305
- entityRanges: [
306
- {
307
- offset: 22,
308
- length: 10,
309
- key: 0
310
- }
311
- ],
312
- data: {}
313
- }
314
- ]);
315
- });
316
- test('apostraphe hell', () => {
317
- expect(encodeHtmlEntities(createEntities("'''''''''", 3, 3)).blocks).toEqual([
318
- {
319
- key: '8vpit',
320
- text: '&#x27;&#x27;&#x27;&#x27;&#x27;&#x27;&#x27;&#x27;&#x27;',
321
- type: 'unstyled',
322
- depth: 0,
323
- inlineStyleRanges: [],
324
- entityRanges: [
325
- {
326
- offset: 18,
327
- length: 18,
328
- key: 0
329
- }
330
- ],
331
- data: {}
332
- }
333
- ]);
334
- });
335
- test('inline style ranges are also adjusted', () => {
336
- expect(encodeHtmlEntities({
337
- blocks: [
338
- {
339
- key: 'ag2kc',
340
- text: "Bold's boldness is very bold. That text is bold, this text is not.",
341
- type: 'unstyled',
342
- depth: 0,
343
- inlineStyleRanges: [
344
- {
345
- offset: 0,
346
- length: 29,
347
- style: 'BOLD'
348
- }
349
- ],
350
- entityRanges: [],
351
- data: {}
352
- }
353
- ],
354
- entityMap: {}
355
- }).blocks).toEqual([
356
- {
357
- key: 'ag2kc',
358
- text: 'Bold&#x27;s boldness is very bold. That text is bold, this text is not.',
359
- type: 'unstyled',
360
- depth: 0,
361
- inlineStyleRanges: [
362
- {
363
- offset: 0,
364
- length: 34,
365
- style: 'BOLD'
366
- }
367
- ],
368
- entityRanges: [],
369
- data: {}
370
- }
371
- ]);
372
- });
373
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,65 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { isDeepEmpty } from "../empty.js";
3
- describe('isDeepEmpty', () => {
4
- test('should return true for empty string', () => {
5
- expect(isDeepEmpty('')).toBe(true);
6
- });
7
- test('should return true for string with only spaces', () => {
8
- expect(isDeepEmpty(' ')).toBe(true);
9
- });
10
- test('should return false for non-empty string', () => {
11
- expect(isDeepEmpty('hello')).toBe(false);
12
- });
13
- test('should return true for empty array', () => {
14
- expect(isDeepEmpty([])).toBe(true);
15
- });
16
- test('should return true for array with only empty values', () => {
17
- expect(isDeepEmpty(['', [], {}])).toBe(true);
18
- });
19
- test('should return false for array with non-empty values', () => {
20
- expect(isDeepEmpty(['hello', [], {}])).toBe(false);
21
- });
22
- test('should return true for empty Map', () => {
23
- expect(isDeepEmpty(new Map())).toBe(true);
24
- });
25
- test('should return true for Map with only empty values', () => {
26
- const map = new Map();
27
- map.set('key1', '');
28
- map.set('key2', []);
29
- expect(isDeepEmpty(map)).toBe(true);
30
- });
31
- test('should return false for Map with non-empty values', () => {
32
- const map = new Map();
33
- map.set('key1', 'value');
34
- expect(isDeepEmpty(map)).toBe(false);
35
- });
36
- test('should return true for empty Set', () => {
37
- expect(isDeepEmpty(new Set())).toBe(true);
38
- });
39
- test('should return true for Set with only empty values', () => {
40
- const set = new Set();
41
- set.add('');
42
- set.add([]);
43
- expect(isDeepEmpty(set)).toBe(true);
44
- });
45
- test('should return false for Set with non-empty values', () => {
46
- const set = new Set();
47
- set.add('value');
48
- expect(isDeepEmpty(set)).toBe(false);
49
- });
50
- test('should return true for null', () => {
51
- expect(isDeepEmpty(null)).toBe(true);
52
- });
53
- test('should return true for undefined', () => {
54
- expect(isDeepEmpty(undefined)).toBe(true);
55
- });
56
- test('should return true for empty object', () => {
57
- expect(isDeepEmpty({})).toBe(true);
58
- });
59
- test('should return true for object with only empty values', () => {
60
- expect(isDeepEmpty({ key1: '', key2: [] })).toBe(true);
61
- });
62
- test('should return false for object with non-empty values', () => {
63
- expect(isDeepEmpty({ key1: 'value' })).toBe(false);
64
- });
65
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { getBasicAuthString } from "../http.js";
3
- function base64String(s) {
4
- return Buffer.from(s).toString('base64');
5
- }
6
- test('getBasicAuthString', () => {
7
- const username = 'foo';
8
- const password = 'bar';
9
- expect(getBasicAuthString({ username, password })).toEqual(base64String('foo:bar'));
10
- expect(getBasicAuthString({ username })).toEqual(base64String('foo:'));
11
- expect(getBasicAuthString({ password })).toEqual(base64String(':bar'));
12
- expect(getBasicAuthString({})).toEqual(base64String(':'));
13
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { rebaseArray, rebaseObject } from "../merge.js";
3
- describe('rebaseArray', () => {
4
- test('preserves order', () => {
5
- const base = ['a', 'b'];
6
- const to = ['a', 'b', 'c'];
7
- const from = ['a', 'b', 'd'];
8
- expect(rebaseArray(to, base, from)).toEqual(['a', 'b', 'c', 'd']);
9
- });
10
- test('removes items', () => {
11
- const base = ['a', 'b', 'c'];
12
- const to = ['a', 'b', 'c', 'd'];
13
- const from = ['a', 'b', 'e'];
14
- expect(rebaseArray(to, base, from)).toEqual(['a', 'b', 'd', 'e']);
15
- });
16
- test('removes duplicates', () => {
17
- const base = ['a', 'b', 'b'];
18
- const to = ['a', 'b', 'b', 'c'];
19
- const from = ['a', 'b', 'd'];
20
- expect(rebaseArray(to, base, from)).toEqual(['a', 'b', 'c', 'd']);
21
- });
22
- });
23
- describe('rebaseObject', () => {
24
- test('base case', () => {
25
- const base = {};
26
- const to = {};
27
- const from = { a: 1, b: 2, c: 3 };
28
- expect(rebaseObject(to, base, from)).toEqual(from);
29
- });
30
- test('handles removing', () => {
31
- const base = { a: 'base', c: 'base' };
32
- const to = { a: 'to', b: 'to', c: 'base' };
33
- const from = { a: 'from' };
34
- expect(rebaseObject(to, base, from)).toEqual({ a: 'from', b: 'to' });
35
- });
36
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { contentType, shouldCompress } from "../mime.js";
3
- test('shouldCompress', () => {
4
- expect(shouldCompress('path/to/foo.json')).toBe(true);
5
- expect(shouldCompress('path/to/foo.html')).toBe(true);
6
- expect(shouldCompress('path/to/foo.eot')).toBe(true);
7
- expect(shouldCompress('path/to/foo.otf')).toBe(true);
8
- expect(shouldCompress('path/to/foo.xml')).toBe(true);
9
- expect(shouldCompress('path/to/foo.woff')).toBe(false);
10
- expect(shouldCompress('path/to/foo.mp4')).toBe(false);
11
- expect(shouldCompress('path/to/foo.webm')).toBe(false);
12
- });
13
- test('contentType', () => {
14
- expect(contentType('foo.jpg')).toBe('image/jpeg');
15
- expect(contentType('awesome.txt')).toBe('text/plain; charset=UTF-8');
16
- expect(contentType('bogus')).toBe('application/octetstream');
17
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getUnusedName } from "../names.js";
3
- describe('getUnusedName', () => {
4
- it('add a number to name to make it unique', () => {
5
- const names = new Set(['name']);
6
- const desiredName = 'name';
7
- const result = getUnusedName(names, desiredName);
8
- expect(result).toBe('name2');
9
- });
10
- it('should keep incrementing until the name is unique', () => {
11
- const names = new Set(['name', 'name2']);
12
- const desiredName = 'name';
13
- const result = getUnusedName(names, desiredName);
14
- expect(result).toBe('name3');
15
- });
16
- it('should handle an empty set of names and return the desired name', () => {
17
- const names = new Set();
18
- const desiredName = 'name';
19
- const result = getUnusedName(names, desiredName);
20
- expect(result).toBe(desiredName);
21
- });
22
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,98 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { getNamingParams, sharedBucketName, sharedResourceName, variantBucketName, variantResourceName } from "../naming.js";
3
- describe('variantResourceName', () => {
4
- test('it works', () => {
5
- expect(variantResourceName({
6
- appName: 'app',
7
- stage: {
8
- env: 'dev',
9
- variant: 'variant'
10
- }
11
- }, 'resourceName')).toEqual('app--dev--variant--resource-name');
12
- });
13
- });
14
- describe('sharedResourceName', () => {
15
- test('it works', () => {
16
- expect(sharedResourceName({
17
- appName: 'app',
18
- stage: {
19
- env: 'dev',
20
- variant: 'variant'
21
- }
22
- }, 'resourceName')).toEqual('app--dev--resource-name');
23
- });
24
- });
25
- describe('variantBucketName', () => {
26
- test('it works', () => {
27
- expect(variantBucketName({
28
- appName: 'app',
29
- stage: {
30
- env: 'dev',
31
- variant: 'variant'
32
- },
33
- region: 'us-west-1'
34
- }, 'bucket')).toEqual('app--dev--variant--us-west-1--bucket');
35
- });
36
- });
37
- describe('sharedBucketName', () => {
38
- test('it works', () => {
39
- expect(sharedBucketName({
40
- appName: 'app',
41
- stage: {
42
- env: 'dev',
43
- variant: 'variant'
44
- },
45
- region: 'us-west-1'
46
- }, 'bucket')).toEqual('app--dev--us-west-1--bucket');
47
- });
48
- });
49
- describe('getNamingParams', () => {
50
- test('it returns correct params', () => {
51
- const env = {
52
- TS_NAME: 'app',
53
- TS_ENV: 'dev',
54
- TS_VARIANT: 'variant',
55
- TS_REGION: 'us-west-1'
56
- };
57
- expect(getNamingParams(env)).toEqual({
58
- appName: 'app',
59
- region: 'us-west-1',
60
- stage: {
61
- env: 'dev',
62
- variant: 'variant'
63
- }
64
- });
65
- });
66
- test('it throws error if TS_NAME is missing', () => {
67
- const env = {
68
- TS_ENV: 'dev',
69
- TS_VARIANT: 'variant',
70
- TS_REGION: 'us-west-1'
71
- };
72
- expect(() => getNamingParams(env)).toThrow('TS_NAME environment variable must be specified');
73
- });
74
- test('it throws error if TS_ENV is missing', () => {
75
- const env = {
76
- TS_NAME: 'app',
77
- TS_VARIANT: 'variant',
78
- TS_REGION: 'us-west-1'
79
- };
80
- expect(() => getNamingParams(env)).toThrow('TS_ENV environment variable must be specified');
81
- });
82
- test('it throws error if TS_REGION is missing', () => {
83
- const env = {
84
- TS_NAME: 'app',
85
- TS_ENV: 'dev',
86
- TS_VARIANT: 'variant'
87
- };
88
- expect(() => getNamingParams(env)).toThrow('TS_REGION environment variable must be specified');
89
- });
90
- test('it throws error if TS_VARIANT is missing and TS_ENV is dev', () => {
91
- const env = {
92
- TS_NAME: 'app',
93
- TS_ENV: 'dev',
94
- TS_REGION: 'us-west-1'
95
- };
96
- expect(() => getNamingParams(env)).toThrow('TS_VARIANT environment variable must be specified');
97
- });
98
- });
@@ -1 +0,0 @@
1
- export {};