@cclr/lang 0.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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `lang`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const lang = require('lang');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
package/cjs/index.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const VAL_TYPE = {
4
+ boolean: "boolean",
5
+ undefined: "undefined",
6
+ number: "undefined",
7
+ string: "string",
8
+ null: "null",
9
+ "[object Object]": "object",
10
+ "[object Function]": "function",
11
+ "[object RegExp]": "regexp",
12
+ "[object Array]": "array",
13
+ "[object Date]": "date",
14
+ "[object Error]": "error",
15
+ "[object Blob]": "blob",
16
+ "[object File]": "file",
17
+ "[object ArrayBuffer]": "arrayBuffer",
18
+ };
19
+
20
+ /**
21
+ * 获取参数类型
22
+ * @param p 参数
23
+ * @returns
24
+ */
25
+ function getParamType(p) {
26
+ return (VAL_TYPE[typeof p] ||
27
+ VAL_TYPE[Object.prototype.toString.call(p)] ||
28
+ (p ? "object" : "null"));
29
+ }
30
+ function isType(params, type) {
31
+ return getParamType(params) === type;
32
+ }
33
+ function isString(s) {
34
+ return getParamType(s) === "string";
35
+ }
36
+ function isBoolean(b) {
37
+ return getParamType(b) === "boolean";
38
+ }
39
+ function isFunction(b) {
40
+ return getParamType(b) === "function";
41
+ }
42
+ function isPlainObject(b) {
43
+ return getParamType(b) === "object";
44
+ }
45
+ function isArray(a) {
46
+ return Array.isArray(a);
47
+ }
48
+
49
+ exports.VAL_TYPE = VAL_TYPE;
50
+ exports.getParamType = getParamType;
51
+ exports.isArray = isArray;
52
+ exports.isBoolean = isBoolean;
53
+ exports.isFunction = isFunction;
54
+ exports.isPlainObject = isPlainObject;
55
+ exports.isString = isString;
56
+ exports.isType = isType;
@@ -0,0 +1,2 @@
1
+ export type TAny = any;
2
+ export type TPlainObject = Record<string, TAny>;
@@ -0,0 +1,3 @@
1
+ export * from './type-asserts';
2
+ export * from './common-type';
3
+ export * from './value-type';
@@ -0,0 +1,14 @@
1
+ import { TVal } from "./value-type";
2
+ /**
3
+ * 获取参数类型
4
+ * @param p 参数
5
+ * @returns
6
+ */
7
+ declare function getParamType(p: unknown): TVal;
8
+ declare function isType(params: any, type: TVal): boolean;
9
+ declare function isString(s: any): s is String;
10
+ declare function isBoolean(b: any): b is Boolean;
11
+ declare function isFunction(b: any): b is Function;
12
+ declare function isPlainObject(b: any): b is Record<string, unknown>;
13
+ declare function isArray(a: any): a is any[];
14
+ export { getParamType, isType, isString, isBoolean, isFunction, isArray, isPlainObject, };
@@ -0,0 +1,17 @@
1
+ export declare const VAL_TYPE: {
2
+ readonly boolean: "boolean";
3
+ readonly undefined: "undefined";
4
+ readonly number: "undefined";
5
+ readonly string: "string";
6
+ readonly null: "null";
7
+ readonly "[object Object]": "object";
8
+ readonly "[object Function]": "function";
9
+ readonly "[object RegExp]": "regexp";
10
+ readonly "[object Array]": "array";
11
+ readonly "[object Date]": "date";
12
+ readonly "[object Error]": "error";
13
+ readonly "[object Blob]": "blob";
14
+ readonly "[object File]": "file";
15
+ readonly "[object ArrayBuffer]": "arrayBuffer";
16
+ };
17
+ export type TVal = typeof VAL_TYPE[keyof typeof VAL_TYPE];
package/esm/index.js ADDED
@@ -0,0 +1,47 @@
1
+ const VAL_TYPE = {
2
+ boolean: "boolean",
3
+ undefined: "undefined",
4
+ number: "undefined",
5
+ string: "string",
6
+ null: "null",
7
+ "[object Object]": "object",
8
+ "[object Function]": "function",
9
+ "[object RegExp]": "regexp",
10
+ "[object Array]": "array",
11
+ "[object Date]": "date",
12
+ "[object Error]": "error",
13
+ "[object Blob]": "blob",
14
+ "[object File]": "file",
15
+ "[object ArrayBuffer]": "arrayBuffer",
16
+ };
17
+
18
+ /**
19
+ * 获取参数类型
20
+ * @param p 参数
21
+ * @returns
22
+ */
23
+ function getParamType(p) {
24
+ return (VAL_TYPE[typeof p] ||
25
+ VAL_TYPE[Object.prototype.toString.call(p)] ||
26
+ (p ? "object" : "null"));
27
+ }
28
+ function isType(params, type) {
29
+ return getParamType(params) === type;
30
+ }
31
+ function isString(s) {
32
+ return getParamType(s) === "string";
33
+ }
34
+ function isBoolean(b) {
35
+ return getParamType(b) === "boolean";
36
+ }
37
+ function isFunction(b) {
38
+ return getParamType(b) === "function";
39
+ }
40
+ function isPlainObject(b) {
41
+ return getParamType(b) === "object";
42
+ }
43
+ function isArray(a) {
44
+ return Array.isArray(a);
45
+ }
46
+
47
+ export { VAL_TYPE, getParamType, isArray, isBoolean, isFunction, isPlainObject, isString, isType };
@@ -0,0 +1,2 @@
1
+ export type TAny = any;
2
+ export type TPlainObject = Record<string, TAny>;
@@ -0,0 +1,3 @@
1
+ export * from './type-asserts';
2
+ export * from './common-type';
3
+ export * from './value-type';
@@ -0,0 +1,14 @@
1
+ import { TVal } from "./value-type";
2
+ /**
3
+ * 获取参数类型
4
+ * @param p 参数
5
+ * @returns
6
+ */
7
+ declare function getParamType(p: unknown): TVal;
8
+ declare function isType(params: any, type: TVal): boolean;
9
+ declare function isString(s: any): s is String;
10
+ declare function isBoolean(b: any): b is Boolean;
11
+ declare function isFunction(b: any): b is Function;
12
+ declare function isPlainObject(b: any): b is Record<string, unknown>;
13
+ declare function isArray(a: any): a is any[];
14
+ export { getParamType, isType, isString, isBoolean, isFunction, isArray, isPlainObject, };
@@ -0,0 +1,17 @@
1
+ export declare const VAL_TYPE: {
2
+ readonly boolean: "boolean";
3
+ readonly undefined: "undefined";
4
+ readonly number: "undefined";
5
+ readonly string: "string";
6
+ readonly null: "null";
7
+ readonly "[object Object]": "object";
8
+ readonly "[object Function]": "function";
9
+ readonly "[object RegExp]": "regexp";
10
+ readonly "[object Array]": "array";
11
+ readonly "[object Date]": "date";
12
+ readonly "[object Error]": "error";
13
+ readonly "[object Blob]": "blob";
14
+ readonly "[object File]": "file";
15
+ readonly "[object ArrayBuffer]": "arrayBuffer";
16
+ };
17
+ export type TVal = typeof VAL_TYPE[keyof typeof VAL_TYPE];
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './esm/src';
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@cclr/lang",
3
+ "version": "0.0.3",
4
+ "description": "> TODO: description",
5
+ "author": "cclr <18843152354@163.com>",
6
+ "homepage": "",
7
+ "license": "ISC",
8
+ "main": "cjs/lang.js",
9
+ "module": "esm/index.js",
10
+ "types": "./index.d.ts",
11
+ "directories": {
12
+ "lib": "lib",
13
+ "test": "__tests__"
14
+ },
15
+ "files": [
16
+ "cjs",
17
+ "esm",
18
+ "index.d.ts",
19
+ "README.md"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
25
+ "scripts": {
26
+ "test": "node ./__tests__/lang.test.js"
27
+ },
28
+ "gitHead": "3b2ad8f10a1334a9876d31e0bf4a16074da88269"
29
+ }