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

fs-aw

v0.0.10

Published

use file system abstraction layer for the browser, miniapp like in NodeJs

Downloads

21

Readme

fs-aw

Multiterminal fs abstraction layer 由Typescript编写的一个多平台文件系统抽象层,帮助你在不同的平台,使用同一套逻辑操作文件系统,默认支持Tree Shaking

使用场景

  1. 需要在 H5小程序WEEX 内存储文件
  2. 在使用Taro 或者 uniapp 开发多平台跨端应用时,碰到一些大文件(大于5MB)的缓存需求,但因为web、小程序、weex等平台的文件操作API,或者是根本没有相关的文件缓存API,一切都需要需要重新设计实现,fs-aw 提供了一套行为完全一致的文件系统,借鉴 nodefs 模块实现的前端工具库,帮助你快速的在不同的平台拥有一个文件管理系统。

快速开始

安装

npm install fs-aw

⚠️注意:fs-aw 因为跨平台统一api的原因,只支持异步调用!

fs-aw设计为按需引入,请根据你当前的平台自行选择抽象层,所有平台的API行为均一致

在H5项目中使用

// 主文件默认导出为web平台
import { webFs as fs } from 'fs-aw';
const main = async () => {
    await fs.writeFile('/test/test.txt', 123);
    const content = await fs.readFile('/test/test.txt', 'utf8');
    console.log(content);
}
main();
// 123

在小程序项目中使用

// 引入小程序专用抽象层
import { miniFs as fs } from 'fs-aw';
const main = async () => {
    await fs.writeFile('/test/test.txt', 123);
    const content = await fs.readFile('/test/test.txt', 'utf8');
    console.log(content);
}
main();
// 123

支持平台

| 平台 | 是否支持 | 测试通过 |实现方式| | ---- | ---- |----|----| | web平台 | ✅ |✅|IndexDB| | 支付宝小程序 | ✅ |✅|FileSystemManager| | 微信小程序 | ✅ |❌|FileSystemManager| | 字节小程序 | ✅ |❌|FileSystemManager| | 百度小程序 | ✅ |❌|FileSystemManager| | ReactNative|❌| ❌| 暂无| | Weex | ❌| ❌ | localStorage| | node | ❌ |❌|fs模块|

还有很多常用的JS平台与常用的API没有实现,欢迎大家共建

API

// 读取文件
declare const readFile: (fileName: string, encoding?: EncodingType) => Promise<any>;
// 写入文件(默认递归创建文件夹)
declare const writeFile: (fileName: string, data: any) => Promise<boolean>;
// 删除文件
declare const removeFile: (fileName: string) => Promise<boolean>;
// 读取文件夹
declare const readdir: (directoryName: string, options?: {
    withFileTypes?: boolean;
}) => Promise<DirectoryEntry[]>;
interface Stat {
    isFile(): boolean;
    isDirectory(): boolean;
}
// 获取文件状态
declare const stat: (filePath: string) => Promise<Stat | null>;
// 创建文件夹(默认递归创建)
declare const mkdir: (fullPath: string) => Promise<boolean>;
// 删除文件夹(默认递归删除)
declare const rmdir: (fullPath: string) => any;
// 判断路径是否存在 (同名文件与文件夹均会存在)
declare const exists: (filePath: string) => Promise<boolean>;

Test

所有API都通过对应平台测试

web

# install
pnpm install

# build
pnpm run build

# test
pnpm run test

alipay-miniapp

注意!部分版本的支付宝小程序开发者工具文件操作系统api不完全,请在真机调试内测试

1. 使用支付宝小程序开发者工具打开 `test/alipay-test` 文件夹
2. 使用真机调试编译
3. 编译完成后扫码观察控制台所有测试用例通过