@varlet/shared 2.4.3-alpha.1671119797012 → 2.4.3-alpha.1672072688719

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
@@ -15,3 +15,4 @@ export declare const uniq: (arr: Array<any>) => any[];
15
15
  export declare const bigCamelize: (s: string) => string;
16
16
  export declare const camelize: (s: string) => string;
17
17
  export declare const kebabCase: (s: string) => string;
18
+ export declare const find: <T>(arr: T[], callback: (item: T, index: number, array: T[]) => any, from?: 'start' | 'end') => [T, number] | [null, -1];
package/lib/index.js CHANGED
@@ -65,3 +65,14 @@ export const kebabCase = (s) => {
65
65
  const ret = s.replace(/([A-Z])/g, ' $1').trim();
66
66
  return ret.split(' ').join('-').toLowerCase();
67
67
  };
68
+ export const find = (arr, callback, from = 'start') => {
69
+ let i = from === 'start' ? 0 : arr.length - 1;
70
+ while (arr.length > 0 && i >= 0 && i <= arr.length - 1) {
71
+ const flag = callback(arr[i], i, arr);
72
+ if (flag) {
73
+ return [arr[i], i];
74
+ }
75
+ from === 'start' ? i++ : i--;
76
+ }
77
+ return [null, -1];
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/shared",
3
- "version": "2.4.3-alpha.1671119797012",
3
+ "version": "2.4.3-alpha.1672072688719",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",