
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
a-node-tools
Advanced tools
一个纯函数的工具,包含了
readFileToJson
读取 .json
文件并返回 JSON 或空对象 null
readFileToJsonSync
同步读取 .json
文件并返回 JSON
或空对象 null
fileExist
文件是否存在dirEmpty
目录是否为空writeJsonFile
把 json
数据写入空白文件runOtherCode
运行其他代码RunOtherCodeParam
运行其他代码的参数类型声明waitingTips
一个用于等待的简单终端提示waitingTipsPrefixStore
用于自定义 waitingTips
的等待的前缀 emojirunOtherCode
简单执行其他的命令,请注意,请不要将用户输入当作 code
值传入方法,执行有风险,且调且珍惜
import { runOtherCode } from 'a-node-tools';
const result = await runOtherCode({
code: 'ls',
printLog: true,
});
npmPkg
模块getPkgInfoResult
方法 getNpmPkgInfo
的返回值类型getNpmPkgInfo
获取 npm 包信息testNpmPackageExist
测试包是否可下载存在现可通过第二参数指定 npm registry 源
可接受参数
type npmRegistry = '官方' | '淘宝' | '腾讯' | '中科大' | 'yarn';
各源的测试情况
由上图可见,使用 淘宝
源时,延迟相对较低。而有些国内源都没有 npm
原源(但是各源有各源的用途,譬如,如果是在腾讯云服务器部署的服务,当然是使用腾讯的 npm 源比较快啦,举衣反山)延迟低。
pathJoin
文件地址拼接pathBasename
给出文件路径获取文件名,不带文件类型后缀initializeFile
初始化路径 __filename
和 __dirname
,因为这两个仅能在 cjs
文件下使用,使用这里做了初始化,兼容getCallerFilename
获取调用函数的文件路径isWindows
当前是否为 windows 环境,用于在使用 path
时分隔符不同产生的差异getDirectoryBy
根据目标的文件或文件名来找到存在该目标的父级目录你可以使用 cursor 进行对光标位置进行操控:
方法 | 示意 | 参数 |
---|---|---|
_p | 在 node 环境下的打印 | r 打印的文本; lineFeed 是否换行,缺省为 true |
cursorHide | 光标隐藏 | -- |
cursorShow | 光标展示 | -- |
cursorPositionSave | 储存光标位置 | -- |
cursorPositionRestore | 恢复光标位置 | -- |
cursorMoveUp | 光标上移 | numberOfUpwardMoves 偏移量,缺省 1 |
cursorMoveDown | 光标下移 | numberOfMovesDown 偏移量,缺省 1 |
cursorMoveLeft | 光标左移 | numberOfLeftShifts 偏移量,缺省 1 |
cursorMoveRight | 光标右移 | numberOfRightShifts 偏移量,缺省 1 |
cursorAfterClear | 光标后内容🧹 | -- |
cursorLineAfterClear | 清理光标所在行光标位置后的内容 | |
cursorLineBeforeClear | 清理光标所在行光标位置前的内容 | |
cursorLineClear | 清理光标所在行的所有内容 |
terminalPageUp
终端整页向上滚动terminalPageOn
终端整页下翻terminalScrollScreen
全屏滚动terminalScrollBetween
设定终端可滚动范围等待用户输入的一个函数。因为要等待,所以是异步的,使用的时候应当使用 await
例:
import { isTrue } from 'a-type-of-js';
import { readInput , _p} from "a-node-tools";
// 不建议使用异步函数,因为我想不到使用场景,所以移除了相关的判断
const callBackFunction = (keyValue: string | undefined, key:any)
=> {
/// 自定义当遇到某一个钟意的键则可以返回,这里只是示例,没有说必须要 `enter` 键才可以
if(key.name && key.name == 'return') {
return true;
}
else {
// 如果返回的是非 `true` 则不会触发异步事件的 resolve 事件
return _p(`换一个键试试,这个键(${keyValue})不允许退出`);
}
};
async function main() {
const result = await readInput(callBackFunction)
// 从 `v4` 版本开始,`Ctrl` + `C` 不再强制退出,而是交予您处理
if (isTrue(result.isSIGINT)) {
_p('老逼登你要干么?你以为按一个 `Ctrl` + `C` 就能退出去了?');
_p('try again 啊!');
_p('有本事拔电线呀!');
await main();
}
}
await main();
一个简单的 process.stdout.write 的封装,用于在 node 环境向终端输入内容
import { _p } from 'a-node-tools';
_p('hello'); // hello
_p('hello', false); // hello (打印完不换行,光标依旧在 o 后面)
一条彩色的分割线:
import { colorLine } from 'a-node-tools';
colorLine(); // 打印一个彩色分割线
colorLine('就是玩'); // 打印一个彩色分割线,中间是文本: “就是玩”
colorLine('就是玩', true); // 打印一个彩色分割线,中间是彩色文本: “就是玩”
colorLine('就是玩', '#f21'); // 打印一个彩色分割线,中间是红色文本: “就是玩”
一个简单的打字机效果,用于在终端输入内容
import { typewrite } from 'a-node-tolls';
await typewrite(
'伟大的中华人民共和国万岁!\n伟大的中国共产党万岁!\n伟大的中国人民解放军万岁!\n全国各族人民大团结万岁!\n伟大的中国人民万岁!',
);
在引用该包的包内使用该包内的方法时,可以使用启动参数 a_node_tools_dev=xxx
来启用部分方法的日志。
xxx
可用的值为:
"all"
"error"
"warn"
"info"
"true"
"false"
在使用 a_node_tools_dev
参数值为上面的值时,将会覆盖原配置的参数值,甚至是在代码中配置值也将被覆盖。
代码内下面的值配置 ANodeToolsDevLog.type
该值将会原配置值,是运行时配置
参看 https://earthnut.dev/a-node-tools/
推荐使用 nry 切换 npm 源
以下源不支持 npm
FAQs
一点点 🤏 node 函数
The npm package a-node-tools receives a total of 85 weekly downloads. As such, a-node-tools popularity was classified as not popular.
We found that a-node-tools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.