验证 Javascript 中的数据的简单方式 Superstruct
- 授权协议: MIT
- 开发语言: JavaScript
- 操作系统: 跨平台
- 软件首页: https://github.com/ianstormtaylor/superstruct
- 软件文档: https://github.com/ianstormtaylor/superstruct
- 官方下载: https://github.com/ianstormtaylor/superstruct
软件介绍
Superstruct 是一个简单和可组合的方式来验证 Javascript 中的数据。它的类型注释 API 受 Typescript、Flow、Go 和 GraphQL 的启发,令用户有熟悉感且易于理解。
不过,Superstruct 是为在运行时验证数据而设计的,所以它会为最终用户抛出(或返回)详细的运行时错误。 这在类似于接受 REST 或 GraphQL API 中的任意输入的情况下特别有用。它甚至可以用来在运行时验证内部数据结构。
Usage
Superstruct 导出一个struct 工厂模式,以根据特定模式验证数据的结构:
import { struct } from 'superstruct'
const Article = struct({
id: 'number',
title: 'string',
is_published: 'boolean?',
tags: ['string'],
author: {
id: 'number',
}
})
const data = {
id: 34,
title: 'Hello World',
tags: ['news', 'features'],
author: {
id: 1,
}
}
const article = Article(data)
// This will throw when the data is invalid, and return the data otherwise.
// If you'd rather not throw, use `Struct.validate()` or `Struct.test()`.它可以识别所有原生的 JavaScript 类型。 你也可以使用 superstruct export 来定义自己的自定义数据类型(根据应用需求)
import { superstruct } from 'superstruct'
import isUuid from 'is-uuid'
import isEmail from 'is-email'
const struct = superstruct({
types: {
uuid: value => isUuid.v4(value),
email: value => isEmail(value) && value.length < 256,
}
})
const User = struct({
id: 'uuid',
email: 'email',
is_admin: 'boolean?',
})
const data = {
id: 'c8d63140-a1f7-45e0-bfc6-df72973fea86',
email: 'jane@example.com',
}
const user = User(data)
叠加体验:用互联网思维设计商业模式
穆胜 / 机械工业出版社 / 2014-11 / 39.00
本书在互联网思维改变一切的背景下,详细介绍了如何运用互联网思维重构商业模式,主要包括以下内容:①互联网经济中的商业逻辑(即“互联网思维”),不仅给出了消费方面的逻辑变革,还给出了在生产端的逻辑变革以及“跨界”的逻辑变革。②给出了一个“三层产品体验模型”,厘清了互联网思维,打造完美终端、云端服务和价值群落三层体验,企业可以选择做不同层面的体验组合,这即是选择了不同的市场策略。但是,企业要基业长青,终......一起来看看 《叠加体验:用互联网思维设计商业模式》 这本书的介绍吧!
