@varlet/shared 2.0.0-alpha.1663499244572 → 2.0.0-alpha.1663742071515

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/LICENCE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 varlet
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 varlet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/es/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- export declare const isString: (val: unknown) => val is string;
2
- export declare const isBoolean: (val: unknown) => val is boolean;
3
- export declare const isNumber: (val: unknown) => val is number;
4
- export declare const isPlainObject: (val: unknown) => val is Record<string, any>;
5
- export declare const isObject: (val: unknown) => val is Record<string, any>;
6
- export declare const isArray: (val: unknown) => val is any[];
7
- export declare const isURL: (val: string | undefined | null) => boolean;
8
- export declare const isEmpty: (val: unknown) => boolean;
9
- export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
10
- export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
11
- export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
12
- export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
13
- export declare const inBrowser: () => boolean;
14
- export declare const uniq: (arr: Array<any>) => any[];
15
- export declare const bigCamelize: (s: string) => string;
16
- export declare const camelize: (s: string) => string;
17
- export declare const kebabCase: (s: string) => string;
1
+ export declare const isString: (val: unknown) => val is string;
2
+ export declare const isBoolean: (val: unknown) => val is boolean;
3
+ export declare const isNumber: (val: unknown) => val is number;
4
+ export declare const isPlainObject: (val: unknown) => val is Record<string, any>;
5
+ export declare const isObject: (val: unknown) => val is Record<string, any>;
6
+ export declare const isArray: (val: unknown) => val is any[];
7
+ export declare const isURL: (val: string | undefined | null) => boolean;
8
+ export declare const isEmpty: (val: unknown) => boolean;
9
+ export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
10
+ export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
11
+ export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
12
+ export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
13
+ export declare const inBrowser: () => boolean;
14
+ export declare const uniq: (arr: Array<any>) => any[];
15
+ export declare const bigCamelize: (s: string) => string;
16
+ export declare const camelize: (s: string) => string;
17
+ export declare const kebabCase: (s: string) => string;
package/es/index.js CHANGED
@@ -1,67 +1,67 @@
1
- export const isString = (val) => typeof val === 'string';
2
- export const isBoolean = (val) => typeof val === 'boolean';
3
- export const isNumber = (val) => typeof val === 'number';
4
- export const isPlainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
5
- export const isObject = (val) => typeof val === 'object' && val !== null;
6
- export const isArray = (val) => Array.isArray(val);
7
- export const isURL = (val) => {
8
- if (!val) {
9
- return false;
10
- }
11
- return /^(http)|(\.*\/)/.test(val);
12
- };
13
- export const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
14
- export const toNumber = (val) => {
15
- if (val == null)
16
- return 0;
17
- if (isString(val)) {
18
- val = parseFloat(val);
19
- val = Number.isNaN(val) ? 0 : val;
20
- return val;
21
- }
22
- if (isBoolean(val))
23
- return Number(val);
24
- return val;
25
- };
26
- export const removeItem = (arr, item) => {
27
- if (arr.length) {
28
- const index = arr.indexOf(item);
29
- if (index > -1) {
30
- return arr.splice(index, 1);
31
- }
32
- }
33
- };
34
- export const toggleItem = (arr, item) => {
35
- arr.includes(item) ? removeItem(arr, item) : arr.push(item);
36
- };
37
- export const throttle = (method, mustRunDelay = 200) => {
38
- let timer;
39
- let start = 0;
40
- return function loop(...args) {
41
- const now = Date.now();
42
- const elapsed = now - start;
43
- if (!start) {
44
- start = now;
45
- }
46
- if (timer) {
47
- window.clearTimeout(timer);
48
- }
49
- if (elapsed >= mustRunDelay) {
50
- method.apply(this, args);
51
- start = now;
52
- }
53
- else {
54
- timer = window.setTimeout(() => {
55
- loop.apply(this, args);
56
- }, mustRunDelay - elapsed);
57
- }
58
- };
59
- };
60
- export const inBrowser = () => typeof window !== 'undefined';
61
- export const uniq = (arr) => [...new Set(arr)];
62
- export const bigCamelize = (s) => camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
63
- export const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
64
- export const kebabCase = (s) => {
65
- const ret = s.replace(/([A-Z])/g, ' $1').trim();
66
- return ret.split(' ').join('-').toLowerCase();
67
- };
1
+ export const isString = (val) => typeof val === 'string';
2
+ export const isBoolean = (val) => typeof val === 'boolean';
3
+ export const isNumber = (val) => typeof val === 'number';
4
+ export const isPlainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
5
+ export const isObject = (val) => typeof val === 'object' && val !== null;
6
+ export const isArray = (val) => Array.isArray(val);
7
+ export const isURL = (val) => {
8
+ if (!val) {
9
+ return false;
10
+ }
11
+ return /^(http)|(\.*\/)/.test(val);
12
+ };
13
+ export const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
14
+ export const toNumber = (val) => {
15
+ if (val == null)
16
+ return 0;
17
+ if (isString(val)) {
18
+ val = parseFloat(val);
19
+ val = Number.isNaN(val) ? 0 : val;
20
+ return val;
21
+ }
22
+ if (isBoolean(val))
23
+ return Number(val);
24
+ return val;
25
+ };
26
+ export const removeItem = (arr, item) => {
27
+ if (arr.length) {
28
+ const index = arr.indexOf(item);
29
+ if (index > -1) {
30
+ return arr.splice(index, 1);
31
+ }
32
+ }
33
+ };
34
+ export const toggleItem = (arr, item) => {
35
+ arr.includes(item) ? removeItem(arr, item) : arr.push(item);
36
+ };
37
+ export const throttle = (method, mustRunDelay = 200) => {
38
+ let timer;
39
+ let start = 0;
40
+ return function loop(...args) {
41
+ const now = Date.now();
42
+ const elapsed = now - start;
43
+ if (!start) {
44
+ start = now;
45
+ }
46
+ if (timer) {
47
+ window.clearTimeout(timer);
48
+ }
49
+ if (elapsed >= mustRunDelay) {
50
+ method.apply(this, args);
51
+ start = now;
52
+ }
53
+ else {
54
+ timer = window.setTimeout(() => {
55
+ loop.apply(this, args);
56
+ }, mustRunDelay - elapsed);
57
+ }
58
+ };
59
+ };
60
+ export const inBrowser = () => typeof window !== 'undefined';
61
+ export const uniq = (arr) => [...new Set(arr)];
62
+ export const bigCamelize = (s) => camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
63
+ export const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
64
+ export const kebabCase = (s) => {
65
+ const ret = s.replace(/([A-Z])/g, ' $1').trim();
66
+ return ret.split(' ').join('-').toLowerCase();
67
+ };
package/lib/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- export declare const isString: (val: unknown) => val is string;
2
- export declare const isBoolean: (val: unknown) => val is boolean;
3
- export declare const isNumber: (val: unknown) => val is number;
4
- export declare const isPlainObject: (val: unknown) => val is Record<string, any>;
5
- export declare const isObject: (val: unknown) => val is Record<string, any>;
6
- export declare const isArray: (val: unknown) => val is any[];
7
- export declare const isURL: (val: string | undefined | null) => boolean;
8
- export declare const isEmpty: (val: unknown) => boolean;
9
- export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
10
- export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
11
- export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
12
- export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
13
- export declare const inBrowser: () => boolean;
14
- export declare const uniq: (arr: Array<any>) => any[];
15
- export declare const bigCamelize: (s: string) => string;
16
- export declare const camelize: (s: string) => string;
17
- export declare const kebabCase: (s: string) => string;
1
+ export declare const isString: (val: unknown) => val is string;
2
+ export declare const isBoolean: (val: unknown) => val is boolean;
3
+ export declare const isNumber: (val: unknown) => val is number;
4
+ export declare const isPlainObject: (val: unknown) => val is Record<string, any>;
5
+ export declare const isObject: (val: unknown) => val is Record<string, any>;
6
+ export declare const isArray: (val: unknown) => val is any[];
7
+ export declare const isURL: (val: string | undefined | null) => boolean;
8
+ export declare const isEmpty: (val: unknown) => boolean;
9
+ export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
10
+ export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
11
+ export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
12
+ export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
13
+ export declare const inBrowser: () => boolean;
14
+ export declare const uniq: (arr: Array<any>) => any[];
15
+ export declare const bigCamelize: (s: string) => string;
16
+ export declare const camelize: (s: string) => string;
17
+ export declare const kebabCase: (s: string) => string;
package/lib/index.js CHANGED
@@ -1,87 +1,87 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.kebabCase = exports.camelize = exports.bigCamelize = exports.uniq = exports.inBrowser = exports.throttle = exports.toggleItem = exports.removeItem = exports.toNumber = exports.isEmpty = exports.isURL = exports.isArray = exports.isObject = exports.isPlainObject = exports.isNumber = exports.isBoolean = exports.isString = void 0;
4
- const isString = (val) => typeof val === 'string';
5
- exports.isString = isString;
6
- const isBoolean = (val) => typeof val === 'boolean';
7
- exports.isBoolean = isBoolean;
8
- const isNumber = (val) => typeof val === 'number';
9
- exports.isNumber = isNumber;
10
- const isPlainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
11
- exports.isPlainObject = isPlainObject;
12
- const isObject = (val) => typeof val === 'object' && val !== null;
13
- exports.isObject = isObject;
14
- const isArray = (val) => Array.isArray(val);
15
- exports.isArray = isArray;
16
- const isURL = (val) => {
17
- if (!val) {
18
- return false;
19
- }
20
- return /^(http)|(\.*\/)/.test(val);
21
- };
22
- exports.isURL = isURL;
23
- const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
24
- exports.isEmpty = isEmpty;
25
- const toNumber = (val) => {
26
- if (val == null)
27
- return 0;
28
- if ((0, exports.isString)(val)) {
29
- val = parseFloat(val);
30
- val = Number.isNaN(val) ? 0 : val;
31
- return val;
32
- }
33
- if ((0, exports.isBoolean)(val))
34
- return Number(val);
35
- return val;
36
- };
37
- exports.toNumber = toNumber;
38
- const removeItem = (arr, item) => {
39
- if (arr.length) {
40
- const index = arr.indexOf(item);
41
- if (index > -1) {
42
- return arr.splice(index, 1);
43
- }
44
- }
45
- };
46
- exports.removeItem = removeItem;
47
- const toggleItem = (arr, item) => {
48
- arr.includes(item) ? (0, exports.removeItem)(arr, item) : arr.push(item);
49
- };
50
- exports.toggleItem = toggleItem;
51
- const throttle = (method, mustRunDelay = 200) => {
52
- let timer;
53
- let start = 0;
54
- return function loop(...args) {
55
- const now = Date.now();
56
- const elapsed = now - start;
57
- if (!start) {
58
- start = now;
59
- }
60
- if (timer) {
61
- window.clearTimeout(timer);
62
- }
63
- if (elapsed >= mustRunDelay) {
64
- method.apply(this, args);
65
- start = now;
66
- }
67
- else {
68
- timer = window.setTimeout(() => {
69
- loop.apply(this, args);
70
- }, mustRunDelay - elapsed);
71
- }
72
- };
73
- };
74
- exports.throttle = throttle;
75
- const inBrowser = () => typeof window !== 'undefined';
76
- exports.inBrowser = inBrowser;
77
- const uniq = (arr) => [...new Set(arr)];
78
- exports.uniq = uniq;
79
- const bigCamelize = (s) => (0, exports.camelize)(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
80
- exports.bigCamelize = bigCamelize;
81
- const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
82
- exports.camelize = camelize;
83
- const kebabCase = (s) => {
84
- const ret = s.replace(/([A-Z])/g, ' $1').trim();
85
- return ret.split(' ').join('-').toLowerCase();
86
- };
87
- exports.kebabCase = kebabCase;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.kebabCase = exports.camelize = exports.bigCamelize = exports.uniq = exports.inBrowser = exports.throttle = exports.toggleItem = exports.removeItem = exports.toNumber = exports.isEmpty = exports.isURL = exports.isArray = exports.isObject = exports.isPlainObject = exports.isNumber = exports.isBoolean = exports.isString = void 0;
4
+ const isString = (val) => typeof val === 'string';
5
+ exports.isString = isString;
6
+ const isBoolean = (val) => typeof val === 'boolean';
7
+ exports.isBoolean = isBoolean;
8
+ const isNumber = (val) => typeof val === 'number';
9
+ exports.isNumber = isNumber;
10
+ const isPlainObject = (val) => Object.prototype.toString.call(val) === '[object Object]';
11
+ exports.isPlainObject = isPlainObject;
12
+ const isObject = (val) => typeof val === 'object' && val !== null;
13
+ exports.isObject = isObject;
14
+ const isArray = (val) => Array.isArray(val);
15
+ exports.isArray = isArray;
16
+ const isURL = (val) => {
17
+ if (!val) {
18
+ return false;
19
+ }
20
+ return /^(http)|(\.*\/)/.test(val);
21
+ };
22
+ exports.isURL = isURL;
23
+ const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
24
+ exports.isEmpty = isEmpty;
25
+ const toNumber = (val) => {
26
+ if (val == null)
27
+ return 0;
28
+ if ((0, exports.isString)(val)) {
29
+ val = parseFloat(val);
30
+ val = Number.isNaN(val) ? 0 : val;
31
+ return val;
32
+ }
33
+ if ((0, exports.isBoolean)(val))
34
+ return Number(val);
35
+ return val;
36
+ };
37
+ exports.toNumber = toNumber;
38
+ const removeItem = (arr, item) => {
39
+ if (arr.length) {
40
+ const index = arr.indexOf(item);
41
+ if (index > -1) {
42
+ return arr.splice(index, 1);
43
+ }
44
+ }
45
+ };
46
+ exports.removeItem = removeItem;
47
+ const toggleItem = (arr, item) => {
48
+ arr.includes(item) ? (0, exports.removeItem)(arr, item) : arr.push(item);
49
+ };
50
+ exports.toggleItem = toggleItem;
51
+ const throttle = (method, mustRunDelay = 200) => {
52
+ let timer;
53
+ let start = 0;
54
+ return function loop(...args) {
55
+ const now = Date.now();
56
+ const elapsed = now - start;
57
+ if (!start) {
58
+ start = now;
59
+ }
60
+ if (timer) {
61
+ window.clearTimeout(timer);
62
+ }
63
+ if (elapsed >= mustRunDelay) {
64
+ method.apply(this, args);
65
+ start = now;
66
+ }
67
+ else {
68
+ timer = window.setTimeout(() => {
69
+ loop.apply(this, args);
70
+ }, mustRunDelay - elapsed);
71
+ }
72
+ };
73
+ };
74
+ exports.throttle = throttle;
75
+ const inBrowser = () => typeof window !== 'undefined';
76
+ exports.inBrowser = inBrowser;
77
+ const uniq = (arr) => [...new Set(arr)];
78
+ exports.uniq = uniq;
79
+ const bigCamelize = (s) => (0, exports.camelize)(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
80
+ exports.bigCamelize = bigCamelize;
81
+ const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
82
+ exports.camelize = camelize;
83
+ const kebabCase = (s) => {
84
+ const ret = s.replace(/([A-Z])/g, ' $1').trim();
85
+ return ret.split(' ').join('-').toLowerCase();
86
+ };
87
+ exports.kebabCase = kebabCase;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/shared",
3
- "version": "2.0.0-alpha.1663499244572",
3
+ "version": "2.0.0-alpha.1663742071515",
4
4
  "module": "es/index.js",
5
5
  "main": "lib/index.js",
6
6
  "description": "shared utils of varlet",
package/tsconfig.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./es",
4
- "target": "es6",
5
- "strict": true,
6
- "downlevelIteration": true,
7
- "declaration": true,
8
- "skipLibCheck": true,
9
- "esModuleInterop": true,
10
- "jsx": "preserve",
11
- "lib": ["esnext", "dom"]
12
- },
13
- "include": ["src/**/*"]
14
- }
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./es",
4
+ "target": "es6",
5
+ "strict": true,
6
+ "downlevelIteration": true,
7
+ "declaration": true,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "jsx": "preserve",
11
+ "lib": ["esnext", "dom"]
12
+ },
13
+ "include": ["src/**/*"]
14
+ }