@lijuhong1981/jscheck 1.0.1 → 1.0.3
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/index.js +2 -2
- package/package.json +1 -1
- package/src/Check.js +11 -0
- package/src/defined.js +5 -0
- package/src/isDefined.js +0 -5
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Check from "./src/Check.js";
|
|
2
|
+
import defined from "./src/defined.js";
|
|
2
3
|
import isArray from "./src/isArray.js";
|
|
3
4
|
import isBoolean from "./src/isBoolean.js";
|
|
4
5
|
import isFunction from "./src/isFunction.js";
|
|
@@ -7,11 +8,11 @@ import isNumber from "./src/isNumber.js";
|
|
|
7
8
|
import isObject from "./src/isObject.js";
|
|
8
9
|
import isString from "./src/isString.js";
|
|
9
10
|
import isTypedArray from "./src/isTypedArray.js";
|
|
10
|
-
import isDefined from "./src/isDefined.js";
|
|
11
11
|
import isValid from "./src/isValid.js";
|
|
12
12
|
|
|
13
13
|
export default Check;
|
|
14
14
|
export {
|
|
15
|
+
defined,
|
|
15
16
|
isArray,
|
|
16
17
|
isBoolean,
|
|
17
18
|
isFunction,
|
|
@@ -20,6 +21,5 @@ export {
|
|
|
20
21
|
isObject,
|
|
21
22
|
isString,
|
|
22
23
|
isTypedArray,
|
|
23
|
-
isDefined,
|
|
24
24
|
isValid,
|
|
25
25
|
};
|
package/package.json
CHANGED
package/src/Check.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import defined from "./defined.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.defined = function (name, test) {
|
|
28
|
+
if (!defined(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));
|
package/src/defined.js
ADDED