# joi2md

> ## Install ```shell yarn add joi2md ```

Latest version **1.1.3** (published 2019-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install joi2md
pnpm add joi2md
yarn add joi2md
bun add joi2md
```

## 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.1.3 |
| Published | 2019-08-08 |
| First published | 2019-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | flynn.yu |
| Maintainers | yujintang |

## Links

- npm: https://www.npmjs.com/package/joi2md
- Repository: https://github.com/ufo-parts/joi2md
- Homepage: https://github.com/ufo-parts/joi2md#readme
- Issues: https://github.com/ufo-parts/joi2md/issues
- npm.io page: https://npm.io/package/joi2md

## Dependencies (2)

- [joi](https://npm.io/package/joi.md) ^14.3.1
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2

## Recent versions

- 1.1.3 (latest) — 2019-08-08
- 1.1.2 — 2019-05-30
- 1.1.1 — 2019-05-13
- 1.1.0 — 2019-04-18
- 1.0.9 — 2019-04-18
- 1.0.8 — 2019-04-17
- 1.0.7 — 2019-02-14
- 1.0.6 — 2019-01-28
- 1.0.5 — 2019-01-28
- 1.0.4 — 2019-01-28
- 1.0.3 — 2019-01-28
- 1.0.2 — 2019-01-26
- 1.0.1 — 2019-01-26
- 1.0.0 — 2019-01-25

## README

## joi2md

## Install 
```shell
yarn add joi2md
```

## Use
```js
const { Joi2md, Joi } = require('joi2md');

const Jm = new Joi2md({
  name: Joi.number().default(1).required().notes('用户名'),
});

// 设置schema
Jm.setSchema({
  name: Joi.number().default(1).required().notes('用户名'),
});
// 得到markdown字符串
const result = Jm.printMd();
console.log(result);

```
> result

| 参数名 | 类型     | 必填   | 默认值 | 说明  |
|-----|--------|------|-----|-----|
| name | number | true | `1` | `用户名` |

// 设置简单json例子
```js
const { Joi2md, Joi } = require('joi2md');

const Jm = new Joi2md();

const schema = {
  a: Joi.object().keys({
    a1: Joi.string().default('hello world'),
    a2: Joi.number().default(0),
    a3: Joi.array().items(Joi.string().valid('ee'), Joi.number(), Joi.date().timestamp()),
  }),
  b: Joi.date(),
};
Jm.setSchema(schema);
const result = Jm.printJson();
console.log(result);
```
>result
```json
{
    "a":{
        "a1":"hello world",
        "a2":0,
        "a3":[
            "",
            0,
            "date"
        ]
    },
    "b":"date"
}
```
## Usage
### new Joi2md( schema )
> 初始化Joi2md对象
### setSchema( schema );
> 重新设置Joi2md对象的 Joi Schema
```js
Jm.setSchema({
    name: Joi.string().notes('姓名'),
});
```
### concatSchema( schame )
> 追加Schema，进行append或者concat动作
```js
Jm.concatSchama({
    age: Joi.number().integer().notes('年龄'),
})
```
### setPrintHeaders( [] );
> 设置md头的中文翻译，默认为：
```js
[
    ['path', '参数名'],
    ['type', '类型'],
    ['presence', '必填'],
    ['default', '默认值'],
    ['notes', '说明']
];
```
### printMd( { throws=false } )
> 输出md文件
 ```js
const result = Jm.printMd();
console.log(result);
 ```

### printJson( { throws=false } )
> 输出JSON文件
```js
const result = Jm.printJson();
console.log(result);
```

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