@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 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
+ vite v7.0.6 building SSR bundle for production...
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
+ ✓ 3 modules transformed.
12
+ rendering chunks...
13
+
14
+ [vite:dts] Start generate declaration files...
15
+ dist/index.js 0.20 kB │ map: 0.09 kB
16
+ dist/ls.js 0.44 kB │ map: 1.05 kB
17
+ dist/files.js 0.84 kB │ map: 1.89 kB
18
+ [vite:dts] Declaration files built in 1625ms.
19
+
20
+ ✓ built in 4.84s
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
+  RUN  v3.2.4 /home/runner/work/utils/utils/packages/browser
11
+ Coverage enabled with v8
12
+
13
+ ↓ src/files.test.ts (1 test | 1 skipped)
14
+ ↓ src/ls.test.ts (1 test | 1 skipped)
15
+
16
+  Test Files  2 skipped (2)
17
+  Tests  2 skipped (2)
18
+  Start at  03:27:03
19
+  Duration  456ms (transform 39ms, setup 0ms, collect 39ms, tests 0ms, environment 1ms, prepare 236ms)
20
+
21
+  % Coverage report from v8
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
@@ -0,0 +1,7 @@
1
+ # @kirill.konshin/browser
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 63fdba8: Divided core to browser/node/worker-specific packages, CTIX upgrade, etc.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Core Utils
@@ -0,0 +1,4 @@
1
+ export declare const downloadFile: (file: File) => Promise<void>;
2
+ export declare const createFile: (text: any, filename?: string, type?: string) => Promise<File>;
3
+ export declare const openFile: () => Promise<string>;
4
+ //# sourceMappingURL=files.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=files.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.test.d.ts","sourceRoot":"","sources":["../src/files.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './files';
2
+ export * from './ls';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,9 @@
1
+ import { createFile, downloadFile, openFile } from "./files.js";
2
+ import { getStorage } from "./ls.js";
3
+ export {
4
+ createFile,
5
+ downloadFile,
6
+ getStorage,
7
+ openFile
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
package/dist/ls.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare function getStorage(pref: string): {
2
+ read: (key: string) => null | any;
3
+ write: (key: string, value: any) => void;
4
+ remove: (key: string) => void;
5
+ };
6
+ //# sourceMappingURL=ls.d.ts.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ls.test.d.ts.map
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ import { expect, describe, test, vi } from 'vitest';
2
+
3
+ test.skip('Dummy', () => {});
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
@@ -0,0 +1,2 @@
1
+ export * from './files';
2
+ export * from './ls';
package/src/ls.test.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { expect, describe, test, vi } from 'vitest';
2
+
3
+ test.skip('Dummy', () => {});
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
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../utils-private/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "declarationDir": "dist"
7
+ },
8
+ "include": ["src"],
9
+ "exclude": []
10
+ }
package/turbo.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://turbo.build/schema.json",
3
+ "extends": ["//"],
4
+ "tasks": {
5
+ "build": {
6
+ "dependsOn": ["^build"],
7
+ "outputs": ["src/**/*/index.ts", "package.json", "dist/**/*"]
8
+ }
9
+ }
10
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,2 @@
1
+ import config from '../utils-private/vite.config';
2
+ export default config;