@pisell/utils 1.0.1

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/.fatherrc.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'father';
2
+
3
+ export default defineConfig({
4
+ // more father config: https://github.com/umijs/father/blob/master/docs/config.md
5
+ esm: { output: 'es' },
6
+ cjs: { output: 'lib' },
7
+ });
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @pisell/utils
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 测试更新包
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @pisell/utils
2
+
3
+ pisell通用utils方法
package/es/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
package/es/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./otherUtils";
2
+ export * from "./typeUtils";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @Description: 生成唯一id
3
+ * @Author: wzw
4
+ * @Date: 2020-12-01 14:20:29
5
+ * @param {*}
6
+ * @return {*}
7
+ */
8
+ export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ //# sourceMappingURL=otherUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otherUtils.d.ts","sourceRoot":"","sources":["otherUtils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,iDAIvB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @Description: 生成唯一id
3
+ * @Author: wzw
4
+ * @Date: 2020-12-01 14:20:29
5
+ * @param {*}
6
+ * @return {*}
7
+ */
8
+ export var getUniqueId = function getUniqueId() {
9
+ var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
10
+ var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
11
+ return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
12
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 判断是否是函数
3
+ * @param obj
4
+ */
5
+ export declare const isFunction: (obj: any) => obj is Function;
6
+ /**
7
+ * 判断是否是数组
8
+ * @param obj
9
+ */
10
+ export declare const isArr: (obj: any) => obj is any[];
11
+ /**
12
+ * 判断是否是字符串
13
+ * @param obj
14
+ */
15
+ export declare const isString: (obj: any) => obj is string;
16
+ /**
17
+ * 判断是否是数字
18
+ * @param obj
19
+ */
20
+ export declare const isNumber: (obj: any) => obj is number;
21
+ /**
22
+ * 判断是否是undefined
23
+ * @param obj
24
+ */
25
+ export declare const isUndefined: (obj: any) => obj is undefined;
26
+ /**
27
+ * 判断是否是boolean
28
+ * @param obj
29
+ */
30
+ export declare const isBoolean: (obj: any) => obj is boolean;
31
+ /**
32
+ * 判断是否是json字符串
33
+ * @param v
34
+ */
35
+ export declare const isJson: (v: any) => boolean;
36
+ /**
37
+ * @Title: 判断是否为对象
38
+ * @Describe:
39
+ * @Author: Wzw
40
+ * @param {any} obj
41
+ */
42
+ export declare const isPlainObject: (obj: any) => boolean;
43
+ //# sourceMappingURL=typeUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,GAAG,oBACR,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAS,GAAG,iBAA0C,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,qBACR,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,GAAG,mBAA6C,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,MAAM,MAAO,GAAG,KAAG,OAU/B,CAAC;AAOF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAS,GAAG,YAarC,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * 判断是否是函数
3
+ * @param obj
4
+ */
5
+ export var isFunction = function isFunction(obj) {
6
+ return typeof obj === 'function';
7
+ };
8
+
9
+ /**
10
+ * 判断是否是数组
11
+ * @param obj
12
+ */
13
+ export var isArr = function isArr(obj) {
14
+ return Array.isArray(obj);
15
+ };
16
+
17
+ /**
18
+ * 判断是否是字符串
19
+ * @param obj
20
+ */
21
+ export var isString = function isString(obj) {
22
+ return typeof obj === 'string';
23
+ };
24
+
25
+ /**
26
+ * 判断是否是数字
27
+ * @param obj
28
+ */
29
+ export var isNumber = function isNumber(obj) {
30
+ return typeof obj === 'number';
31
+ };
32
+
33
+ /**
34
+ * 判断是否是undefined
35
+ * @param obj
36
+ */
37
+ export var isUndefined = function isUndefined(obj) {
38
+ return typeof obj === 'undefined';
39
+ };
40
+
41
+ /**
42
+ * 判断是否是boolean
43
+ * @param obj
44
+ */
45
+ export var isBoolean = function isBoolean(obj) {
46
+ return typeof obj === 'boolean';
47
+ };
48
+
49
+ /**
50
+ * 判断是否是json字符串
51
+ * @param v
52
+ */
53
+ export var isJson = function isJson(v) {
54
+ if (typeof v === 'string') {
55
+ try {
56
+ return JSON.parse(v);
57
+ } catch (e) {
58
+ return false;
59
+ }
60
+ } else {
61
+ return false;
62
+ }
63
+ };
64
+ var getProto = Object.getPrototypeOf;
65
+ var hasOwn = {}.hasOwnProperty;
66
+ var fnToString = hasOwn.toString;
67
+ var ObjectFunctionString = fnToString.call(Object);
68
+
69
+ /**
70
+ * @Title: 判断是否为对象
71
+ * @Describe:
72
+ * @Author: Wzw
73
+ * @param {any} obj
74
+ */
75
+ export var isPlainObject = function isPlainObject(obj) {
76
+ var proto, Ctor;
77
+ if (!obj || toString.call(obj) !== '[object Object]') {
78
+ return false;
79
+ }
80
+ proto = getProto(obj);
81
+ if (!proto) {
82
+ return true;
83
+ }
84
+ Ctor = hasOwn.call(proto, 'constructor') && proto.constructor;
85
+ return typeof Ctor === 'function' && fnToString.call(Ctor) === ObjectFunctionString;
86
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/index.ts
17
+ var src_exports = {};
18
+ module.exports = __toCommonJS(src_exports);
19
+ __reExport(src_exports, require("./otherUtils"), module.exports);
20
+ __reExport(src_exports, require("./typeUtils"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("./otherUtils"),
24
+ ...require("./typeUtils")
25
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @Description: 生成唯一id
3
+ * @Author: wzw
4
+ * @Date: 2020-12-01 14:20:29
5
+ * @param {*}
6
+ * @return {*}
7
+ */
8
+ export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
+ //# sourceMappingURL=otherUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otherUtils.d.ts","sourceRoot":"","sources":["otherUtils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,iDAIvB,CAAC"}
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/otherUtils.ts
20
+ var otherUtils_exports = {};
21
+ __export(otherUtils_exports, {
22
+ getUniqueId: () => getUniqueId
23
+ });
24
+ module.exports = __toCommonJS(otherUtils_exports);
25
+ var getUniqueId = (prefix = "", maxLength = 11) => {
26
+ return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ getUniqueId
31
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 判断是否是函数
3
+ * @param obj
4
+ */
5
+ export declare const isFunction: (obj: any) => obj is Function;
6
+ /**
7
+ * 判断是否是数组
8
+ * @param obj
9
+ */
10
+ export declare const isArr: (obj: any) => obj is any[];
11
+ /**
12
+ * 判断是否是字符串
13
+ * @param obj
14
+ */
15
+ export declare const isString: (obj: any) => obj is string;
16
+ /**
17
+ * 判断是否是数字
18
+ * @param obj
19
+ */
20
+ export declare const isNumber: (obj: any) => obj is number;
21
+ /**
22
+ * 判断是否是undefined
23
+ * @param obj
24
+ */
25
+ export declare const isUndefined: (obj: any) => obj is undefined;
26
+ /**
27
+ * 判断是否是boolean
28
+ * @param obj
29
+ */
30
+ export declare const isBoolean: (obj: any) => obj is boolean;
31
+ /**
32
+ * 判断是否是json字符串
33
+ * @param v
34
+ */
35
+ export declare const isJson: (v: any) => boolean;
36
+ /**
37
+ * @Title: 判断是否为对象
38
+ * @Describe:
39
+ * @Author: Wzw
40
+ * @param {any} obj
41
+ */
42
+ export declare const isPlainObject: (obj: any) => boolean;
43
+ //# sourceMappingURL=typeUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,GAAG,oBACR,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAS,GAAG,iBAA0C,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,qBACR,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,GAAG,mBAA6C,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,MAAM,MAAO,GAAG,KAAG,OAU/B,CAAC;AAOF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAS,GAAG,YAarC,CAAC"}
@@ -0,0 +1,75 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/typeUtils.ts
20
+ var typeUtils_exports = {};
21
+ __export(typeUtils_exports, {
22
+ isArr: () => isArr,
23
+ isBoolean: () => isBoolean,
24
+ isFunction: () => isFunction,
25
+ isJson: () => isJson,
26
+ isNumber: () => isNumber,
27
+ isPlainObject: () => isPlainObject,
28
+ isString: () => isString,
29
+ isUndefined: () => isUndefined
30
+ });
31
+ module.exports = __toCommonJS(typeUtils_exports);
32
+ var isFunction = (obj) => typeof obj === "function";
33
+ var isArr = (obj) => Array.isArray(obj);
34
+ var isString = (obj) => typeof obj === "string";
35
+ var isNumber = (obj) => typeof obj === "number";
36
+ var isUndefined = (obj) => typeof obj === "undefined";
37
+ var isBoolean = (obj) => typeof obj === "boolean";
38
+ var isJson = (v) => {
39
+ if (typeof v === "string") {
40
+ try {
41
+ return JSON.parse(v);
42
+ } catch (e) {
43
+ return false;
44
+ }
45
+ } else {
46
+ return false;
47
+ }
48
+ };
49
+ var getProto = Object.getPrototypeOf;
50
+ var hasOwn = {}.hasOwnProperty;
51
+ var fnToString = hasOwn.toString;
52
+ var ObjectFunctionString = fnToString.call(Object);
53
+ var isPlainObject = (obj) => {
54
+ var proto, Ctor;
55
+ if (!obj || toString.call(obj) !== "[object Object]") {
56
+ return false;
57
+ }
58
+ proto = getProto(obj);
59
+ if (!proto) {
60
+ return true;
61
+ }
62
+ Ctor = hasOwn.call(proto, "constructor") && proto.constructor;
63
+ return typeof Ctor === "function" && fnToString.call(Ctor) === ObjectFunctionString;
64
+ };
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ isArr,
68
+ isBoolean,
69
+ isFunction,
70
+ isJson,
71
+ isNumber,
72
+ isPlainObject,
73
+ isString,
74
+ isUndefined
75
+ });
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@pisell/utils",
3
+ "version": "1.0.1",
4
+ "devDependencies": {
5
+ "father": "^4.1.0"
6
+ },
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "scripts": {
11
+ "build": "father build",
12
+ "dev": "father dev"
13
+ }
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
@@ -0,0 +1,13 @@
1
+
2
+ /**
3
+ * @Description: 生成唯一id
4
+ * @Author: wzw
5
+ * @Date: 2020-12-01 14:20:29
6
+ * @param {*}
7
+ * @return {*}
8
+ */
9
+ export const getUniqueId = (prefix = '', maxLength = 11) => {
10
+ return (
11
+ prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength)
12
+ );
13
+ };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * 判断是否是函数
3
+ * @param obj
4
+ */
5
+ export const isFunction = (obj: any): obj is Function =>
6
+ typeof obj === 'function';
7
+
8
+ /**
9
+ * 判断是否是数组
10
+ * @param obj
11
+ */
12
+ export const isArr = (obj: any): obj is Array<any> => Array.isArray(obj);
13
+
14
+ /**
15
+ * 判断是否是字符串
16
+ * @param obj
17
+ */
18
+ export const isString = (obj: any): obj is string => typeof obj === 'string';
19
+
20
+ /**
21
+ * 判断是否是数字
22
+ * @param obj
23
+ */
24
+ export const isNumber = (obj: any): obj is number => typeof obj === 'number';
25
+
26
+ /**
27
+ * 判断是否是undefined
28
+ * @param obj
29
+ */
30
+ export const isUndefined = (obj: any): obj is undefined =>
31
+ typeof obj === 'undefined';
32
+
33
+ /**
34
+ * 判断是否是boolean
35
+ * @param obj
36
+ */
37
+ export const isBoolean = (obj: any): obj is boolean => typeof obj === 'boolean';
38
+
39
+ /**
40
+ * 判断是否是json字符串
41
+ * @param v
42
+ */
43
+ export const isJson = (v: any): boolean => {
44
+ if (typeof v === 'string') {
45
+ try {
46
+ return JSON.parse(v);
47
+ } catch (e) {
48
+ return false;
49
+ }
50
+ } else {
51
+ return false;
52
+ }
53
+ };
54
+
55
+ const getProto = Object.getPrototypeOf;
56
+ const hasOwn = {}.hasOwnProperty;
57
+ const fnToString = hasOwn.toString;
58
+ const ObjectFunctionString = fnToString.call(Object);
59
+
60
+ /**
61
+ * @Title: 判断是否为对象
62
+ * @Describe:
63
+ * @Author: Wzw
64
+ * @param {any} obj
65
+ */
66
+ export const isPlainObject = (obj: any) => {
67
+ var proto, Ctor;
68
+ if (!obj || toString.call(obj) !== '[object Object]') {
69
+ return false;
70
+ }
71
+ proto = getProto(obj);
72
+ if (!proto) {
73
+ return true;
74
+ }
75
+ Ctor = hasOwn.call(proto, 'constructor') && proto.constructor;
76
+ return (
77
+ typeof Ctor === 'function' && fnToString.call(Ctor) === ObjectFunctionString
78
+ );
79
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "declaration": true,
5
+ "skipLibCheck": true,
6
+ "esModuleInterop": true,
7
+ "jsx": "react",
8
+ "baseUrl": "./",
9
+ "paths": {
10
+ "@": ["src/*"]
11
+ }
12
+ },
13
+ "include": ["src"]
14
+ }