@zenfs/dom 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/fetch.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  export declare const fetchIsAvailable: boolean;
3
2
  /**
4
3
  * Asynchronously download a file as a buffer or a JSON object.
@@ -7,9 +6,9 @@ export declare const fetchIsAvailable: boolean;
7
6
  * constants.
8
7
  * @hidden
9
8
  */
10
- export declare function fetchFile(p: string, type: 'buffer'): Promise<Buffer>;
9
+ export declare function fetchFile(p: string, type: 'buffer'): Promise<Uint8Array>;
11
10
  export declare function fetchFile(p: string, type: 'json'): Promise<any>;
12
- export declare function fetchFile(p: string, type: string): Promise<any>;
11
+ export declare function fetchFile(p: string, type: 'buffer' | 'json'): Promise<any>;
13
12
  /**
14
13
  * Asynchronously retrieves the size of the given file in bytes.
15
14
  * @hidden
package/dist/fetch.js CHANGED
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  /**
11
11
  * Contains utility methods for network I/O (using fetch)
12
12
  */
13
- import { Buffer } from 'buffer';
14
13
  import { ApiError, ErrorCode } from '@zenfs/core/ApiError.js';
15
14
  export const fetchIsAvailable = typeof fetch !== 'undefined' && fetch !== null;
16
15
  /**
@@ -27,11 +26,10 @@ export function fetchFile(p, type) {
27
26
  }
28
27
  switch (type) {
29
28
  case 'buffer':
30
- const buf = yield response.arrayBuffer().catch(convertError);
31
- return Buffer.from(buf);
29
+ const arrayBuffer = yield response.arrayBuffer().catch(convertError);
30
+ return new Uint8Array(arrayBuffer);
32
31
  case 'json':
33
- const json = yield response.json().catch(convertError);
34
- return json;
32
+ return response.json().catch(convertError);
35
33
  default:
36
34
  throw new ApiError(ErrorCode.EINVAL, 'Invalid download type: ' + type);
37
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -26,35 +26,31 @@
26
26
  "exports": {
27
27
  "./*": "./dist/*"
28
28
  },
29
+ "typesVersions": {
30
+ "*": {
31
+ "*": [
32
+ "./dist/*"
33
+ ]
34
+ }
35
+ },
29
36
  "scripts": {
30
37
  "format": "prettier --write src",
31
38
  "format:check": "prettier --check src",
32
39
  "lint": "eslint src",
33
- "test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
34
40
  "build": "node scripts/build.mjs",
35
- "build:docs": "typedoc --out docs --name ZenFS src/index.ts",
41
+ "build:docs": "typedoc --out docs --name 'ZenFS DOM' src/index.ts",
36
42
  "prepublishOnly": "npm run build"
37
43
  },
38
44
  "devDependencies": {
39
- "@jest/globals": "^29.5.0",
40
- "@types/jest": "^29.5.1",
41
- "@types/node": "^14.18.62",
42
45
  "@typescript-eslint/eslint-plugin": "^5.55.0",
43
46
  "@typescript-eslint/parser": "^5.55.0",
44
- "archiver": "~2.1.1",
45
- "buffer": "~5.1.0",
46
- "cross-env": "^7.0.3",
47
47
  "esbuild": "^0.17.18",
48
- "esbuild-plugin-polyfill-node": "^0.3.0",
49
48
  "eslint": "^8.36.0",
50
- "jest": "^29.5.0",
51
- "path": "^0.12.7",
52
49
  "prettier": "^2.8.7",
53
- "ts-jest": "^29.1.0",
54
50
  "typedoc": "^0.25.1",
55
51
  "typescript": "5.2.2"
56
52
  },
57
53
  "dependencies": {
58
- "@zenfs/core": "^0.0.6"
54
+ "@zenfs/core": "^0.0.11"
59
55
  }
60
56
  }
package/readme.md CHANGED
@@ -19,22 +19,15 @@ For more information, see the [API documentation](https://zen-fs.github.io/fs-do
19
19
  npm install @zenfs/fs-dom
20
20
  ```
21
21
 
22
- ## Building
23
-
24
- - Make sure you have Node and NPM installed. You must have Node v18 or newer.
25
- - Install dependencies with `npm install`
26
- - Build using `npm run build`
27
- - You can find the built code in `dist`.
28
-
29
22
  ## Usage
30
23
 
31
- > 🛈 The examples are written in ESM. If you are using CJS, you can `require` the package. If running in a borwser you can add a script tag to your HTML pointing to the `browser.min.js` and use ZenFS DOM via the global `ZenFS_DOM` object.
24
+ > 🛈 The examples are written in ESM. If you are using CJS, you can `require` the package. If running in a browser you can add a script tag to your HTML pointing to the `browser.min.js` and use ZenFS DOM via the global `ZenFS_DOM` object.
32
25
 
33
26
  You can use DOM backends, though you must register them if you plan on using `configure`:
34
27
 
35
28
  ```js
36
29
  import { configure, fs, registerBackend } from '@zenfs/core';
37
- import { Storage } '@zenfs/fs-dom';
30
+ import { Storage } from '@zenfs/fs-dom';
38
31
 
39
32
  registerBackend(Storage);
40
33
  await configure({ fs: 'Storage', options: { storage: localStorage } });
@@ -46,7 +39,3 @@ if (!fs.existsSync('/test.txt')) {
46
39
  const contents = fs.readFileSync('/test.txt', 'utf-8');
47
40
  console.log(contents);
48
41
  ```
49
-
50
- ### Testing
51
-
52
- Run unit tests with `npm test`.