@kirill.konshin/browser 0.0.2 → 0.0.4
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/dist/_virtual/_rolldown/runtime.js +5 -0
- package/dist/files.d.ts +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +25 -25
- package/dist/files.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -7
- package/dist/ls.js +15 -10
- package/dist/ls.js.map +1 -1
- package/package.json +14 -4
- package/.ctirc +0 -20
- package/.turbo/turbo-build.log +0 -21
- package/.turbo/turbo-test.log +0 -31
- package/CHANGELOG.md +0 -7
- package/dist/files.test.d.ts +0 -2
- package/dist/files.test.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/ls.test.d.ts +0 -2
- package/dist/ls.test.d.ts.map +0 -1
- package/src/files.test.ts +0 -3
- package/src/files.ts +0 -29
- package/src/index.ts +0 -2
- package/src/ls.test.ts +0 -3
- package/src/ls.ts +0 -15
- package/tsconfig.json +0 -10
- package/turbo.json +0 -10
- package/vite.config.ts +0 -2
package/dist/files.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const downloadFile: (file: File) => Promise<void>;
|
|
2
2
|
export declare const createFile: (text: any, filename?: string, type?: string) => Promise<File>;
|
|
3
|
-
export declare const openFile: () => Promise<string>;
|
|
3
|
+
export declare const openFile: () => Promise<ArrayBuffer | string | null | undefined>;
|
|
4
4
|
//# sourceMappingURL=files.d.ts.map
|
package/dist/files.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,IAAI,CAM3D,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,MAAM,GAAG,EAAE,iBAAsB,EAAE,aAAyB,KAAG,OAAO,CAAC,IAAI,CAE3G,CAAC;
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,IAAI,CAM3D,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,MAAM,GAAG,EAAE,iBAAsB,EAAE,aAAyB,KAAG,OAAO,CAAC,IAAI,CAE3G,CAAC;AAGF,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,WAAW,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAgBrE,CAAC"}
|
package/dist/files.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { __require } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/files.ts
|
|
3
|
+
var downloadFile = async (file) => {
|
|
4
|
+
const { saveAs } = __require("file-saver");
|
|
5
|
+
return saveAs(file, file.name);
|
|
4
6
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
var createFile = async (text, filename = "file.json", type = "application/json") => {
|
|
8
|
+
return new File([new Blob([text], { type })], filename);
|
|
7
9
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
var openFile = () => new Promise((res, rej) => {
|
|
11
|
+
const input = document.createElement("input");
|
|
12
|
+
input.type = "file";
|
|
13
|
+
input.addEventListener("change", function readFile(e) {
|
|
14
|
+
input.removeEventListener("change", readFile);
|
|
15
|
+
const [file] = e.target.files;
|
|
16
|
+
if (!file) return;
|
|
17
|
+
const reader = new FileReader();
|
|
18
|
+
reader.onload = (e) => res(e.target?.result);
|
|
19
|
+
reader.onerror = rej;
|
|
20
|
+
reader.onabort = rej;
|
|
21
|
+
reader.readAsText(file);
|
|
22
|
+
});
|
|
23
|
+
input.click();
|
|
22
24
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=files.js.map
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createFile, downloadFile, openFile };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=files.js.map
|
package/dist/files.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sources":["../src/files.ts"],"sourcesContent":["export const downloadFile = async (file: File): Promise<void> => {\n //FIXME https://github.com/eligrey/FileSaver.js/issues/471\n const { saveAs } = require('file-saver');\n\n //FIXME https://github.com/eligrey/FileSaver.js/issues/731\n return saveAs(file, file.name);\n};\n\nexport const createFile = async (text: any, filename = 'file.json', type = 'application/json'): Promise<File> => {\n return new File([new Blob([text], { type })], filename);\n};\n\nexport const openFile = (): Promise<string> =>\n new Promise((res, rej) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.addEventListener('change', function readFile(e) {\n input.removeEventListener('change', readFile);\n // @ts-expect-error file is always there\n const [file] = e.target.files;\n if (!file) return;\n const reader = new FileReader();\n reader.onload = (e) => res(e.target?.result
|
|
1
|
+
{"version":3,"file":"files.js","names":[],"sources":["../src/files.ts"],"sourcesContent":["export const downloadFile = async (file: File): Promise<void> => {\n //FIXME https://github.com/eligrey/FileSaver.js/issues/471\n const { saveAs } = require('file-saver');\n\n //FIXME https://github.com/eligrey/FileSaver.js/issues/731\n return saveAs(file, file.name);\n};\n\nexport const createFile = async (text: any, filename = 'file.json', type = 'application/json'): Promise<File> => {\n return new File([new Blob([text], { type })], filename);\n};\n\n// TODO Filter types\nexport const openFile = (): Promise<ArrayBuffer | string | null | undefined> =>\n new Promise((res, rej) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.addEventListener('change', function readFile(e) {\n input.removeEventListener('change', readFile);\n // @ts-expect-error file is always there\n const [file] = e.target.files;\n if (!file) return;\n const reader = new FileReader();\n reader.onload = (e) => res(e.target?.result);\n reader.onerror = rej;\n reader.onabort = rej;\n reader.readAsText(file);\n });\n input.click();\n });\n"],"mappings":";;AAAA,IAAa,eAAe,OAAO,SAA8B;CAE7D,MAAM,EAAE,WAAA,UAAmB,YAAY;CAGvC,OAAO,OAAO,MAAM,KAAK,IAAI;AACjC;AAEA,IAAa,aAAa,OAAO,MAAW,WAAW,aAAa,OAAO,uBAAsC;CAC7G,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC,GAAG,QAAQ;AAC1D;AAGA,IAAa,iBACT,IAAI,SAAS,KAAK,QAAQ;CACtB,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,OAAO;CACb,MAAM,iBAAiB,UAAU,SAAS,SAAS,GAAG;EAClD,MAAM,oBAAoB,UAAU,QAAQ;EAE5C,MAAM,CAAC,QAAQ,EAAE,OAAO;EACxB,IAAI,CAAC,MAAM;EACX,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,UAAU,MAAM,IAAI,EAAE,QAAQ,MAAM;EAC3C,OAAO,UAAU;EACjB,OAAO,UAAU;EACjB,OAAO,WAAW,IAAI;CAC1B,CAAC;CACD,MAAM,MAAM;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './files';
|
|
2
|
-
export * from './ls';
|
|
1
|
+
export * from './files.js';
|
|
2
|
+
export * from './ls.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import { createFile, downloadFile, openFile } from "./files.js";
|
|
2
2
|
import { getStorage } from "./ls.js";
|
|
3
|
-
export {
|
|
4
|
-
createFile,
|
|
5
|
-
downloadFile,
|
|
6
|
-
getStorage,
|
|
7
|
-
openFile
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
+
export { createFile, downloadFile, getStorage, openFile };
|
package/dist/ls.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
//#region src/ls.ts
|
|
1
2
|
function getStorage(pref) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const prefix = (key) => `${pref}-${key}`;
|
|
4
|
+
const ls = typeof window !== "undefined" ? localStorage : null;
|
|
5
|
+
const read = (key) => JSON.parse(ls?.getItem(prefix(key)) || "null");
|
|
6
|
+
const write = (key, value) => ls?.setItem(prefix(key), JSON.stringify(value));
|
|
7
|
+
const remove = (key) => ls?.removeItem(prefix(key));
|
|
8
|
+
return {
|
|
9
|
+
read,
|
|
10
|
+
write,
|
|
11
|
+
remove
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=ls.js.map
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getStorage };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=ls.js.map
|
package/dist/ls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ls.js","sources":["../src/ls.ts"],"sourcesContent":["export function getStorage(pref: string): {\n read: (key: string) => null | any;\n write: (key: string, value: any) => void;\n remove: (key: string) => void;\n} {\n const prefix = (key) => `${pref}-${key}`;\n\n const ls = (typeof window !== 'undefined' ? localStorage : null) as Storage;\n\n const read = (key: string): any => JSON.parse(ls?.getItem(prefix(key)) || 'null');\n const write = (key: string, value: any): void => ls?.setItem(prefix(key), JSON.stringify(value));\n const remove = (key: string): void => ls?.removeItem(prefix(key));\n\n return { read, write, remove };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"ls.js","names":[],"sources":["../src/ls.ts"],"sourcesContent":["export function getStorage(pref: string): {\n read: (key: string) => null | any;\n write: (key: string, value: any) => void;\n remove: (key: string) => void;\n} {\n const prefix = (key) => `${pref}-${key}`;\n\n const ls = (typeof window !== 'undefined' ? localStorage : null) as Storage;\n\n const read = (key: string): any => JSON.parse(ls?.getItem(prefix(key)) || 'null');\n const write = (key: string, value: any): void => ls?.setItem(prefix(key), JSON.stringify(value));\n const remove = (key: string): void => ls?.removeItem(prefix(key));\n\n return { read, write, remove };\n}\n"],"mappings":";AAAA,SAAgB,WAAW,MAIzB;CACE,MAAM,UAAU,QAAQ,GAAG,KAAK,GAAG;CAEnC,MAAM,KAAM,OAAO,WAAW,cAAc,eAAe;CAE3D,MAAM,QAAQ,QAAqB,KAAK,MAAM,IAAI,QAAQ,OAAO,GAAG,CAAC,KAAK,MAAM;CAChF,MAAM,SAAS,KAAa,UAAqB,IAAI,QAAQ,OAAO,GAAG,GAAG,KAAK,UAAU,KAAK,CAAC;CAC/F,MAAM,UAAU,QAAsB,IAAI,WAAW,OAAO,GAAG,CAAC;CAEhE,OAAO;EAAE;EAAM;EAAO;CAAO;AACjC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirill.konshin/browser",
|
|
3
3
|
"description": "Browser Utilities",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"----- BUILD -----": "",
|
|
8
8
|
"clean": "rm -rf dist .tscache tsconfig.tsbuildinfo",
|
|
9
9
|
"build": "vite build",
|
|
10
|
-
"build:index": "ctix build",
|
|
11
|
-
"build:check-types": "attw --pack .",
|
|
12
10
|
"start": "yarn build --watch",
|
|
13
11
|
"wait": "wait-on ./dist/index.js",
|
|
14
12
|
"----- TEST -----": "",
|
|
@@ -40,5 +38,17 @@
|
|
|
40
38
|
"main": "./dist/index.js",
|
|
41
39
|
"module": "./dist/index.js",
|
|
42
40
|
"types": "./dist/index.d.ts",
|
|
43
|
-
"
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/kirill-konshin/utils.git",
|
|
44
|
+
"directory": "packages/browser"
|
|
45
|
+
},
|
|
46
|
+
"nx": {
|
|
47
|
+
"tags": [
|
|
48
|
+
"platform:browser"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist"
|
|
53
|
+
]
|
|
44
54
|
}
|
package/.ctirc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"options": [
|
|
3
|
-
{
|
|
4
|
-
"mode": "create",
|
|
5
|
-
"project": "tsconfig.json",
|
|
6
|
-
"include": "src/**/*.{ts,tsx}",
|
|
7
|
-
"exclude": [
|
|
8
|
-
"**/*.stories.*",
|
|
9
|
-
"**/*.test.*",
|
|
10
|
-
"**/*.fixture.*"
|
|
11
|
-
],
|
|
12
|
-
"startFrom": "src",
|
|
13
|
-
"backup": false,
|
|
14
|
-
"overwrite": true,
|
|
15
|
-
"generationStyle": "default-alias-named-star",
|
|
16
|
-
"output": "src",
|
|
17
|
-
"verbose": true
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
[36mvite v7.0.6 [32mbuilding SSR bundle for production...[36m[39m
|
|
2
|
-
- ctix 'create' mode start, ...
|
|
3
|
-
✔ /home/runner/work/utils/utils/packages/browser/tsconfig.json loading complete!
|
|
4
|
-
✔ analysis export statements completed!
|
|
5
|
-
- build "index.ts" file start
|
|
6
|
-
- output file exists check, ...
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
✔ ctix 'create' mode complete!
|
|
10
|
-
transforming...
|
|
11
|
-
[32m✓[39m 3 modules transformed.
|
|
12
|
-
rendering chunks...
|
|
13
|
-
|
|
14
|
-
[vite:dts] Start generate declaration files...
|
|
15
|
-
[2mdist/[22m[36mindex.js [39m[1m[2m0.20 kB[22m[1m[22m[2m │ map: 0.09 kB[22m
|
|
16
|
-
[2mdist/[22m[36mls.js [39m[1m[2m0.44 kB[22m[1m[22m[2m │ map: 1.05 kB[22m
|
|
17
|
-
[2mdist/[22m[36mfiles.js [39m[1m[2m0.84 kB[22m[1m[22m[2m │ map: 1.89 kB[22m
|
|
18
|
-
[vite:dts] Declaration files built in 1625ms.
|
|
19
|
-
|
|
20
|
-
[32m✓ built in 4.84s[39m
|
|
21
|
-
Updated package.json with exports
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
- ctix 'create' mode start, ...
|
|
2
|
-
✔ /home/runner/work/utils/utils/packages/browser/tsconfig.json loading complete!
|
|
3
|
-
✔ analysis export statements completed!
|
|
4
|
-
- build "index.ts" file start
|
|
5
|
-
- output file exists check, ...
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
✔ ctix 'create' mode complete!
|
|
9
|
-
|
|
10
|
-
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/home/runner/work/utils/utils/packages/browser[39m
|
|
11
|
-
[2mCoverage enabled with [22m[33mv8[39m
|
|
12
|
-
|
|
13
|
-
[2m[90m↓[39m[22m src/files.test.ts [2m([22m[2m1 test[22m[2m | [22m[33m1 skipped[39m[2m)[22m
|
|
14
|
-
[2m[90m↓[39m[22m src/ls.test.ts [2m([22m[2m1 test[22m[2m | [22m[33m1 skipped[39m[2m)[22m
|
|
15
|
-
|
|
16
|
-
[2m Test Files [22m [33m2 skipped[39m[90m (2)[39m
|
|
17
|
-
[2m Tests [22m [33m2 skipped[39m[90m (2)[39m
|
|
18
|
-
[2m Start at [22m 03:27:03
|
|
19
|
-
[2m Duration [22m 456ms[2m (transform 39ms, setup 0ms, collect 39ms, tests 0ms, environment 1ms, prepare 236ms)[22m
|
|
20
|
-
|
|
21
|
-
[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
22
|
-
----------|---------|----------|---------|---------|-------------------
|
|
23
|
-
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
24
|
-
----------|---------|----------|---------|---------|-------------------
|
|
25
|
-
All files | 0 | 0 | 0 | 0 |
|
|
26
|
-
files.ts | 0 | 0 | 0 | 0 | 1-29
|
|
27
|
-
index.ts | 0 | 0 | 0 | 0 | 1-2
|
|
28
|
-
ls.ts | 0 | 0 | 0 | 0 | 1-15
|
|
29
|
-
----------|---------|----------|---------|---------|-------------------
|
|
30
|
-
Updated package.json with exports
|
|
31
|
-
Updated package.json with exports
|
package/CHANGELOG.md
DELETED
package/dist/files.test.d.ts
DELETED
package/dist/files.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files.test.d.ts","sourceRoot":"","sources":["../src/files.test.ts"],"names":[],"mappings":""}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/ls.test.d.ts
DELETED
package/dist/ls.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ls.test.d.ts","sourceRoot":"","sources":["../src/ls.test.ts"],"names":[],"mappings":""}
|
package/src/files.test.ts
DELETED
package/src/files.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const downloadFile = async (file: File): Promise<void> => {
|
|
2
|
-
//FIXME https://github.com/eligrey/FileSaver.js/issues/471
|
|
3
|
-
const { saveAs } = require('file-saver');
|
|
4
|
-
|
|
5
|
-
//FIXME https://github.com/eligrey/FileSaver.js/issues/731
|
|
6
|
-
return saveAs(file, file.name);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const createFile = async (text: any, filename = 'file.json', type = 'application/json'): Promise<File> => {
|
|
10
|
-
return new File([new Blob([text], { type })], filename);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const openFile = (): Promise<string> =>
|
|
14
|
-
new Promise((res, rej) => {
|
|
15
|
-
const input = document.createElement('input');
|
|
16
|
-
input.type = 'file';
|
|
17
|
-
input.addEventListener('change', function readFile(e) {
|
|
18
|
-
input.removeEventListener('change', readFile);
|
|
19
|
-
// @ts-expect-error file is always there
|
|
20
|
-
const [file] = e.target.files;
|
|
21
|
-
if (!file) return;
|
|
22
|
-
const reader = new FileReader();
|
|
23
|
-
reader.onload = (e) => res(e.target?.result as string);
|
|
24
|
-
reader.onerror = rej;
|
|
25
|
-
reader.onabort = rej;
|
|
26
|
-
reader.readAsText(file);
|
|
27
|
-
});
|
|
28
|
-
input.click();
|
|
29
|
-
});
|
package/src/index.ts
DELETED
package/src/ls.test.ts
DELETED
package/src/ls.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function getStorage(pref: string): {
|
|
2
|
-
read: (key: string) => null | any;
|
|
3
|
-
write: (key: string, value: any) => void;
|
|
4
|
-
remove: (key: string) => void;
|
|
5
|
-
} {
|
|
6
|
-
const prefix = (key) => `${pref}-${key}`;
|
|
7
|
-
|
|
8
|
-
const ls = (typeof window !== 'undefined' ? localStorage : null) as Storage;
|
|
9
|
-
|
|
10
|
-
const read = (key: string): any => JSON.parse(ls?.getItem(prefix(key)) || 'null');
|
|
11
|
-
const write = (key: string, value: any): void => ls?.setItem(prefix(key), JSON.stringify(value));
|
|
12
|
-
const remove = (key: string): void => ls?.removeItem(prefix(key));
|
|
13
|
-
|
|
14
|
-
return { read, write, remove };
|
|
15
|
-
}
|
package/tsconfig.json
DELETED
package/turbo.json
DELETED
package/vite.config.ts
DELETED