Skip to content

Commit

Permalink
Update docs, test build name
Browse files Browse the repository at this point in the history
  • Loading branch information
perry-mitchell committed Feb 24, 2024
1 parent e9b9c54 commit 184665a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Version 5 upgrades the library to use ESM (ECMAScript Modules), and so your envi

* NodeJS project with `"type": "module"` in `package.json` (ESM mode)
* Web project bundled with a tool like Webpack that can handle ESM
* React-native projects (via direct import or using automatic react-native entry)

If you're not ready to upgrade, you may consider using version 4 of this library.

Expand Down Expand Up @@ -65,6 +66,14 @@ Versions 3/4 supported a UMD-style module in the browser, but this is no longer

**NB:** Streams are not available within the browser, so `createReadStream` and `createWriteStream` are just stubbed. Calling them will throw an exception.

#### React-Native support

React-Native is better supported as of version `5.4.0`, using a specific build for the platform. The import should be automatic, but can be forced by importing from `/react-native` directly:

```typescript
import { createClient } from "webdav/react-native";
```

### Types

Typescript types are exported with this library for the Node build. All of the types can also be directly imported from the module:
Expand Down
7 changes: 7 additions & 0 deletions source/compat/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
declare var TARGET: "web" | "react-native" | undefined;

export function getDebugBuildName(): string {
if (typeof TARGET === "string") {
return TARGET;
}
return "node";
}

export function isReactNative(): boolean {
return typeof TARGET === "string" && TARGET === "react-native";
}
Expand Down
7 changes: 7 additions & 0 deletions test/web/compat/env.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { getDebugBuildName } from "../../../source/compat/env.js";

describe("getDebugBuildName", () => {
it("outputs 'web'", () => {
expect(getDebugBuildName()).to.equal("web");
});
});
2 changes: 1 addition & 1 deletion test/web/tools/size.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { calculateDataLength } from "../../../source/tools/size.js";

describe("calculateDataLength", () => {
it("Correctly calculates length for utf-8 string", () => {
it("correctly calculates length for utf-8 string", () => {
const utf8String = "řeřicha";
expect(calculateDataLength(utf8String)).to.equal(9);
});
Expand Down

0 comments on commit 184665a

Please sign in to comment.