@varlet/shared 2.10.0 → 2.10.1-alpha.1682608027166

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/lib/index.d.ts CHANGED
@@ -1,20 +1,20 @@
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 isFunction: (val: unknown) => val is Function;
7
- export declare const isArray: (val: unknown) => val is any[];
8
- export declare const isURL: (val: string | undefined | null) => boolean;
9
- export declare const isEmpty: (val: unknown) => boolean;
10
- export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
11
- export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
12
- export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
13
- export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
14
- export declare const inBrowser: () => boolean;
15
- export declare const uniq: (arr: Array<any>) => any[];
16
- export declare const bigCamelize: (s: string) => string;
17
- export declare const camelize: (s: string) => string;
18
- export declare const kebabCase: (s: string) => string;
19
- export declare const find: <T>(arr: T[], callback: (item: T, index: number, array: T[]) => any, from?: 'start' | 'end') => [T, number] | [null, -1];
20
- export declare const normalizeToArray: <T>(value: T | T[]) => T[];
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 isFunction: (val: unknown) => val is Function;
7
+ export declare const isArray: (val: unknown) => val is any[];
8
+ export declare const isURL: (val: string | undefined | null) => boolean;
9
+ export declare const isEmpty: (val: unknown) => boolean;
10
+ export declare const toNumber: (val: number | string | boolean | undefined | null) => number;
11
+ export declare const removeItem: (arr: Array<unknown>, item: unknown) => unknown[] | undefined;
12
+ export declare const toggleItem: (arr: Array<unknown>, item: unknown) => void;
13
+ export declare const throttle: (method: any, mustRunDelay?: number) => (() => void);
14
+ export declare const inBrowser: () => boolean;
15
+ export declare const uniq: (arr: Array<any>) => any[];
16
+ export declare const bigCamelize: (s: string) => string;
17
+ export declare const camelize: (s: string) => string;
18
+ export declare const kebabCase: (s: string) => string;
19
+ export declare const find: <T>(arr: T[], callback: (item: T, index: number, array: T[]) => any, from?: 'start' | 'end') => [T, number] | [null, -1];
20
+ export declare const normalizeToArray: <T>(value: T | T[]) => T[];
package/lib/index.js CHANGED
@@ -1,81 +1,81 @@
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
- // eslint-disable-next-line
7
- export const isFunction = (val) => typeof val === 'function';
8
- export const isArray = (val) => Array.isArray(val);
9
- export const isURL = (val) => {
10
- if (!val) {
11
- return false;
12
- }
13
- return /^(http)|(\.*\/)/.test(val);
14
- };
15
- export const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
16
- export const toNumber = (val) => {
17
- if (val == null)
18
- return 0;
19
- if (isString(val)) {
20
- val = parseFloat(val);
21
- val = Number.isNaN(val) ? 0 : val;
22
- return val;
23
- }
24
- if (isBoolean(val))
25
- return Number(val);
26
- return val;
27
- };
28
- export const removeItem = (arr, item) => {
29
- if (arr.length) {
30
- const index = arr.indexOf(item);
31
- if (index > -1) {
32
- return arr.splice(index, 1);
33
- }
34
- }
35
- };
36
- export const toggleItem = (arr, item) => {
37
- arr.includes(item) ? removeItem(arr, item) : arr.push(item);
38
- };
39
- export const throttle = (method, mustRunDelay = 200) => {
40
- let timer;
41
- let start = 0;
42
- return function loop(...args) {
43
- const now = Date.now();
44
- const elapsed = now - start;
45
- if (!start) {
46
- start = now;
47
- }
48
- if (timer) {
49
- window.clearTimeout(timer);
50
- }
51
- if (elapsed >= mustRunDelay) {
52
- method.apply(this, args);
53
- start = now;
54
- }
55
- else {
56
- timer = window.setTimeout(() => {
57
- loop.apply(this, args);
58
- }, mustRunDelay - elapsed);
59
- }
60
- };
61
- };
62
- export const inBrowser = () => typeof window !== 'undefined';
63
- export const uniq = (arr) => [...new Set(arr)];
64
- export const bigCamelize = (s) => camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
65
- export const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
66
- export const kebabCase = (s) => {
67
- const ret = s.replace(/([A-Z])/g, ' $1').trim();
68
- return ret.split(' ').join('-').toLowerCase();
69
- };
70
- export const find = (arr, callback, from = 'start') => {
71
- let i = from === 'start' ? 0 : arr.length - 1;
72
- while (arr.length > 0 && i >= 0 && i <= arr.length - 1) {
73
- const flag = callback(arr[i], i, arr);
74
- if (flag) {
75
- return [arr[i], i];
76
- }
77
- from === 'start' ? i++ : i--;
78
- }
79
- return [null, -1];
80
- };
81
- export const normalizeToArray = (value) => (isArray(value) ? value : [value]);
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
+ // eslint-disable-next-line
7
+ export const isFunction = (val) => typeof val === 'function';
8
+ export const isArray = (val) => Array.isArray(val);
9
+ export const isURL = (val) => {
10
+ if (!val) {
11
+ return false;
12
+ }
13
+ return /^(http)|(\.*\/)/.test(val);
14
+ };
15
+ export const isEmpty = (val) => val === undefined || val === null || val === '' || (Array.isArray(val) && !val.length);
16
+ export const toNumber = (val) => {
17
+ if (val == null)
18
+ return 0;
19
+ if (isString(val)) {
20
+ val = parseFloat(val);
21
+ val = Number.isNaN(val) ? 0 : val;
22
+ return val;
23
+ }
24
+ if (isBoolean(val))
25
+ return Number(val);
26
+ return val;
27
+ };
28
+ export const removeItem = (arr, item) => {
29
+ if (arr.length) {
30
+ const index = arr.indexOf(item);
31
+ if (index > -1) {
32
+ return arr.splice(index, 1);
33
+ }
34
+ }
35
+ };
36
+ export const toggleItem = (arr, item) => {
37
+ arr.includes(item) ? removeItem(arr, item) : arr.push(item);
38
+ };
39
+ export const throttle = (method, mustRunDelay = 200) => {
40
+ let timer;
41
+ let start = 0;
42
+ return function loop(...args) {
43
+ const now = Date.now();
44
+ const elapsed = now - start;
45
+ if (!start) {
46
+ start = now;
47
+ }
48
+ if (timer) {
49
+ window.clearTimeout(timer);
50
+ }
51
+ if (elapsed >= mustRunDelay) {
52
+ method.apply(this, args);
53
+ start = now;
54
+ }
55
+ else {
56
+ timer = window.setTimeout(() => {
57
+ loop.apply(this, args);
58
+ }, mustRunDelay - elapsed);
59
+ }
60
+ };
61
+ };
62
+ export const inBrowser = () => typeof window !== 'undefined';
63
+ export const uniq = (arr) => [...new Set(arr)];
64
+ export const bigCamelize = (s) => camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
65
+ export const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
66
+ export const kebabCase = (s) => {
67
+ const ret = s.replace(/([A-Z])/g, ' $1').trim();
68
+ return ret.split(' ').join('-').toLowerCase();
69
+ };
70
+ export const find = (arr, callback, from = 'start') => {
71
+ let i = from === 'start' ? 0 : arr.length - 1;
72
+ while (arr.length > 0 && i >= 0 && i <= arr.length - 1) {
73
+ const flag = callback(arr[i], i, arr);
74
+ if (flag) {
75
+ return [arr[i], i];
76
+ }
77
+ from === 'start' ? i++ : i--;
78
+ }
79
+ return [null, -1];
80
+ };
81
+ export const normalizeToArray = (value) => (isArray(value) ? value : [value]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/shared",
3
- "version": "2.10.0",
3
+ "version": "2.10.1-alpha.1682608027166",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",