0model

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

Lightweight module for data control

原始使用文档

Codacy

npm -g install 0model

  • Coverage: +
  • Browser: +

Browser

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

Global var: zm

Examples

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)) + "!";

Instance

AttributeTypeNote
-
to, then, is, itobjectthis
-
setfunction(v)return: this
getfunction([callback])return: current value
-
lastError-
value-current value
[T]
bool, booleanfunction(true, on, yes, 1) = true
str, stringfunction(NaN, null, undefined, []) = ""
int, integerfunction(radix)
float, numberfunction
-
datefunction
symbolfunction
-
table, hashTablefunction(notParse)
arrayfunction(notParse)
jsonfunction
[M]
removefunction(t)t: string, regEx (string), function(elem)
absfunction
clampfunction(min, max)
[V]
requiredfunctionfalse: NaN, [], null, undefined, "", Invalid Date, {}
emptyfunctiontrue: NaN, [], null, undefined, "", Invalid Date, {}
has, havefunction(...)for: string, array, object

License

MIT


@ 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 和提交记录判断。