### Start React Native Metro Packager for Example App Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command starts the Metro server, which is necessary to run the example application. It allows for live reloading of JavaScript code changes during development. ```sh yarn example start ``` -------------------------------- ### Run React Native Example App on Android Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command builds and runs the example application on a connected Android device or emulator. It requires the Android development environment to be properly set up. ```sh yarn example android ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command installs all required dependencies for the `react-native-saf-x` project's packages. It should be run in the root directory to set up the development environment. ```sh yarn ``` -------------------------------- ### Run React Native Example App on iOS Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command builds and runs the example application on a connected iOS device or simulator. It requires Xcode and the iOS development environment to be properly configured. ```sh yarn example ios ``` -------------------------------- ### Basic Usage: Open Document Tree and Create Directory Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Demonstrates how to use `openDocumentTree` to select a base directory and then `mkdir` to create nested folders within the selected URI. This example shows the asynchronous nature of the operations and how to handle the returned URI. ```JavaScript import { openDocumentTree, mkdir } from "react-native-saf-x"; // somewhere in the app ..... async function testIt() { const doc = await openDocumentTree(true); if (doc && doc.uri) { // user has selected a directory and uri is available // you can save this uri as base directory in your app and reuse it anywhere you want await mkdir(doc.uri + '/foo/bar'); // creates foo/bar folder and subfolder at selected directory } } ``` -------------------------------- ### Install react-native-saf-x via npm or Yarn Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Instructions to add the react-native-saf-x module to your project using either npm or Yarn package managers. ```Shell npm install react-native-saf-x ``` ```Shell yarn add react-native-saf-x ``` -------------------------------- ### Get File or Directory Statistics by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Retrieves detailed statistics and metadata for a file or directory located at the specified URI. Returns a `DocumentFileDetail` object. ```APIDOC stat(uriString: string): Promise ``` -------------------------------- ### Project Scripts Reference Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md A comprehensive list of available `yarn` scripts in the `package.json` file, detailing their purpose and functionality for common development tasks. ```APIDOC yarn bootstrap: setup project by installing all dependencies and pods. yarn typescript: type-check files with TypeScript. yarn lint: lint files with ESLint. yarn test: run unit tests with Jest. yarn example start: start the Metro server for the example app. yarn example android: run the example app on Android. yarn example ios: run the example app on iOS. ``` -------------------------------- ### API Method: mkdir Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Creates a new directory at the given URI. This method automatically creates any necessary parent folders in the path, allowing for easy creation of nested directories. It rejects if the creation fails. ```APIDOC mkdir(uriString: string): Promise Description: Create a directory at given uri. Automatically creates folders in path if needed. You can use it to create nested directories easily. Rejects if it fails. Parameters: uriString: string - The URI string where the directory should be created. Returns: Promise - A promise that resolves with the DocumentFileDetail of the newly created directory. ``` -------------------------------- ### Run Unit Tests with Jest Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command executes the project's unit tests using Jest. Running tests is essential to ensure that changes do not introduce regressions and new features work as expected. ```sh yarn test ``` -------------------------------- ### Publish New Versions to npm using Release-it Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command uses `release-it` to automate the process of publishing new versions of the package to npm. It handles tasks like bumping versions, creating tags, and generating releases. ```sh yarn release ``` -------------------------------- ### API Reference: Functions Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md List of all public functions available in the react-native-saf-x module for interacting with scoped storage. ```APIDOC copyFile createDocument createFile exists getPersistedUriPermissions hasPermission listFiles mkdir moveFile openDocument openDocumentTree readFile releasePersistableUriPermission rename stat unlink writeFile ``` -------------------------------- ### API Method: listFiles Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Lists all files and folders within a specified directory URI, returning an array of detailed document file information. ```APIDOC listFiles(uriString: string): Promise Description: List all files and folders in a directory uri. Parameters: uriString: string - The URI string of the directory. Returns: Promise - A promise that resolves with an array of DocumentFileDetail objects. ``` -------------------------------- ### Create Directory by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Creates a new directory at the specified URI. Returns a `DocumentFileDetail` object for the newly created directory. ```APIDOC mkdir(uriString: string): Promise ``` -------------------------------- ### API Method: openDocument Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Opens the Android Document Picker, allowing the user to select one or more files. The result is always an array of `DocumentFileDetail` objects. ```APIDOC openDocument(options: OpenDocumentOptions): Promise Description: Open the Document Picker to select a file. DocumentFileDetail is always an array. Parameters: options: OpenDocumentOptions - Options for opening the document picker. Returns: Promise - A promise that resolves with an array of DocumentFileDetail objects for selected files, or null if the user did not select a file. ``` -------------------------------- ### API Method: stat Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Retrieves detailed information about a file or directory located at the specified URI. ```APIDOC stat(uriString: string): Promise Description: Get details for a file/directory at given uri. Parameters: uriString: string - The URI string of the file or directory. Returns: Promise - A promise that resolves with the DocumentFileDetail object containing details about the item. ``` -------------------------------- ### API Reference: Variables Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md List of public variables available in the react-native-saf-x module. ```APIDOC default: Object ``` -------------------------------- ### API Method: openDocumentTree Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Opens the Android Document Picker to allow the user to select a folder. Read/Write permissions will be granted to the selected folder. Returns an object of type `DocumentFileDetail` or `null` if the user does not select a folder. ```APIDOC openDocumentTree(persist: boolean): Promise Description: Open the Document Picker to select a folder. Read/Write Permission will be granted to the selected folder. Returns an object of type `DocumentFileDetail` or `null` if user did not select a folder. Parameters: persist: boolean - Whether to persist the URI permission for future access. Returns: Promise - A promise that resolves with the DocumentFileDetail of the selected folder, or null if the user did not select a folder. ``` -------------------------------- ### Verify Code Quality with TypeScript and ESLint Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md These commands run type checking with TypeScript and linting with ESLint to ensure code adheres to project standards. It's crucial to verify code quality before committing changes. ```sh yarn typescript yarn lint ``` -------------------------------- ### Open Document Tree Picker in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Opens the system's Document Tree Picker, allowing the user to select a directory. Returns a `DocumentFileDetail` object for the selected directory or `null` if the user cancels. The `persist` option determines if permissions are persisted. ```APIDOC openDocumentTree(persist: boolean): Promise ``` -------------------------------- ### API Method: readFile Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Reads the contents of the file pointed to by the given URI. The URI must specifically point to a file, not a directory. ```APIDOC readFile(uriString: string, options?: Pick): Promise Description: Read contents of the given uri. uri must point to a file. Parameters: uriString: string - The URI string of the file to read. options?: Pick - Optional settings, specifically for encoding. Returns: Promise - A promise that resolves with the content of the file as a string. ``` -------------------------------- ### Write Data to File (writeFile) Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Documents the `writeFile` method, which allows writing string data to a specified file URI. The method attempts to create the file if it does not already exist. It resolves with a void promise upon successful completion. ```APIDOC writeFile(uriString: string, data: string, options?: FileOperationOptions): Promise Description: Writes the given data to the file at given uri. Tries to create the file if does not already exist before writing to it. Resolves with given uriString if successful. Parameters: uriString: string - The URI of the file to write to. data: string - The data to write to the file. options?: FileOperationOptions - Optional settings for the file operation. Returns: Promise - A promise that resolves when the write operation is complete. ``` -------------------------------- ### Create Empty File at URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Creates a new empty file at the specified URI. The operation will reject if a file or directory already exists at the target URI. ```APIDOC createFile( uriString: string, options?: Pick ): Promise ``` -------------------------------- ### Open Document Picker for Existing Files in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Opens the system's Document Picker, allowing the user to select one or more existing files. Returns an array of `DocumentFileDetail` objects for the selected files or `null` if the user cancels. ```APIDOC openDocument(options: OpenDocumentOptions): Promise ``` -------------------------------- ### API Method: moveFile Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Moves a file from a source URI to a destination URI. This promise rejects if the destination already exists and the `replaceIfDestinationExists` option is not set to true. This method does not support moving directories. ```APIDOC moveFile(srcUri: string, destUri: string, options?: FileTransferOptions): Promise Description: Move file from source uri to destination uri. promise Rejects if destination already exists and `replaceIfDestinationExists` option is not set to true. Does not support moving directories. Parameters: srcUri: string - The source URI of the file to move. destUri: string - The destination URI for the file. options?: FileTransferOptions - Optional settings for the file transfer. Returns: Promise - A promise that resolves with the DocumentFileDetail of the moved file, or null if the operation fails or is cancelled. ``` -------------------------------- ### API Method: rename Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Renames the document (file or folder) at the given URI. The promise resolves with the `DocumentFileDetail` of the renamed item. ```APIDOC rename(uriString: string, newName: string): Promise Description: Renames the document at given uri. uri can be file or folder. Resolves with `true` if successful and `false` otherwise. Parameters: uriString: string - The URI string of the document (file or folder) to rename. newName: string - The new name for the document. Returns: Promise - A promise that resolves with the DocumentFileDetail of the renamed item. ``` -------------------------------- ### API Reference: Type Aliases Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Definitions for various type aliases used within the react-native-saf-x module, detailing their properties and structures. ```APIDOC CreateDocumentOptions: Type: FileOperationOptions & { initialName?: string } Defined in: index.tsx:90 DocumentFileDetail: Type: Object Properties: lastModified: number mime: string name: string size: number type: "directory" | "file" uri: string Defined in: index.tsx:70 Encoding: Type: "utf8" | "base64" | "ascii" Defined in: index.tsx:29 FileOperationOptions: Type: Object Properties: append?: boolean - Append data to the file. If not set file content will be overwritten. encoding?: Encoding - Defaults to 'utf8' mimeType?: string - mime type of the file being saved. Defaults to '*/*' Defined in: index.tsx:79 OpenDocumentOptions: Type: Object Properties: multiple?: boolean - should the file picker allow multiple documents ? persist?: boolean - should the permission of returned document(s) be persisted ? Defined in: index.tsx:103 ``` -------------------------------- ### List Files in a Directory by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Lists all files and subdirectories within the specified URI. Returns an array of `DocumentFileDetail` objects. ```APIDOC listFiles(uriString: string): Promise ``` -------------------------------- ### Open Document Picker to Save File in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Opens the system's Document Picker, allowing the user to save a file. Returns a `DocumentFileDetail` object upon successful selection, or `null` if the user cancels the operation. ```APIDOC createDocument( data: string, options?: CreateDocumentOptions ): Promise ``` -------------------------------- ### Automatically Fix Code Formatting with ESLint Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md This command attempts to automatically fix common formatting errors detected by ESLint. It helps maintain consistent code style across the project. ```sh yarn lint --fix ``` -------------------------------- ### API Method: unlink Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Removes (deletes) the file or directory at the given URI. The promise resolves with `true` if the deletion is successful, and throws an error otherwise. ```APIDOC unlink(uriString: string): Promise Description: Removes the file or directory at given uri. Resolves with `true` if delete is successful, throws otherwise. Parameters: uriString: string - The URI string of the file or directory to remove. Returns: Promise - A promise that resolves with `true` if the deletion is successful. ``` -------------------------------- ### Copy File in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Copies a file from a source URI to a destination URI. This operation does not support moving directories and will reject if the destination already exists unless `replaceIfDestinationExists` option is set to true. ```APIDOC copyFile( srcUri: string, destUri: string, options?: FileTransferOptions ): Promise ``` -------------------------------- ### Conventional Commits Specification Source: https://github.com/jd1378/react-native-saf-x/blob/main/CONTRIBUTING.md Defines the standard commit message types used in the project, adhering to the conventional commits specification. Each type indicates the nature of the change. ```APIDOC fix: bug fixes, e.g. fix crash due to deprecated method. feat: new features, e.g. add new method to the module. refactor: code refactor, e.g. migrate from class components to hooks. docs: changes into documentation, e.g. add usage example for the module.. test: adding or updating tests, e.g. add integration tests using detox. chore: tooling changes, e.g. change CI config. ``` -------------------------------- ### Write Data to File by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Writes the provided data string to a file at the specified URI. Returns a Promise that resolves when the write operation is complete. ```APIDOC writeFile( uriString: string, data: string, options?: FileOperationOptions ): Promise ``` -------------------------------- ### Check File Existence by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Checks whether a document or file exists at the given URI. Returns a boolean indicating its presence. ```APIDOC exists(uriString: string): Promise ``` -------------------------------- ### Delete File or Directory by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Deletes a file or an empty directory at the specified URI. Returns a boolean indicating success or failure. ```APIDOC unlink(uriString: string): Promise ``` -------------------------------- ### Move File in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Moves a file from a source URI to a destination URI. Returns a `DocumentFileDetail` object for the moved file or `null` if the operation fails. ```APIDOC moveFile( srcUri: string, destUri: string, options?: FileTransferOptions ): Promise ``` -------------------------------- ### Check URI Access Permission in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Determines if the application has the necessary permissions to access the specified URI. Returns a boolean indicating permission status. ```APIDOC hasPermission(uriString: string): Promise ``` -------------------------------- ### Read File Content by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Reads the content of a file located at the specified URI. Returns the file content as a string, with optional encoding. ```APIDOC readFile( uriString: string, options?: Pick ): Promise ``` -------------------------------- ### Retrieve Persisted URI Permissions in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Retrieves a list of all URIs for which the application has persisted permissions. This is useful for managing long-term access to user-granted URIs. ```APIDOC getPersistedUriPermissions(): Promise ``` -------------------------------- ### Rename File or Directory by URI in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Renames a file or directory at the specified URI to a new name. Returns a `DocumentFileDetail` object for the renamed item. ```APIDOC rename( uriString: string, newName: string ): Promise ``` -------------------------------- ### API Method: releasePersistableUriPermission Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Removes a URI from the list of persisted URI permissions, revoking long-term access to the associated content. ```APIDOC releasePersistableUriPermission(uriString: string): Promise Description: Remove a uri from persisted uri permissions list. Parameters: uriString: string - The URI string for which to release the permission. Returns: Promise - A promise that resolves when the permission has been released. ``` -------------------------------- ### Release Persistable URI Permission in React Native SAF-X Source: https://github.com/jd1378/react-native-saf-x/blob/main/README.md Releases a previously persisted URI permission, revoking long-term access to the specified URI. ```APIDOC releasePersistableUriPermission(uriString: string): Promise ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.