0model 中文文档教程

发布于 8年前 浏览 17 项目主页 更新于 3年前

Codacy

npm -g install 0model

  • Coverage: +
  • Browser: +

Browser

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

全局变量: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

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

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文