diff --git a/README.md b/README.md index 198f6789..6d99e2a2 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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: diff --git a/source/compat/env.ts b/source/compat/env.ts index c84e7481..a6cb909e 100644 --- a/source/compat/env.ts +++ b/source/compat/env.ts @@ -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"; } diff --git a/test/web/compat/env.spec.js b/test/web/compat/env.spec.js new file mode 100644 index 00000000..c983711e --- /dev/null +++ b/test/web/compat/env.spec.js @@ -0,0 +1,7 @@ +import { getDebugBuildName } from "../../../source/compat/env.js"; + +describe("getDebugBuildName", () => { + it("outputs 'web'", () => { + expect(getDebugBuildName()).to.equal("web"); + }); +}); diff --git a/test/web/tools/size.spec.js b/test/web/tools/size.spec.js index 8873cc43..233cdc5f 100644 --- a/test/web/tools/size.spec.js +++ b/test/web/tools/size.spec.js @@ -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); });