@leexi/shared 0.7.1 → 0.7.2

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 CHANGED
@@ -66,6 +66,7 @@ export default defineNuxtConfig({
66
66
  - [Utils](#utils)
67
67
  - [Array](#array)
68
68
  - [castArray](#castarray)
69
+ - [filterMap](#filtermap)
69
70
  - [groupBy](#groupby)
70
71
  - [joinBy](#joinby)
71
72
  - [partition](#partition)
@@ -80,6 +81,7 @@ export default defineNuxtConfig({
80
81
  - [Function](#function)
81
82
  - [debounce](#debounce)
82
83
  - [Number](#number)
84
+ - [rand](#rand)
83
85
  - [toPadStart](#topadstart)
84
86
  - [Objects](#objects)
85
87
  - [deepDup](#deepdup)
@@ -133,6 +135,21 @@ console.log(localStorage.userSetting); // Output: '{"theme":"dark","notification
133
135
 
134
136
  ```
135
137
 
138
+ #### filterMap
139
+ Returns a new array containing the truthy results (everything except false, '', 0, undefined and null) of running the
140
+ given callback for every item.
141
+ - Type
142
+ ```ts
143
+ const filterMap: <T>(items: T[], callback: (_item: T) => unknown) => unknown[];
144
+ ```
145
+ - Example
146
+ ```ts
147
+ const items = [0, 1];
148
+ const foos = filterMap(records, foo => foo2);
149
+
150
+ console.log(foos); // Output: [2]
151
+ ```
152
+
136
153
  #### groupBy
137
154
  - Type
138
155
  ```ts
@@ -237,6 +254,22 @@ console.log(uniq); // Output: [true, false, 1, 2, 'foo', 'bar']
237
254
  ```
238
255
 
239
256
  ### Number
257
+ #### rand
258
+ Returns a random integer greater than or equal to `min` and less than or equal to `max`.
259
+ If the min is bigger than the max then NaN is returned.
260
+ - Type
261
+ ```ts
262
+ const rand: (max: number, min?: number) => number;
263
+ ```
264
+ - Example
265
+ ```ts
266
+ const randOne = rand(2);
267
+ console.log(randOne); // Output: 1
268
+
269
+ const randTwo = rand(2, -2);
270
+ console.log(randTwo); // Output: -1
271
+ ```
272
+
240
273
  #### toPadStart
241
274
  - Type
242
275
  ```ts
@@ -27,6 +27,7 @@ const config = [
27
27
  "eqeqeq": ["error", "smart"],
28
28
  "no-console": "error",
29
29
  "no-nested-ternary": "error",
30
+ "no-shadow": "error",
30
31
  "no-unused-vars": ["error", {
31
32
  argsIgnorePattern: "^_",
32
33
  destructuredArrayIgnorePattern: "^_",
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "configKey": "leexi",
3
3
  "name": "@leexi/shared",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Returns a new array containing the truthy results (everything except false, '', 0, undefined and null) of running the
3
+ * given callback for every item.
4
+ *
5
+ * @param items An array of items.
6
+ * @param callback A callback returning the mapped result.
7
+ * @returns An array of filtered items mapped to the given callback.
8
+ *
9
+ * @example
10
+ * const items = [0, 1];
11
+ * const foos = filterMap(records, foo => foo * 2);
12
+ *
13
+ * console.log(foos); // Output: [2]
14
+ */
15
+ export declare const filterMap: <T>(items: T[], callback: (_item: T) => unknown) => unknown[];
@@ -0,0 +1,7 @@
1
+ export const filterMap = (items, callback) => items.reduce((filteredItems, currentItem) => {
2
+ const item = callback(currentItem);
3
+ if (item) {
4
+ filteredItems.push(item);
5
+ }
6
+ return filteredItems;
7
+ }, []);
@@ -1,4 +1,5 @@
1
1
  export { castArray } from "./castArray.js";
2
+ export { filterMap } from "./filterMap.js";
2
3
  export { groupBy } from "./groupBy.js";
3
4
  export { joinBy } from "./joinBy.js";
4
5
  export { partition } from "./partition.js";
@@ -1,4 +1,5 @@
1
1
  export { castArray } from './castArray.js';
2
+ export { filterMap } from './filterMap.js';
2
3
  export { groupBy } from './groupBy.js';
3
4
  export { joinBy } from './joinBy.js';
4
5
  export { partition } from './partition.js';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns a random integer greater than or equal to `min` and less than or equal to `max`.
3
+ * If the min is bigger than the max then NaN is returned.
4
+ *
5
+ * @param max A number.
6
+ * @param min A number (defaults to 0).
7
+ * @returns A random number within the range.
8
+ *
9
+ * @example
10
+ * const randOne = rand(2);
11
+ * console.log(randOne); // Output: 1
12
+ *
13
+ * const randTwo = rand(2, -2);
14
+ * console.log(randTwo); // Output: -1
15
+ */
16
+ export declare const rand: (max: number, min?: number) => number;
@@ -0,0 +1 @@
1
+ export const rand = (max, min = 0) => Math.floor(Math.random() * (max - min + 1)) + min;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "license": "UNLICENSED",
3
3
  "name": "@leexi/shared",
4
4
  "type": "module",
5
- "version": "0.7.1",
5
+ "version": "0.7.2",
6
6
  "exports": {
7
7
  "./composables": {
8
8
  "import": "./dist/runtime/composables/index.js",
@@ -46,25 +46,25 @@
46
46
  "tsc": "vue-tsc --noEmit"
47
47
  },
48
48
  "dependencies": {
49
- "@stylistic/eslint-plugin": "^5.5.0",
50
- "@types/eslint-plugin-tailwindcss": "^3.17.0",
51
- "eslint": "^9.39.0",
52
- "eslint-plugin-sort-keys-plus": "^1.5.0",
53
- "eslint-plugin-tailwindcss": "^3.18.2",
54
- "eslint-plugin-vue": "^10.5.1",
55
- "globals": "^16.5.0",
56
- "typescript": "^5.9.3",
57
- "typescript-eslint": "^8.46.2",
58
- "vue-eslint-parser": "^10.2.0"
49
+ "@stylistic/eslint-plugin": "5.6.1",
50
+ "@types/eslint-plugin-tailwindcss": "3.17.0",
51
+ "eslint": "9.39.1",
52
+ "eslint-plugin-sort-keys-plus": "1.5.0",
53
+ "eslint-plugin-tailwindcss": "3.18.2",
54
+ "eslint-plugin-vue": "10.6.2",
55
+ "globals": "16.5.0",
56
+ "typescript": "5.9.3",
57
+ "typescript-eslint": "8.48.1",
58
+ "vue-eslint-parser": "10.2.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@nuxt/module-builder": "^1.0.2",
62
- "@nuxt/test-utils": "^3.20.1",
61
+ "@nuxt/module-builder": "1.0.2",
62
+ "@nuxt/test-utils": "3.20.1",
63
63
  "@types/node": "<23.0.0",
64
- "happy-dom": "^20.0.10",
65
- "nuxt": "^4.2.0",
64
+ "happy-dom": "20.0.11",
65
+ "nuxt": "4.2.2",
66
66
  "tailwindcss": "<4.0.0",
67
- "vitest": "^4.0.6",
68
- "vue-tsc": "^3.1.3"
67
+ "vitest": "4.0.14",
68
+ "vue-tsc": "3.1.5"
69
69
  }
70
70
  }