npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rn-common/file

v0.1.1

Published

This module provides a set of utility functions for working with the file system in React Native, using Expo's `FileSystem` API. It includes functions for creating directories, reading and writing files, deleting files and folders, and managing downloads.

Downloads

2

Readme

@rn-common/file

This module provides a set of utility functions for working with the file system in React Native, using Expo's FileSystem API. It includes functions for creating directories, reading and writing files, deleting files and folders, and managing downloads.

Installation

Install using:

npx expo install @rn-common/file expo-file-system

Exports

Directories

  • DocumentDirectory: The document directory path.
  • CacheDirectory: The cache directory path.

Functions

mkdir(dir: string)

Creates a new directory at the specified path, including any necessary intermediate directories.

Parameters:

  • dir (string): The path of the directory to create.

Returns:

  • Promise<void>: Resolves when the directory is created.

Example:

await mkdir('/path/to/new/directory')

readFile(filePath: string, options?: FileSystem.ReadingOptions)

Reads the contents of a file as a string.

Parameters:

  • filePath (string): The path of the file to read.
  • options (FileSystem.ReadingOptions): Optional settings for reading the file.

Returns:

  • Promise<string>: The contents of the file.

Example:

const contents = await readFile('/path/to/file.txt')

writeFile(filePath: string, contents: string, options?: FileSystem.WritingOptions)

Writes content to a file.

Parameters:

  • filePath (string): The path of the file to write to.
  • contents (string): The content to write.
  • options (FileSystem.WritingOptions): Optional settings for writing the file.

Returns:

  • Promise<void>: Resolves when the file is written.

Example:

await writeFile('/path/to/file.txt', 'Hello, World!')

removeFile(filePath: string)

Deletes a file at the specified path.

Parameters:

  • filePath (string): The path of the file to delete.

Returns:

  • Promise<void>: Resolves when the file is deleted.

Example:

await removeFile('/path/to/file.txt')

removeFolder(folderPath: string)

Deletes a folder and all its contents.

Parameters:

  • folderPath (string): The path of the folder to delete.

Returns:

  • Promise<void>: Resolves when the folder and its contents are deleted.

Example:

await removeFolder('/path/to/folder')

extractFilename(filePath: string, withExtension = true)

Extracts the filename from a given file path.

Parameters:

  • filePath (string): The file path.
  • withExtension (boolean, default: true): Whether to include the file extension.

Returns:

  • string: The extracted filename.

Example:

const filename = extractFilename('/path/to/file.txt') // 'file.txt'
const nameWithoutExtension = extractFilename('/path/to/file.txt', false) // 'file'

extractExtension(filePath: string)

Extracts the file extension from a given file path.

Parameters:

  • filePath (string): The file path.

Returns:

  • string: The file extension.

Example:

const extension = extractExtension('/path/to/file.txt') // 'txt'

joinPath(...paths: string[])

Joins multiple path segments into a single path.

Parameters:

  • ...paths (string[]): Path segments.

Returns:

  • string: The combined path.

Example:

const fullPath = joinPath('/path', 'to', 'file.txt') // '/path/to/file.txt'

createDownloadFile({ uri, filePath, options, onProgress })

Initiates a file download from a specified URI.

Parameters:

  • uri (string): The URI of the file to download.
  • filePath (string): The local path to save the downloaded file.
  • options (FileSystem.DownloadOptions): Optional download settings.
  • onProgress (function): Callback for download progress.

Returns:

  • Object: Methods to control the download (download, pause, resume, cancel) and the uri of the downloaded file.

Example:

const { download, pause, resume, cancel, uri } = createDownloadFile({
  uri: 'https://example.com/file.zip',
  filePath: '/path/to/file.zip',
  onProgress: (progress) => console.log(`Download progress: ${progress}%`),
})
await download()