# @elanine/leo-utils

> 为 leo 及其生态提供的工具库

Latest version **1.0.0** (published 2022-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @elanine/leo-utils
pnpm add @elanine/leo-utils
yarn add @elanine/leo-utils
bun add @elanine/leo-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-04 |
| First published | 2022-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 304 |
| Author | elanine |
| Maintainers | elanine |

## Links

- npm: https://www.npmjs.com/package/@elanine/leo-utils
- Repository: https://github.com/JDFED/leo
- Homepage: https://github.com/JDFED/leo#readme
- Issues: https://github.com/JDFED/leo/issues
- npm.io page: https://npm.io/package/@elanine/leo-utils

## Dependencies (7)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [signale](https://npm.io/package/signale.md) ^1.4.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [npminstall](https://npm.io/package/npminstall.md) ^4.11.0
- [global-dirs](https://npm.io/package/global-dirs.md) ^3.0.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2
- [compare-versions](https://npm.io/package/compare-versions.md) ^3.6.0

## Recent versions

- 1.0.0 (latest) — 2022-03-04

## README

# leo-utils

为 leo 及其生态提供的工具库

## loadPkg

动态加载

### 基础使用

```js
import { loadPkg } from '@leo/leo-utils';

(async () => {
  const puppeteer = await loadPkg('puppeteer', '10.0.0');
})();
```

### 高级使用

```js
import { loadPkg, log } from '@leo/leo-utils';

(async () => {
  const puppeteer = await loadPkg('puppeteer', {
    version: '10.0.0',
    private: true,
    beforeInstall: () => {
      log.info('Log info when beforeInstall');
    },
    installSuccess: () => {
      log.success('Log info when installSuccess');
    },
    installFail: () => {
      log.error('Log info when installFail');
    },
  });
})();
```

### API

#### loadPkg

| 属性名                         | 描述                     | 类型                                       | 默认值  |
| ------------------------------ | ------------------------ | ------------------------------------------ | ------- |
| name                           | 安装路径                 | `string`                                   | `--`    |
| versionOrOptions               | 版本号或相关配置         | `string` / `object`                        | `--`    |
| versionOrOptions.version       | 版本号                   | `string`                                   | `false` |
| versionOrOptions.dev           | 本次安装是否为开发模式   | `boolean`                                  | `false` |
| versionOrOptions.private       | 是否将安装的包单独隔离   | `boolean`                                  | `false` |
| versionOrOptions.beforeInstall | 本次安装后执行的声明周期 | `(name: string, version?: string) => void` | `--`    |
| versionOrOptions.afterInstall  | 本次安装前执行的声明周期 | `(name: string, version?: string) => void` | `--     |

## log

基于 [signale](https://www.npmjs.com/package/signale) 封装的 log 工具

### 基础使用

```js
import { log } from '@leo/leo-utils';

log.error('');
log.fatal('');
log.fav('');
log.info('');
log.star('');
log.success('');
log.wait('');
log.warn('');
log.complete('');
log.pending('');
log.note('');
log.start('');
log.pause('');
log.debug('');
log.await('');
log.watch('');
log.log('');
```

### 高级使用

```js
import { log } from '@leo/leo-utils';

// 在输出时标识你的作用域，用于区分输出
const myLog = log.scope('plugin scope');

myLog.info('info');

// [plugin scope] › ℹ  info      Info will has scope remark
```

### 注意

- `log.debug` 是否输出由 `leoConfig.isDebug` 来控制，你可以通过使用 `log.debug` 来定位线上问题

---
_Source: https://npm.io/package/@elanine/leo-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
