# json-schema-format

> customised format based on tv4

Latest version **0.0.4** (published 2014-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-format
pnpm add json-schema-format
yarn add json-schema-format
bun add json-schema-format
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2014-08-12 |
| First published | 2014-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yinruo.nyj@taobao.com |
| Maintainers | abc-team |
| Keywords | json-schema, json, format |

## Links

- npm: https://www.npmjs.com/package/json-schema-format
- Repository: git@gitlab.alibaba-inc.com:jsonnanny/json-schema-format
- npm.io page: https://npm.io/package/json-schema-format

## Dependencies (1)

- [tv4](https://npm.io/package/tv4.md) ^1.0.18

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.4 (latest) — 2014-08-12
- 0.0.3 — 2014-05-22
- 0.0.2 — 2014-05-22
- 0.0.1 — 2014-05-22

## README

## json-schema-format

针对阿里的业务特点，对常用的format进行验证的实现。

参考river的[format列表](http://gitlab.alibaba-inc.com/river/spec/blob/master/JSON-Schema.md#format )，部分实现。

依赖[tv4](https://github.com/geraintluff/tv4)，将通过tv4的[addFormat](https://github.com/geraintluff/tv4#addformatformat-validationfunction)方法将这些format添加进去

## 目前实现的format

- date-time
- email
- hostname
- ipv4
- ipv6
- uri
- TIMESTAMP
- URL
- TMALL_DETAIL
- TAOBAO_DETAIL
- TMALL_SHOP
- TAOBAO_SHOP
- CDN_PIC

## 安装

[TBower](http://bower.fed.taobao.net/#/home)

```
tbower install json-schema-format --save
```

npm

```
npm install json-schema-format --save
```

## 使用

* 若在浏览器中使用，不使用CMD/AMD，直接使用`window.JsonSchemaFormat`。

#### 单独使用Format

```
var Format = require( 'json-schema-format' );

// --> true
console.log( Format( 'TMALL_DETAIL', 'http://detail.tmall.com/item.htm?spm=p531232234.1.w5003-6316546454.14.ZkNgbh&id=36628862613&mt=&scene=taobao_shop' ) )

```

#### 结合tv4使用

```
var TV4 = require( 'tv4' );
var Format = require( 'json-schema-format' );

var schema = {
    type: 'object',
    properties: {
        pic: {
            type: 'string',
            format: 'CDN_PIC'
        }
    }
};

var retForCDNPic = TV4.validate( {
    pic: 'http://pan.taobao.com'
}, schema );

if( !retForCDNPic ){
    // --> Format validation failed (不匹配格式 CDN_PIC 的要求)
    console.log( TV4.error );
}
```

#### 获取支持的格式列表

```
var Format = require( 'json-schema-format' );

// --> [ 'uri', 'ipv4'.... ]
console.log( Format.getAllFormats() );

```

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