@kirill.konshin/browser 0.0.2
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/.ctirc +20 -0
- package/.turbo/turbo-build.log +21 -0
- package/.turbo/turbo-test.log +31 -0
- package/CHANGELOG.md +7 -0
- package/README.md +1 -0
- package/dist/files.d.ts +4 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +28 -0
- package/dist/files.js.map +1 -0
- package/dist/files.test.d.ts +2 -0
- package/dist/files.test.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/ls.d.ts +6 -0
- package/dist/ls.d.ts.map +1 -0
- package/dist/ls.js +12 -0
- package/dist/ls.js.map +1 -0
- package/dist/ls.test.d.ts +2 -0
- package/dist/ls.test.d.ts.map +1 -0
- package/package.json +44 -0
- package/src/files.test.ts +3 -0
- package/src/files.ts +29 -0
- package/src/index.ts +2 -0
- package/src/ls.test.ts +3 -0
- package/src/ls.ts +15 -0
- package/tsconfig.json +10 -0
- package/turbo.json +10 -0
- package/vite.config.ts +2 -0
package/.ctirc
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1,31 @@
|
|
|
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
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Core Utils
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +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;AAEF,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,MAAM,CAgBpC,CAAC"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const downloadFile = async (file) => {
|
|
2
|
+
const { saveAs } = require("file-saver");
|
|
3
|
+
return saveAs(file, file.name);
|
|
4
|
+
};
|
|
5
|
+
const createFile = async (text, filename = "file.json", type = "application/json") => {
|
|
6
|
+
return new File([new Blob([text], { type })], filename);
|
|
7
|
+
};
|
|
8
|
+
const openFile = () => new Promise((res, rej) => {
|
|
9
|
+
const input = document.createElement("input");
|
|
10
|
+
input.type = "file";
|
|
11
|
+
input.addEventListener("change", function readFile(e) {
|
|
12
|
+
input.removeEventListener("change", readFile);
|
|
13
|
+
const [file] = e.target.files;
|
|
14
|
+
if (!file) return;
|
|
15
|
+
const reader = new FileReader();
|
|
16
|
+
reader.onload = (e2) => res(e2.target?.result);
|
|
17
|
+
reader.onerror = rej;
|
|
18
|
+
reader.onabort = rej;
|
|
19
|
+
reader.readAsText(file);
|
|
20
|
+
});
|
|
21
|
+
input.click();
|
|
22
|
+
});
|
|
23
|
+
export {
|
|
24
|
+
createFile,
|
|
25
|
+
downloadFile,
|
|
26
|
+
openFile
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +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 as string);\n reader.onerror = rej;\n reader.onabort = rej;\n reader.readAsText(file);\n });\n input.click();\n });\n"],"names":["e"],"mappings":"AAAO,MAAM,eAAe,OAAO,SAA8B;AAE7D,QAAM,EAAE,OAAA,IAAW,QAAQ,YAAY;AAGvC,SAAO,OAAO,MAAM,KAAK,IAAI;AACjC;AAEO,MAAM,aAAa,OAAO,MAAW,WAAW,aAAa,OAAO,uBAAsC;AAC7G,SAAO,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,KAAA,CAAM,CAAC,GAAG,QAAQ;AAC1D;AAEO,MAAM,WAAW,MACpB,IAAI,QAAQ,CAAC,KAAK,QAAQ;AACtB,QAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,QAAM,OAAO;AACb,QAAM,iBAAiB,UAAU,SAAS,SAAS,GAAG;AAClD,UAAM,oBAAoB,UAAU,QAAQ;AAE5C,UAAM,CAAC,IAAI,IAAI,EAAE,OAAO;AACxB,QAAI,CAAC,KAAM;AACX,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,SAAS,CAACA,OAAM,IAAIA,GAAE,QAAQ,MAAgB;AACrD,WAAO,UAAU;AACjB,WAAO,UAAU;AACjB,WAAO,WAAW,IAAI;AAAA,EAC1B,CAAC;AACD,QAAM,MAAA;AACV,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.test.d.ts","sourceRoot":"","sources":["../src/files.test.ts"],"names":[],"mappings":""}
|
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,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/ls.d.ts
ADDED
package/dist/ls.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../src/ls.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG;IACtC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,GAAG,CAAC;IAClC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAUA"}
|
package/dist/ls.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function getStorage(pref) {
|
|
2
|
+
const prefix = (key) => `${pref}-${key}`;
|
|
3
|
+
const ls = typeof window !== "undefined" ? localStorage : null;
|
|
4
|
+
const read = (key) => JSON.parse(ls?.getItem(prefix(key)) || "null");
|
|
5
|
+
const write = (key, value) => ls?.setItem(prefix(key), JSON.stringify(value));
|
|
6
|
+
const remove = (key) => ls?.removeItem(prefix(key));
|
|
7
|
+
return { read, write, remove };
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
getStorage
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=ls.js.map
|
package/dist/ls.js.map
ADDED
|
@@ -0,0 +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"],"names":[],"mappings":"AAAO,SAAS,WAAW,MAIzB;AACE,QAAM,SAAS,CAAC,QAAQ,GAAG,IAAI,IAAI,GAAG;AAEtC,QAAM,KAAM,OAAO,WAAW,cAAc,eAAe;AAE3D,QAAM,OAAO,CAAC,QAAqB,KAAK,MAAM,IAAI,QAAQ,OAAO,GAAG,CAAC,KAAK,MAAM;AAChF,QAAM,QAAQ,CAAC,KAAa,UAAqB,IAAI,QAAQ,OAAO,GAAG,GAAG,KAAK,UAAU,KAAK,CAAC;AAC/F,QAAM,SAAS,CAAC,QAAsB,IAAI,WAAW,OAAO,GAAG,CAAC;AAEhE,SAAO,EAAE,MAAM,OAAO,OAAA;AAC1B;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls.test.d.ts","sourceRoot":"","sources":["../src/ls.test.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kirill.konshin/browser",
|
|
3
|
+
"description": "Browser Utilities",
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"----- BUILD -----": "",
|
|
8
|
+
"clean": "rm -rf dist .tscache tsconfig.tsbuildinfo",
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"build:index": "ctix build",
|
|
11
|
+
"build:check-types": "attw --pack .",
|
|
12
|
+
"start": "yarn build --watch",
|
|
13
|
+
"wait": "wait-on ./dist/index.js",
|
|
14
|
+
"----- TEST -----": "",
|
|
15
|
+
"test": "vitest run --coverage",
|
|
16
|
+
"test:watch": "vitest watch --coverage",
|
|
17
|
+
"----- STORYBOOK -----": "",
|
|
18
|
+
"storybook:start": "storybook dev -p 6006",
|
|
19
|
+
"storybook:build": "storybook build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"file-saver": "^2.0.5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@kirill.konshin/utils-private": "*"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"author": "Kirill Konshin <kirill@konshin.org> (https://konshin.org)",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"main": "./dist/index.js",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"peerDependenciesMeta": {}
|
|
44
|
+
}
|
package/src/files.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
ADDED
package/src/ls.test.ts
ADDED
package/src/ls.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
package/turbo.json
ADDED
package/vite.config.ts
ADDED