@humanfs/core
以 尼古拉斯·扎卡斯
如果你觉得有用,请考虑支持我的工作 捐赠 或者说 提名我 为吉他之星.
说明
在所有运行时间的所有执行中共享的人机核心功能. 本套件的内容有意是运行时间不可知的,并非打算单独使用.
目前,这个软件包只是输出 Hfs 类,这是一个抽象的基础类,意在从运行时特定的hfs包中继承(如 @humanfs/node) (中文(简体) ).
[尖叫声] 这个项目是 实验 在v1.0.0之前可能会发生重大变化。 用你自己的谨慎,绝对不要生产!
安装
节点.js
使用您最喜欢的节点软件包管理器安装 :
npm install @humanfs/core
# or
pnpm install @humanfs/core
# or
yarn add @humanfs/core
# or
bun install @humanfs/core
然后你可以导入 Hfs 财务报告和审定财务报表 Path 像这样的课程 :
import { Hfs, Path } from "@humanfs/core";
德诺
使用 日 尔数字 :
deno add @humanfs/core
# or
jsr add @humanfs/core
然后你可以导入 Hfs 像这样的课:
import { Hfs, Path } from "@humanfs/core";
浏览器
建议导入精密版本以节省带宽:
import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core?min";
然而,您也可以导入未修改的版本用于调试:
import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core";
使用量
Hfs 类
这个 Hfs 类包含一个 Hfs 实例 无 预定义的 impl。 此类主要用于创建运行时间特定简表, 例如 NodeHfs 财务报告和审定财务报表 DenoHfs。 。 。 .
您可以通过提供 impl 直接 :
const hfs = new Hfs({ impl: { async text() {} }});
指定的 impl 成为实例的基础 , 意思是, 你总是可以重置回它 resetImpl()。 。 。 .
您也可以继承 Hfs 用预设的简便来创建自己的课程,例如:
class MyHfs extends Hfs {
constructor() {
super({
impl: myImpl
});
}
}
Path 类
这个 Path 类代表文件系统内目录或文件的路径。 它是一种抽象的表示方式,即使在传统文件系统之外也可以使用,在传统文件系统中,字符串路径可能不合理.
const myPath = new Path(["dir", "subdir"]);
console.log(myPath.toString()); // "dir/subdir"
// add another step
myPath.push("file.txt");
console.log(myPath.toString()); // "dir/subdir/file.txt"
// get just the last step
console.log(myPath.name); // "file.txt"
// change just the last step
myPath.name = "file.json";
console.log(myPath.name); // "file.json"
console.log(myPath.toString()); // "dir/subdir/file.json"
// get the size of the path
console.log(myPath.size); // 3
// remove the last step
myPath.pop();
console.log(myPath.toString()); // "dir/subdir"
// iterate over the steps
for (const step of myPath) {
// do something
}
// create a new path from a string
const newPath = Path.fromString("/foo/bar");
许可证
Apache 2.0 (英语)