@leexi/shared 0.5.1 → 0.6.0

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
@@ -69,6 +69,7 @@ export default defineNuxtConfig({
69
69
  - [groupBy](#groupby)
70
70
  - [joinBy](#joinby)
71
71
  - [partition](#partition)
72
+ - [pluck](#pluck)
72
73
  - [removeRecord](#removerecord)
73
74
  - [replaceRecord](#replacerecord)
74
75
  - [sortBy](#sortby)
@@ -150,6 +151,20 @@ console.log(localStorage.userSetting); // Output: '{"theme":"dark","notification
150
151
 
151
152
  ```
152
153
 
154
+ #### pluck
155
+ Extract the given attribute from each element in the array.
156
+ - Type
157
+ ```ts
158
+ const pluck: <T extends Record<string, unknown>, K extends keyof T>(records: T[], attr: K) => T[K][];
159
+ ```
160
+ - Example
161
+ ```ts
162
+ const records = [{ foo: 1 }, { foo: 2 }];
163
+ const foos = pluck(records, 'foo');
164
+
165
+ console.log(foos); // Output: [1, 2]
166
+ ```
167
+
153
168
  #### removeRecord
154
169
  - Type
155
170
  ```ts
@@ -169,15 +184,30 @@ const sortBy: <T, C extends (_: T) => Primitive, K extends Extract<FilteredAttrs
169
184
  ```
170
185
 
171
186
  #### sum
187
+ Returns the sum of elements.
172
188
  - Type
173
189
  ```ts
190
+ const sum: (numbers: number[]) => number;
191
+ ```
192
+ - Example
193
+ ```ts
194
+ const sum = sum([1, 2, 3])
174
195
 
196
+ console.log(sum); // Output: 6
175
197
  ```
176
198
 
177
199
  #### sumBy
200
+ Returns the sum of elements at a given attribute.
178
201
  - Type
179
202
  ```ts
203
+ const sumBy: <T extends Record<string, unknown>>(records: T[], attr: FilteredAttrs<T, number>) => number;
204
+ ```
205
+ - Example
206
+ ```ts
207
+ const records = [{ foo: 1 }, { foo: 2 }];
208
+ const sum = sumBy(records, 'foo');
180
209
 
210
+ console.log(sum); // Output: 3
181
211
  ```
182
212
 
183
213
  #### uniq
@@ -38,9 +38,12 @@ const config = [
38
38
  "prefer-template": "error",
39
39
  "@stylistic/array-bracket-spacing": ["error", "never"],
40
40
  "@stylistic/arrow-parens": ["error", "as-needed"],
41
+ "@stylistic/arrow-spacing": "error",
42
+ "@stylistic/block-spacing": "error",
41
43
  "@stylistic/comma-dangle": ["error", "always-multiline"],
42
44
  "@stylistic/comma-spacing": "error",
43
45
  "@stylistic/eol-last": ["error", "always"],
46
+ "@stylistic/function-call-spacing": "error",
44
47
  "@stylistic/indent": ["error", 2, {
45
48
  SwitchCase: 1
46
49
  }],
@@ -17,24 +17,51 @@ const config = [
17
17
  "@stylistic/indent": "off",
18
18
  "@stylistic/object-curly-spacing": "off",
19
19
  "tailwindcss/no-custom-classname": "error",
20
+ "vue/array-bracket-spacing": ["error", "never"],
21
+ "vue/arrow-spacing": "error",
20
22
  "vue/attributes-order": ["error", {
21
23
  alphabetical: true
22
24
  }],
25
+ "vue/block-spacing": "error",
26
+ "vue/comma-dangle": ["error", "always-multiline"],
27
+ "vue/comma-spacing": "error",
23
28
  "vue/component-name-in-template-casing": ["error", "PascalCase", {
24
29
  registeredComponentsOnly: false
25
30
  }],
31
+ "vue/custom-event-name-casing": "error",
32
+ "vue/define-macros-order": ["error", {
33
+ defineExposeLast: true,
34
+ order: ["definePage", "defineOptions", "defineProps", "defineEmits", "defineSlots", "defineModel"]
35
+ }],
36
+ "vue/eqeqeq": ["error", "smart"],
26
37
  "vue/first-attribute-linebreak": ["error", {
27
38
  singleline: "beside"
28
39
  }],
40
+ "vue/func-call-spacing": "error",
41
+ "vue/key-spacing": "error",
29
42
  "vue/multi-word-component-names": "off",
43
+ "vue/multiline-ternary": ["error", "never"],
30
44
  "vue/no-bare-strings-in-template": "error",
45
+ "vue/no-multiple-objects-in-class": "error",
46
+ "vue/no-negated-v-if-condition": "error",
47
+ "vue/no-unused-emit-declarations": "error",
48
+ "vue/no-unused-refs": "error",
31
49
  "vue/object-curly-spacing": ["error", "always"],
50
+ "vue/padding-line-between-blocks": "error",
51
+ "vue/prefer-separate-static-class": "error",
32
52
  "vue/prefer-template": "error",
53
+ "vue/prefer-use-template-ref": "error",
54
+ "vue/quote-props": ["error", "consistent-as-needed"],
33
55
  "vue/require-default-prop": "off",
56
+ "vue/require-macro-variable-name": "error",
34
57
  "vue/script-indent": ["error", 2, {
35
58
  switchCase: 1
36
59
  }],
37
- "vue/template-curly-spacing": ["error", "never"]
60
+ "vue/space-in-parens": ["error", "never"],
61
+ "vue/template-curly-spacing": ["error", "never"],
62
+ "vue/v-bind-style": ["error", "shorthand", {
63
+ sameNameShorthand: "always"
64
+ }]
38
65
  }
39
66
  },
40
67
  {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "configKey": "leexi",
3
3
  "name": "@leexi/shared",
4
- "version": "0.5.1",
4
+ "version": "0.6.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -33,6 +33,6 @@ export const useLocalStorage = (key, defaultValue) => {
33
33
  } else {
34
34
  localStorage?.removeItem(key);
35
35
  }
36
- }, { immediate: true });
36
+ }, { deep: true, immediate: true });
37
37
  return data;
38
38
  };
@@ -2,6 +2,7 @@ export { castArray } from "./castArray.js";
2
2
  export { groupBy } from "./groupBy.js";
3
3
  export { joinBy } from "./joinBy.js";
4
4
  export { partition } from "./partition.js";
5
+ export { pluck } from "./pluck.js";
5
6
  export { removeRecord } from "./removeRecord.js";
6
7
  export { replaceRecord } from "./replaceRecord.js";
7
8
  export { sortBy } from "./sortBy.js";
@@ -2,6 +2,7 @@ export { castArray } from './castArray.js';
2
2
  export { groupBy } from './groupBy.js';
3
3
  export { joinBy } from './joinBy.js';
4
4
  export { partition } from './partition.js';
5
+ export { pluck } from './pluck.js';
5
6
  export { removeRecord } from './removeRecord.js';
6
7
  export { replaceRecord } from './replaceRecord.js';
7
8
  export { sortBy } from './sortBy.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Extract the given attribute from each element in the array.
3
+ *
4
+ * @param records An array of records.
5
+ * @param attr An attribute of the given records.
6
+ * @returns An array of records mapped to the given attribute.
7
+ *
8
+ * @example
9
+ * const records = [{ foo: 1 }, { foo: 2 }];
10
+ * const foos = pluck(records, 'foo');
11
+ *
12
+ * console.log(foos); // Output: [1, 2]
13
+ */
14
+ export declare const pluck: <T extends Record<string, unknown>, K extends keyof T>(records: T[], attr: K) => T[K][];
@@ -0,0 +1 @@
1
+ export const pluck = (records, attr) => records.map((record) => record[attr]);
@@ -1,4 +1,4 @@
1
- import { deepDup } from "~/src/runtime/utils";
1
+ import { deepDup } from "../index.js";
2
2
  export const sortBy = (items, attrsOrCallbacks) => {
3
3
  const directions = [];
4
4
  if (!Array.isArray(attrsOrCallbacks)) {
@@ -1 +1,12 @@
1
- export function sum(numbers: any): any;
1
+ /**
2
+ * Returns the sum of elements.
3
+ *
4
+ * @param numbers An array of number.
5
+ * @returns The sum of numbers.
6
+ *
7
+ * @example
8
+ * const sum = sum([1, 2, 3])
9
+ *
10
+ * console.log(sum); // Output: 6
11
+ */
12
+ export declare const sum: (numbers: number[]) => number;
@@ -1 +1 @@
1
- export const sum = numbers => numbers.reduce((a, b) => a + b, 0);
1
+ export const sum = (numbers) => numbers.reduce((a, b) => a + b, 0);
@@ -1 +1,15 @@
1
- export function sumBy(records: any, attr: any): any;
1
+ import type { FilteredAttrs } from '~/types';
2
+ /**
3
+ * Returns the sum of elements at a given attribute.
4
+ *
5
+ * @param records An array of records.
6
+ * @param attr An attribute of the given records.
7
+ * @returns The sum of numbers.
8
+ *
9
+ * @example
10
+ * const records = [{ foo: 1 }, { foo: 2 }];
11
+ * const sum = sumBy(records, 'foo');
12
+ *
13
+ * console.log(sum); // Output: 3
14
+ */
15
+ export declare const sumBy: <T extends Record<string, unknown>>(records: T[], attr: FilteredAttrs<T, number>) => number;
@@ -1,3 +1,2 @@
1
- import { sum } from '../index.js';
2
-
3
- export const sumBy = (records, attr) => sum(records.map(record => record[attr]));
1
+ import { pluck, sum } from "../index.js";
2
+ export const sumBy = (records, attr) => sum(pluck(records, attr));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "license": "UNLICENSED",
3
3
  "name": "@leexi/shared",
4
4
  "type": "module",
5
- "version": "0.5.1",
5
+ "version": "0.6.0",
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.3.1",
49
+ "@stylistic/eslint-plugin": "^5.4.0",
50
50
  "@types/eslint-plugin-tailwindcss": "^3.17.0",
51
- "eslint": "^9.34.0",
51
+ "eslint": "^9.36.0",
52
52
  "eslint-plugin-sort-keys-plus": "^1.5.0",
53
53
  "eslint-plugin-tailwindcss": "^3.18.2",
54
- "eslint-plugin-vue": "^10.4.0",
55
- "globals": "^16.3.0",
56
- "typescript": "^5.9.2",
57
- "typescript-eslint": "^8.42.0",
54
+ "eslint-plugin-vue": "^10.5.0",
55
+ "globals": "^16.4.0",
56
+ "typescript": "^5.9.3",
57
+ "typescript-eslint": "^8.45.0",
58
58
  "vue-eslint-parser": "^10.2.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@nuxt/module-builder": "^1.0.2",
62
62
  "@nuxt/test-utils": "^3.19.2",
63
63
  "@types/node": "<23.0.0",
64
- "happy-dom": "^18.0.1",
65
- "nuxt": "^4.1.0",
64
+ "happy-dom": "^19.0.2",
65
+ "nuxt": "^4.1.2",
66
66
  "tailwindcss": "<4.0.0",
67
67
  "vitest": "^3.2.4",
68
- "vue-tsc": "^3.0.6"
68
+ "vue-tsc": "^3.1.0"
69
69
  }
70
70
  }