@lijuhong1981/jscheck 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Check.js +11 -0
package/package.json
CHANGED
package/src/Check.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import isDefined from "./isDefined.js";
|
|
1
2
|
import isValid from "./isValid.js";
|
|
2
3
|
|
|
3
4
|
const Check = {};
|
|
4
5
|
|
|
5
6
|
Check.typeOf = {};
|
|
6
7
|
|
|
8
|
+
function getUndefinedErrorMessage(name) {
|
|
9
|
+
return name + " is required, actual value was undefined.";
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
function getInvalidErrorMessage(name) {
|
|
8
13
|
return name + " is required, actual value was invalid.";
|
|
9
14
|
}
|
|
@@ -19,6 +24,12 @@ function getFailedTypeErrorMessage(actual, expected, name) {
|
|
|
19
24
|
);
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
Check.isDefined = function (name, test) {
|
|
28
|
+
if (!isDefined(test)) {
|
|
29
|
+
throw new Error(getUndefinedErrorMessage(name));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
22
33
|
Check.isValid = function (name, test) {
|
|
23
34
|
if (!isValid(test)) {
|
|
24
35
|
throw new Error(getInvalidErrorMessage(name));
|