fire-keeper
TypeScript icon, indicating that this package has built-in type declarations

0.0.214 • Public • Published

Fire Keeper

一个简单的工具箱。

安装

pnpm i fire-keeper

使用

首先,在代码中引入模块。

import $ from 'fire-keeper'

之后就可以愉快地玩耍啦。

$.echo('hello world')

当然,也可以按需加载。

import echo from 'fire-keeper/dist/echo'
echo('hello world')

构建

npm run build

测试

npm run test

文档

argv

获取argv

const argv = $.argv()

backup

备份文件。

await $.backup('./readme.md') // 生成`./readme.md.bak`

copy

复制文件。

await $.copy('./readme.md', './temp')

download

下载文件。

await $.download('http://example.com', './temp')

echo

在控制台显示信息。

$.echo('hello world')
$.echo('error', 'a error message')

exec

执行命令。

await $.exec('npm run build')

getBasename

获取basename

const basename = $.getBasename('./readme.md') // `readme`

getDirname

获取dirname

const dirname = $.getDirname('./readme.md') // `./`的绝对路径

getExtname

获取extname

const extname = $.getExtname('./readme.md') // `.md`

getFilename

获取filename

const filename = $.getFilename('./readme.md') // `readme.md`

getName

获取文件名。

const name = $.getName('./readme.md')

getType

获取类型。

const type = $.getType(42) // number

glob

获取文件列表。

const listSource = await $.glob('./source/**/*')

home

获取用户主目录。

const home = $.home()

isExist

判断文件是否存在。

const isExist = await $.isExist('./readme.md')

isSame

判断两个文件是否相同。

const isSame = await $.isSame('./readme.md', './readme.md.bak')

link

创建软链接。

await $.link('./readme.md', './temp/readme.md')

mkdir

创建目录。

await $.mkdir('./temp')

move

移动文件。

await $.move('./readme.md', './temp')

normalizePath

规范化路径。

const path = $.normalizePath('./readme.md')

os

获取操作系统类型。

const os = $.os()

prompt

提示用户输入。

const answer = await $.prompt({
  list: ['a', 'b', 'c'],
  message: 'choose a letter',
  type: 'select',
})

read

读取文件。

const content = await $.read('./readme.md')

recover

恢复文件。

await $.recover('./readme.md') // 从`./readme.md.bak`恢复

remove

删除文件。

await $.remove('./temp')

rename

重命名文件。

await $.rename('./readme.md', 'readme-new.md')

root

获取项目根目录。

const root = $.root()

sleep

休眠。

await $.sleep(1e3)

stat

获取文件状态。

const stat = await $.stat('./readme.md')

toArray

转换为数组。

const list = $.toArray('hello world') // `['hello world']`

toDate

转换为日期。

const date = $.toDate('2020-01-01') // `new Date('2020-01-01')`

toJson

转换为JSON

const json = $.toJson('{"a":1}') // `{a:1}`

toString

转换为字符串。

const string = $.toString(42) // `'42'`

watch

监听文件变化。

$.watch('./source/**/*', (path) => $.echo(path))

write

写入文件。

await $.write('./readme.md', 'hello world')

zip

压缩文件。

await $.zip('./source/**/*', './temp/source.zip')

Readme

Keywords

Package Sidebar

Install

npm i fire-keeper

Weekly Downloads

35

Version

0.0.214

License

MIT

Unpacked Size

361 kB

Total Files

189

Last publish

Collaborators

  • phonowell