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:字符串,数组,对象 |
许可证
麻省理工学院