0model

中文文档
0.4.2发布于 2016/10/20MITCommonJS零依赖

轻量级的数据控制模块

中文使用文档

Codacy

npm -g install 0model

  • 覆盖范围:+
  • 浏览器:+

浏览器

  • 包括: //raw.githack.com/Daeren/0model/master/index.js

全局变量: zm

示例

var zm = require("0model");


zm(" D ").string().get().trim();            // <-- "D"
zm(" 13.").to.int().it.is.required();       // <-- true

zm({x: 1, y: 2}).to.have("x", "z");         // <-- false
zm({}).it.is.empty();                       // <-- true


zm("[1,2]").to.json().get();                // <-- [1, 2]
zm("[1,").to.json().to.string().get();      // <-- ''
zm("[1,").json().string().get();            // <-- ''

zm(5.9).int().str() + 10;                   // <-- '510'
zm(5.9).to.integer() + " num";              // <-- '5 num'
zm(zm('d0' / 1)).empty();                   // <-- true


zm([1, 2, 3]).set(x => x.reduce((a, b) => a + b)).get(console.log);
zm(3.14159).set(x => x.toFixed(0)).str().get(console.log);


zm("hello 2 world").to.string().then.remove(/\d+/).it.is.required();
zm("hello 2 world").to.string().then.remove(/\d+/).get();
zm("hello 2 world").to.string().then.remove(d => d.substr(2)) + "!";

实例

属性类型注意
-
那么,它就是它对象这
-
集函数(v)返回:
得到函数(回调)返回:当前值
-
lastError-
价值-当前值
[T]
bool,布尔函数(true, on, yes, 1) = true
str,字符串函数(NaN, null, undefined, []) = “”
整数,整数函数(基数)
浮动,数量函数
-
日期函数
象征函数
-
表,散列表函数(notParse)
数组函数(notParse)
json函数
[M]
删除函数(t)t:字符串,regEx(字符串),函数(元素)
腹肌函数
夹函数(最小,最大)
[V]
要求函数false: NaN, [], null, undefined, "",无效日期,{}
空函数true: NaN, [], null, undefined, "",无效日期,{}
有,有函数(…)For:字符串,数组,对象

许可证

麻省理工学院


@ Daeren

版本与发布记录

0model 共发布 18 个版本,首次发布于 2015/03/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.2latest2016/10/2010 年前
0.4.12016/10/2010 年前
0.3.12016/10/2010 年前
0.3.02016/10/1910 年前
0.2.02016/10/1910 年前
0.1.02016/10/1910 年前

关于 0model 的常见问题

0model 是什么?

轻量级的数据控制模块

如何安装 0model?

在项目目录运行 npm install 0model,或使用 pnpm add / yarn add / bun add。

0model 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/0model 是否存在。

0model 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

0model 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.8.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

0model 可以商用吗?

0model 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

0model 还在维护吗?

最新版本 0.4.2 发布于 2016/10/20(10 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/03/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。