@sqlrooms/utils 0.0.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.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-dev.log +203 -0
- package/.turbo/turbo-lint.log +16 -0
- package/.turbo/turbo-test.log +51 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +9 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +10 -0
- package/dist/format.d.ts +11 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +10 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +56 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +9 -0
- package/dist/str.d.ts +13 -0
- package/dist/str.d.ts.map +1 -0
- package/dist/str.js +122 -0
- package/dist/str.test.d.ts +2 -0
- package/dist/str.test.d.ts.map +1 -0
- package/dist/str.test.js +42 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/xhr.d.ts +20 -0
- package/dist/xhr.d.ts.map +1 -0
- package/dist/xhr.js +94 -0
- package/eslint.config.js +4 -0
- package/jest.config.ms +8 -0
- package/package.json +36 -0
- package/src/color.ts +11 -0
- package/src/format.ts +12 -0
- package/src/helpers.ts +68 -0
- package/src/index.ts +6 -0
- package/src/storage.ts +14 -0
- package/src/str.test.ts +65 -0
- package/src/str.ts +166 -0
- package/src/xhr.ts +124 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @sqlrooms/utils@1.0.0 dev /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
4
|
+
> tsc -w
|
|
5
|
+
|
|
6
|
+
[2J[3J[H[[90m7:31:02 PM[0m] Starting compilation in watch mode...
|
|
7
|
+
|
|
8
|
+
[96msrc/color.ts[0m:[93m1[0m:[93m32[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-color'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/d3-color@3.1.0/node_modules/d3-color/src/index.js' implicitly has an 'any' type.
|
|
9
|
+
Try `npm i --save-dev @types/d3-color` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-color';`
|
|
10
|
+
|
|
11
|
+
[7m1[0m import {color as d3color} from 'd3-color';
|
|
12
|
+
[7m [0m [91m ~~~~~~~~~~[0m
|
|
13
|
+
|
|
14
|
+
[96msrc/format.ts[0m:[93m1[0m:[93m27[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-format'. '/Users/ilya/Workspace/sqlrooms/node_modules/d3-format/src/index.js' implicitly has an 'any' type.
|
|
15
|
+
Try `npm i --save-dev @types/d3-format` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-format';`
|
|
16
|
+
|
|
17
|
+
[7m1[0m import * as d3Format from 'd3-format';
|
|
18
|
+
[7m [0m [91m ~~~~~~~~~~~[0m
|
|
19
|
+
|
|
20
|
+
[96msrc/helpers.ts[0m:[93m1[0m:[93m26[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'd3-time-format'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/d3-time-format@3.0.0/node_modules/d3-time-format/dist/d3-time-format.js' implicitly has an 'any' type.
|
|
21
|
+
Try `npm i --save-dev @types/d3-time-format` if it exists or add a new declaration (.d.ts) file containing `declare module 'd3-time-format';`
|
|
22
|
+
|
|
23
|
+
[7m1[0m import {timeFormat} from 'd3-time-format';
|
|
24
|
+
[7m [0m [91m ~~~~~~~~~~~~~~~~[0m
|
|
25
|
+
|
|
26
|
+
[96msrc/helpers.ts[0m:[93m2[0m:[93m20[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module 'seedrandom'. '/Users/ilya/Workspace/sqlrooms/node_modules/.pnpm/seedrandom@3.0.5/node_modules/seedrandom/index.js' implicitly has an 'any' type.
|
|
27
|
+
Try `npm i --save-dev @types/seedrandom` if it exists or add a new declaration (.d.ts) file containing `declare module 'seedrandom';`
|
|
28
|
+
|
|
29
|
+
[7m2[0m import {alea} from 'seedrandom';
|
|
30
|
+
[7m [0m [91m ~~~~~~~~~~~~[0m
|
|
31
|
+
|
|
32
|
+
[96msrc/str.test.ts[0m:[93m7[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
33
|
+
|
|
34
|
+
[7m7[0m test('generateUniqueName generates unique table names', () => {
|
|
35
|
+
[7m [0m [91m~~~~[0m
|
|
36
|
+
|
|
37
|
+
[96msrc/str.test.ts[0m:[93m8[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
38
|
+
|
|
39
|
+
[7m8[0m expect(generateUniqueName('foo', [])).toBe('foo');
|
|
40
|
+
[7m [0m [91m ~~~~~~[0m
|
|
41
|
+
|
|
42
|
+
[96msrc/str.test.ts[0m:[93m9[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
43
|
+
|
|
44
|
+
[7m9[0m expect(generateUniqueName('foo', ['345'])).toBe('foo');
|
|
45
|
+
[7m [0m [91m ~~~~~~[0m
|
|
46
|
+
|
|
47
|
+
[96msrc/str.test.ts[0m:[93m10[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
48
|
+
|
|
49
|
+
[7m10[0m expect(generateUniqueName('foo', ['foo_1'])).toBe('foo');
|
|
50
|
+
[7m [0m [91m ~~~~~~[0m
|
|
51
|
+
|
|
52
|
+
[96msrc/str.test.ts[0m:[93m11[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
53
|
+
|
|
54
|
+
[7m11[0m expect(generateUniqueName('foo', ['foo', 'foo_1'])).toBe('foo_2');
|
|
55
|
+
[7m [0m [91m ~~~~~~[0m
|
|
56
|
+
|
|
57
|
+
[96msrc/str.test.ts[0m:[93m12[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
58
|
+
|
|
59
|
+
[7m12[0m expect(generateUniqueName('foo_1', ['foo_1'])).toBe('foo_2');
|
|
60
|
+
[7m [0m [91m ~~~~~~[0m
|
|
61
|
+
|
|
62
|
+
[96msrc/str.test.ts[0m:[93m13[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
63
|
+
|
|
64
|
+
[7m13[0m expect(generateUniqueName('foo_2', ['foo_2'])).toBe('foo_3');
|
|
65
|
+
[7m [0m [91m ~~~~~~[0m
|
|
66
|
+
|
|
67
|
+
[96msrc/str.test.ts[0m:[93m14[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
68
|
+
|
|
69
|
+
[7m14[0m expect(generateUniqueName('foo', ['foo', 'foo_1', 'foo_2'])).toBe('foo_3');
|
|
70
|
+
[7m [0m [91m ~~~~~~[0m
|
|
71
|
+
|
|
72
|
+
[96msrc/str.test.ts[0m:[93m15[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
73
|
+
|
|
74
|
+
[7m15[0m expect(generateUniqueName('')).toBe('');
|
|
75
|
+
[7m [0m [91m ~~~~~~[0m
|
|
76
|
+
|
|
77
|
+
[96msrc/str.test.ts[0m:[93m16[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
78
|
+
|
|
79
|
+
[7m16[0m expect(generateUniqueName('', [''])).toBe('_1');
|
|
80
|
+
[7m [0m [91m ~~~~~~[0m
|
|
81
|
+
|
|
82
|
+
[96msrc/str.test.ts[0m:[93m17[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
83
|
+
|
|
84
|
+
[7m17[0m expect(generateUniqueName('_', ['_'])).toBe('__1');
|
|
85
|
+
[7m [0m [91m ~~~~~~[0m
|
|
86
|
+
|
|
87
|
+
[96msrc/str.test.ts[0m:[93m20[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
88
|
+
|
|
89
|
+
[7m20[0m test('generateUniquePath generates unique paths', () => {
|
|
90
|
+
[7m [0m [91m~~~~[0m
|
|
91
|
+
|
|
92
|
+
[96msrc/str.test.ts[0m:[93m21[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
93
|
+
|
|
94
|
+
[7m21[0m expect(generateUniquePath('/foo/bar.csv', [])).toBe('/foo/bar.csv');
|
|
95
|
+
[7m [0m [91m ~~~~~~[0m
|
|
96
|
+
|
|
97
|
+
[96msrc/str.test.ts[0m:[93m22[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
98
|
+
|
|
99
|
+
[7m22[0m expect(generateUniquePath('/foo/bar.csv', ['345'])).toBe('/foo/bar.csv');
|
|
100
|
+
[7m [0m [91m ~~~~~~[0m
|
|
101
|
+
|
|
102
|
+
[96msrc/str.test.ts[0m:[93m23[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
103
|
+
|
|
104
|
+
[7m23[0m expect(generateUniquePath('/foo/bar.csv', ['/foo/bar.csv'])).toBe(
|
|
105
|
+
[7m [0m [91m ~~~~~~[0m
|
|
106
|
+
|
|
107
|
+
[96msrc/str.test.ts[0m:[93m26[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
108
|
+
|
|
109
|
+
[7m26[0m expect(generateUniquePath('/foo/bar.csv', ['/foo/bar_1.csv'])).toBe(
|
|
110
|
+
[7m [0m [91m ~~~~~~[0m
|
|
111
|
+
|
|
112
|
+
[96msrc/str.test.ts[0m:[93m29[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
113
|
+
|
|
114
|
+
[7m29[0m expect(
|
|
115
|
+
[7m [0m [91m ~~~~~~[0m
|
|
116
|
+
|
|
117
|
+
[96msrc/str.test.ts[0m:[93m32[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
118
|
+
|
|
119
|
+
[7m32[0m expect(
|
|
120
|
+
[7m [0m [91m ~~~~~~[0m
|
|
121
|
+
|
|
122
|
+
[96msrc/str.test.ts[0m:[93m39[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
123
|
+
|
|
124
|
+
[7m39[0m expect(generateUniquePath('/foo/bar_1.csv', ['/foo/bar_1.csv'])).toBe(
|
|
125
|
+
[7m [0m [91m ~~~~~~[0m
|
|
126
|
+
|
|
127
|
+
[96msrc/str.test.ts[0m:[93m42[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
128
|
+
|
|
129
|
+
[7m42[0m expect(generateUniquePath('/foo/bar_2.csv', ['/foo/bar_2.csv'])).toBe(
|
|
130
|
+
[7m [0m [91m ~~~~~~[0m
|
|
131
|
+
|
|
132
|
+
[96msrc/str.test.ts[0m:[93m45[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
133
|
+
|
|
134
|
+
[7m45[0m expect(generateUniquePath('/foo', [])).toBe('/foo');
|
|
135
|
+
[7m [0m [91m ~~~~~~[0m
|
|
136
|
+
|
|
137
|
+
[96msrc/str.test.ts[0m:[93m46[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
138
|
+
|
|
139
|
+
[7m46[0m expect(generateUniquePath('/foo/bar', [])).toBe('/foo/bar');
|
|
140
|
+
[7m [0m [91m ~~~~~~[0m
|
|
141
|
+
|
|
142
|
+
[96msrc/str.test.ts[0m:[93m47[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
143
|
+
|
|
144
|
+
[7m47[0m expect(generateUniquePath('/foo/bar', ['/foo/bar'])).toBe('/foo/bar_1');
|
|
145
|
+
[7m [0m [91m ~~~~~~[0m
|
|
146
|
+
|
|
147
|
+
[96msrc/str.test.ts[0m:[93m48[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
148
|
+
|
|
149
|
+
[7m48[0m expect(generateUniquePath('/', [])).toBe('/');
|
|
150
|
+
[7m [0m [91m ~~~~~~[0m
|
|
151
|
+
|
|
152
|
+
[96msrc/str.test.ts[0m:[93m49[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
153
|
+
|
|
154
|
+
[7m49[0m expect(generateUniquePath('', [])).toBe('');
|
|
155
|
+
[7m [0m [91m ~~~~~~[0m
|
|
156
|
+
|
|
157
|
+
[96msrc/str.test.ts[0m:[93m50[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
158
|
+
|
|
159
|
+
[7m50[0m expect(generateUniquePath('', [''])).toBe('_1');
|
|
160
|
+
[7m [0m [91m ~~~~~~[0m
|
|
161
|
+
|
|
162
|
+
[96msrc/str.test.ts[0m:[93m51[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
163
|
+
|
|
164
|
+
[7m51[0m expect(generateUniquePath('_', ['_'])).toBe('__1');
|
|
165
|
+
[7m [0m [91m ~~~~~~[0m
|
|
166
|
+
|
|
167
|
+
[96msrc/str.test.ts[0m:[93m54[0m:[93m1[0m - [91merror[0m[90m TS2582: [0mCannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`.
|
|
168
|
+
|
|
169
|
+
[7m54[0m test('convertToUniqueS3ObjectName works correctly', () => {
|
|
170
|
+
[7m [0m [91m~~~~[0m
|
|
171
|
+
|
|
172
|
+
[96msrc/str.test.ts[0m:[93m55[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
173
|
+
|
|
174
|
+
[7m55[0m expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
175
|
+
[7m [0m [91m ~~~~~~[0m
|
|
176
|
+
|
|
177
|
+
[96msrc/str.test.ts[0m:[93m56[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
178
|
+
|
|
179
|
+
[7m56[0m expect(convertToUniqueS3ObjectName('&flows.csv', [])).toBe('_flows.csv');
|
|
180
|
+
[7m [0m [91m ~~~~~~[0m
|
|
181
|
+
|
|
182
|
+
[96msrc/str.test.ts[0m:[93m57[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
183
|
+
|
|
184
|
+
[7m57[0m expect(convertToUniqueS3ObjectName('@flows.csv', [])).toBe('_flows.csv');
|
|
185
|
+
[7m [0m [91m ~~~~~~[0m
|
|
186
|
+
|
|
187
|
+
[96msrc/str.test.ts[0m:[93m58[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
188
|
+
|
|
189
|
+
[7m58[0m expect(convertToUniqueS3ObjectName('/flows.csv', [])).toBe('_flows.csv');
|
|
190
|
+
[7m [0m [91m ~~~~~~[0m
|
|
191
|
+
|
|
192
|
+
[96msrc/str.test.ts[0m:[93m59[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
193
|
+
|
|
194
|
+
[7m59[0m expect(convertToUniqueS3ObjectName('flows.csv', ['flows.csv'])).toBe(
|
|
195
|
+
[7m [0m [91m ~~~~~~[0m
|
|
196
|
+
|
|
197
|
+
[96msrc/str.test.ts[0m:[93m62[0m:[93m3[0m - [91merror[0m[90m TS2304: [0mCannot find name 'expect'.
|
|
198
|
+
|
|
199
|
+
[7m62[0m expect(
|
|
200
|
+
[7m [0m [91m ~~~~~~[0m
|
|
201
|
+
|
|
202
|
+
[[90m7:31:04 PM[0m] Found 38 errors. Watching for file changes.
|
|
203
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
> @sqlrooms/utils@0.0.0 lint /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
3
|
+
> eslint .
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/Users/ilya/Workspace/sqlrooms/packages/utils/src/helpers.ts
|
|
7
|
+
63:46 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
|
8
|
+
|
|
9
|
+
/Users/ilya/Workspace/sqlrooms/packages/utils/src/str.ts
|
|
10
|
+
118:22 warning Unnecessary escape character: \. no-useless-escape
|
|
11
|
+
|
|
12
|
+
/Users/ilya/Workspace/sqlrooms/packages/utils/src/xhr.ts
|
|
13
|
+
6:25 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
|
|
14
|
+
|
|
15
|
+
✖ 3 problems (0 errors, 3 warnings)
|
|
16
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @sqlrooms/utils@0.0.0 test /Users/ilya/Workspace/sqlrooms/packages/utils
|
|
4
|
+
> jest
|
|
5
|
+
|
|
6
|
+
[1m[2mDetermining test suites to run...[22m[22m[999D[K
|
|
7
|
+
|
|
8
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
[1m[31mJest encountered an unexpected token[39m[22m
|
|
15
|
+
|
|
16
|
+
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
|
|
17
|
+
|
|
18
|
+
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
|
|
19
|
+
|
|
20
|
+
By default "node_modules" folder is ignored by transformers.
|
|
21
|
+
|
|
22
|
+
Here's what you can do:
|
|
23
|
+
• If you are trying to use ECMAScript Modules, see [4mhttps://jestjs.io/docs/ecmascript-modules[24m for how to enable it.
|
|
24
|
+
• If you are trying to use TypeScript, see [4mhttps://jestjs.io/docs/getting-started#using-typescript[24m
|
|
25
|
+
• To have some of your "node_modules" files transformed, you can specify a custom [1m"transformIgnorePatterns"[22m in your config.
|
|
26
|
+
• If you need a custom transformation specify a [1m"transform"[22m option in your config.
|
|
27
|
+
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the [1m"moduleNameMapper"[22m config option.
|
|
28
|
+
|
|
29
|
+
You'll find more details and examples of these config options in the docs:
|
|
30
|
+
[36mhttps://jestjs.io/docs/configuration[39m
|
|
31
|
+
For information about custom transformations, see:
|
|
32
|
+
[36mhttps://jestjs.io/docs/code-transformation[39m
|
|
33
|
+
|
|
34
|
+
[1m[31mDetails:[39m[22m
|
|
35
|
+
|
|
36
|
+
/Users/ilya/Workspace/sqlrooms/packages/utils/dist/str.test.js:1
|
|
37
|
+
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { convertToUniqueS3ObjectName, generateUniqueName, generateUniquePath } from './str';
|
|
38
|
+
^^^^^^
|
|
39
|
+
|
|
40
|
+
SyntaxError: Cannot use import statement outside a module
|
|
41
|
+
|
|
42
|
+
[2mat Runtime.createScriptFromCode ([22m../../node_modules/.pnpm/jest-runtime@29.7.0/node_modules/jest-runtime/build/index.js[2m:1505:14)[22m
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2mdist/[22m[1mstr.test.js[22m
|
|
46
|
+
|
|
47
|
+
[1mTests: [22m0 total
|
|
48
|
+
[1mSnapshots: [22m0 total
|
|
49
|
+
[1mTime:[22m 0.208 s
|
|
50
|
+
[2mRan all test suites[22m[2m.[22m
|
|
51
|
+
[41m[30m ELIFECYCLE [39m[49m [31mTest failed. See above for more details.[39m
|
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Ilya Boyandin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQnE"}
|
package/dist/color.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { color as d3color } from 'd3-color';
|
|
2
|
+
export function opacifyHex(hexCode, opacity) {
|
|
3
|
+
const c = d3color(hexCode);
|
|
4
|
+
if (!c) {
|
|
5
|
+
console.warn('Invalid color: ', hexCode);
|
|
6
|
+
return `rgba(255, 255, 255, ${opacity})`;
|
|
7
|
+
}
|
|
8
|
+
const col = c.rgb();
|
|
9
|
+
return `rgba(${col.r}, ${col.g}, ${col.b}, ${opacity})`;
|
|
10
|
+
}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const formatCount: (n: number | {
|
|
2
|
+
valueOf(): number;
|
|
3
|
+
}) => string;
|
|
4
|
+
export declare const formatCount4: (n: number | {
|
|
5
|
+
valueOf(): number;
|
|
6
|
+
}) => string;
|
|
7
|
+
export declare const formatCountShort: (n: number | {
|
|
8
|
+
valueOf(): number;
|
|
9
|
+
}) => string;
|
|
10
|
+
export declare function shorten(str: string, maxLength?: number): string;
|
|
11
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW;;YAA0B,CAAC;AACnD,eAAO,MAAM,YAAY;;YAA0B,CAAC;AACpD,eAAO,MAAM,gBAAgB;;YAA0B,CAAC;AAExD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,MAAM,CAK3D"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as d3Format from 'd3-format';
|
|
2
|
+
export const formatCount = d3Format.format(',.0f');
|
|
3
|
+
export const formatCount4 = d3Format.format('.4~s');
|
|
4
|
+
export const formatCountShort = d3Format.format(',.0s');
|
|
5
|
+
export function shorten(str, maxLength = 10) {
|
|
6
|
+
if (str.length <= maxLength) {
|
|
7
|
+
return str;
|
|
8
|
+
}
|
|
9
|
+
return `${str.substring(0, maxLength - 3)}…`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConfigType } from 'dayjs';
|
|
2
|
+
export declare const toDateTime: (secs: number) => Date;
|
|
3
|
+
export declare function genRandomStr(length: number, seed?: string): string;
|
|
4
|
+
export declare const NUMBER_FORMAT: Intl.NumberFormat;
|
|
5
|
+
export declare const formatNumber: (n: number) => string;
|
|
6
|
+
export declare const formatDateTime: (d: Date | number | bigint) => string;
|
|
7
|
+
export declare const formatDate: (d: Date | number | bigint) => string;
|
|
8
|
+
export declare const formatTimeOfDay: (d: Date | number | bigint) => string;
|
|
9
|
+
export declare const formatTimeRelative: (d: ConfigType) => string;
|
|
10
|
+
export declare const getErrorMessageForDisplay: (e: any) => string;
|
|
11
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAc,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AAKxC,eAAO,MAAM,UAAU,SAAU,MAAM,SAItC,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,UAgBzD;AAED,eAAO,MAAM,aAAa,mBAExB,CAAC;AAEH,eAAO,MAAM,YAAY,MAAO,MAAM,WAA4B,CAAC;AAMnE,eAAO,MAAM,cAAc,MAAO,IAAI,GAAG,MAAM,GAAG,MAAM,WAIvD,CAAC;AAEF,eAAO,MAAM,UAAU,MAAO,IAAI,GAAG,MAAM,GAAG,MAAM,WAGnD,CAAC;AAEF,eAAO,MAAM,eAAe,MAAO,IAAI,GAAG,MAAM,GAAG,MAAM,WAGxD,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,UAAU,WAE/C,CAAC;AAEF,eAAO,MAAM,yBAAyB,MAAO,GAAG,WAK/C,CAAC"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { timeFormat } from 'd3-time-format';
|
|
2
|
+
import { alea } from 'seedrandom';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
5
|
+
dayjs.extend(relativeTime);
|
|
6
|
+
export const toDateTime = (secs) => {
|
|
7
|
+
const t = new Date('1970-01-01T00:30:00Z'); // Unix epoch start.
|
|
8
|
+
t.setSeconds(secs);
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
export function genRandomStr(length, seed) {
|
|
12
|
+
const rnd = seed ? alea(seed) : Math.random;
|
|
13
|
+
return Array.from((function* () {
|
|
14
|
+
for (let i = 0; i < length; i++) {
|
|
15
|
+
const v = Math.floor(rnd() * (26 * 2 + 10));
|
|
16
|
+
if (v < 26) {
|
|
17
|
+
yield String.fromCharCode(v + 65); // 'A' - 'Z'
|
|
18
|
+
}
|
|
19
|
+
else if (v < 52) {
|
|
20
|
+
yield String.fromCharCode(v + 71); // 'a' - 'z'
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
yield String.fromCharCode(v + 48); // '0' - '9'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})()).join('');
|
|
27
|
+
}
|
|
28
|
+
export const NUMBER_FORMAT = new Intl.NumberFormat('en-US', {
|
|
29
|
+
minimumFractionDigits: 0,
|
|
30
|
+
});
|
|
31
|
+
export const formatNumber = (n) => NUMBER_FORMAT.format(n);
|
|
32
|
+
const TIME_OF_DAY_FORMAT = timeFormat('%I:%M %p');
|
|
33
|
+
const DATE_TIME_FORMAT = timeFormat('%a %Y-%m-%d %I:%M %p');
|
|
34
|
+
const DATE_FORMAT = timeFormat('%Y-%m-%d');
|
|
35
|
+
export const formatDateTime = (d) => {
|
|
36
|
+
const date = d instanceof Date ? d : new Date(Number(d));
|
|
37
|
+
// return date.toISOString();
|
|
38
|
+
return DATE_TIME_FORMAT(date);
|
|
39
|
+
};
|
|
40
|
+
export const formatDate = (d) => {
|
|
41
|
+
const date = d instanceof Date ? d : new Date(Number(d));
|
|
42
|
+
return DATE_FORMAT(date);
|
|
43
|
+
};
|
|
44
|
+
export const formatTimeOfDay = (d) => {
|
|
45
|
+
const date = d instanceof Date ? d : new Date(Number(d));
|
|
46
|
+
return TIME_OF_DAY_FORMAT(date);
|
|
47
|
+
};
|
|
48
|
+
export const formatTimeRelative = (d) => {
|
|
49
|
+
return dayjs().to(d);
|
|
50
|
+
};
|
|
51
|
+
export const getErrorMessageForDisplay = (e) => {
|
|
52
|
+
let msg = e instanceof Error ? e.message : String(e);
|
|
53
|
+
msg = msg.replace(/Query failed: Error: /, '');
|
|
54
|
+
const firstNl = msg.indexOf('\n');
|
|
55
|
+
return firstNl >= 0 ? msg.substring(0, firstNl) : msg;
|
|
56
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAGA,wBAAsB,gBAAgB,CACpC,MAAM,EACF;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAC,GACjC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,gBAO5E"}
|
package/dist/storage.js
ADDED
package/dist/str.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function formatBytes(bytes: number): string;
|
|
2
|
+
export declare function splitFilePath(filePath: string): {
|
|
3
|
+
dir: string;
|
|
4
|
+
name: string;
|
|
5
|
+
ext: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function convertToUniqueColumnOrTableName(filename: string, existingTables?: string[]): string;
|
|
8
|
+
export declare function generateUniqueName(name: string, usedNames?: string[]): string;
|
|
9
|
+
export declare function generateUniquePath(filePath: string, existingPaths: string[]): string;
|
|
10
|
+
export declare function convertToUniqueS3ObjectName(str: string, existingObjects?: string[]): string;
|
|
11
|
+
export declare function convertToUniqueS3FolderPath(str: string, existingObjects?: string[]): string;
|
|
12
|
+
export declare function camelCaseToTitle(camelCase: string): string;
|
|
13
|
+
//# sourceMappingURL=str.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"str.d.ts","sourceRoot":"","sources":["../src/str.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBjD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAYA;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,MAAM,EAChB,cAAc,CAAC,EAAE,MAAM,EAAE,GACxB,MAAM,CAoBR;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,UAsBpE;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,GACtB,MAAM,CAqBR;AAED,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,MAAM,CAeR;AAED,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,MAAM,CAaR;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB1D"}
|
package/dist/str.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export function formatBytes(bytes) {
|
|
2
|
+
if (bytes === 0)
|
|
3
|
+
return '0 Bytes';
|
|
4
|
+
const k = 1024;
|
|
5
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
6
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
7
|
+
let sizeValue = bytes / Math.pow(k, i);
|
|
8
|
+
// Use floor to check if there's a non-zero fractional part, format accordingly
|
|
9
|
+
sizeValue =
|
|
10
|
+
sizeValue != Math.floor(sizeValue)
|
|
11
|
+
? parseFloat(sizeValue.toFixed(2))
|
|
12
|
+
: Math.floor(sizeValue);
|
|
13
|
+
return sizeValue + ' ' + sizes[i];
|
|
14
|
+
}
|
|
15
|
+
export function splitFilePath(filePath) {
|
|
16
|
+
const pathParts = filePath.split('/');
|
|
17
|
+
const file = pathParts.pop() || '';
|
|
18
|
+
const dotIndex = file.lastIndexOf('.');
|
|
19
|
+
if (dotIndex === -1 || dotIndex === 0)
|
|
20
|
+
return { dir: pathParts.join('/'), name: file, ext: '' };
|
|
21
|
+
const name = file.substring(0, dotIndex);
|
|
22
|
+
const ext = file.substring(dotIndex + 1);
|
|
23
|
+
return { dir: pathParts.join('/'), name, ext };
|
|
24
|
+
}
|
|
25
|
+
export function convertToUniqueColumnOrTableName(filename, existingTables) {
|
|
26
|
+
// Remove file extension
|
|
27
|
+
const base = filename.replace(/\.[^/.]+$/, '');
|
|
28
|
+
// Replace any invalid character with underscore, and convert to lowercase
|
|
29
|
+
let tableName = base.replace(/[^a-z0-9_]/gi, '_');
|
|
30
|
+
// If the first character is a number, prepend an underscore
|
|
31
|
+
if (/^\d/.test(tableName)) {
|
|
32
|
+
tableName = '_' + tableName;
|
|
33
|
+
}
|
|
34
|
+
// Truncate to the max length 63
|
|
35
|
+
if (tableName.length > 63) {
|
|
36
|
+
tableName = tableName.substring(0, 63);
|
|
37
|
+
}
|
|
38
|
+
tableName = generateUniqueName(tableName, existingTables);
|
|
39
|
+
return tableName;
|
|
40
|
+
}
|
|
41
|
+
export function generateUniqueName(name, usedNames) {
|
|
42
|
+
const usedNamesLower = usedNames?.map((n) => n.toLowerCase());
|
|
43
|
+
// If tableName exists in the list
|
|
44
|
+
if (usedNamesLower?.includes(name.toLowerCase())) {
|
|
45
|
+
let baseName = name;
|
|
46
|
+
let i = 0;
|
|
47
|
+
// If tableName ends with `_${i}` pattern, update the baseTableName and i
|
|
48
|
+
const matched = name.match(/^(.+)_(\d+)$/);
|
|
49
|
+
if (matched) {
|
|
50
|
+
baseName = matched[1];
|
|
51
|
+
i = Number(matched[2]);
|
|
52
|
+
}
|
|
53
|
+
do {
|
|
54
|
+
i++;
|
|
55
|
+
name = `${baseName}_${i}`;
|
|
56
|
+
} while (usedNamesLower.includes(name.toLowerCase()));
|
|
57
|
+
}
|
|
58
|
+
return name;
|
|
59
|
+
}
|
|
60
|
+
export function generateUniquePath(filePath, existingPaths) {
|
|
61
|
+
let nextPath = filePath;
|
|
62
|
+
if (existingPaths?.includes(filePath)) {
|
|
63
|
+
const { dir, name, ext } = splitFilePath(filePath);
|
|
64
|
+
let i = 0;
|
|
65
|
+
let baseName = name;
|
|
66
|
+
const matched = name.match(/^(.+)_(\d+)$/);
|
|
67
|
+
if (matched) {
|
|
68
|
+
baseName = matched[1];
|
|
69
|
+
i = Number(matched[2]);
|
|
70
|
+
}
|
|
71
|
+
do {
|
|
72
|
+
i++;
|
|
73
|
+
const fname = `${baseName}_${i}${ext ? `.${ext}` : ''}`;
|
|
74
|
+
nextPath = `${dir}${dir ? '/' : ''}${fname}`;
|
|
75
|
+
} while (existingPaths.includes(nextPath));
|
|
76
|
+
}
|
|
77
|
+
return nextPath;
|
|
78
|
+
}
|
|
79
|
+
export function convertToUniqueS3ObjectName(str, existingObjects) {
|
|
80
|
+
let rv = str
|
|
81
|
+
.trim() // Remove leading and trailing white spaces
|
|
82
|
+
.replace(/[^\w\s-\.]/g, '_') // Replace special characters with underscores
|
|
83
|
+
.replace(/\s+/g, '_') // Replace consecutive spaces with a single underscore
|
|
84
|
+
// .replace(/_+/g, '_') // Remove consecutive underscores
|
|
85
|
+
// .replace(/^_/, '') // Remove leading underscores
|
|
86
|
+
// .replace(/_$/, '') // Remove trailing underscores
|
|
87
|
+
.slice(0, 255); // Truncate the string if it exceeds 255 characters
|
|
88
|
+
if (existingObjects?.length) {
|
|
89
|
+
rv = generateUniquePath(rv, existingObjects);
|
|
90
|
+
}
|
|
91
|
+
return rv;
|
|
92
|
+
}
|
|
93
|
+
export function convertToUniqueS3FolderPath(str, existingObjects) {
|
|
94
|
+
let next = convertToUniqueS3ObjectName(str, existingObjects);
|
|
95
|
+
if (!next.endsWith('/'))
|
|
96
|
+
next += '/'; // Add trailing slash if not present
|
|
97
|
+
return next;
|
|
98
|
+
// return (
|
|
99
|
+
// str
|
|
100
|
+
// .trim() // Remove leading and trailing white spaces
|
|
101
|
+
// .replace(/\/+/g, '/') // Replace consecutive slashes with a single slash
|
|
102
|
+
// .replace(/[^\w\s-\/]/g, '_') // Replace special characters with underscores
|
|
103
|
+
// .replace(/\s+/g, '_') // Replace consecutive spaces with a single underscore
|
|
104
|
+
// .replace(/^\//, '') + // Remove leading slash
|
|
105
|
+
// (str.endsWith('/') ? '' : '/')
|
|
106
|
+
// );
|
|
107
|
+
}
|
|
108
|
+
export function camelCaseToTitle(camelCase) {
|
|
109
|
+
// Split the string into words on the camelCase boundaries
|
|
110
|
+
const words = camelCase.match(/^[a-z]+|[A-Z][a-z]*/g);
|
|
111
|
+
// If words are found, transform them and join into a title string
|
|
112
|
+
if (words) {
|
|
113
|
+
return words
|
|
114
|
+
.map((word) => {
|
|
115
|
+
// Capitalize the first letter of each word
|
|
116
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
117
|
+
})
|
|
118
|
+
.join(' '); // Join the words with space
|
|
119
|
+
}
|
|
120
|
+
// If no words were found, just capitalize the whole string
|
|
121
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"str.test.d.ts","sourceRoot":"","sources":["../src/str.test.ts"],"names":[],"mappings":""}
|