@leexi/shared 0.5.2 → 0.7.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,21 +184,43 @@ 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
214
+ Returns a new array by removing duplicate values in self.
184
215
  - Type
185
216
  ```ts
217
+ const uniq: (primitives: Primitive[]) => Primitive[];
218
+ ```
219
+ - Example
220
+ ```ts
221
+ const uniq = uniq([true, true, false, 1, 1, 2, 'foo', 'foo', 'bar'])
186
222
 
223
+ console.log(uniq); // Output: [true, false, 1, 2, 'foo', 'bar']
187
224
  ```
188
225
 
189
226
  #### uniqBy
@@ -228,7 +265,7 @@ console.log(originalObject.e === duplicatedObject.e); // Output: false
228
265
 
229
266
  #### isSame
230
267
  Checks if two objects are the same by comparing their JSON stringified representations.
231
- Note: This method has limitations and may not accurately compare objects with different key orders, non-primitive values like functions or Dates, or circular references.
268
+ Note: This method has limitations and may not accurately compare objects with different key orders, complex values like functions or Dates, or circular references.
232
269
  - Type
233
270
  ```ts
234
271
  const isSame: (a: object, b: object) => boolean;
@@ -32,15 +32,23 @@ const config = [
32
32
  destructuredArrayIgnorePattern: "^_",
33
33
  ignoreRestSiblings: true
34
34
  }],
35
+ "padding-line-between-statements": [
36
+ "error",
37
+ { blankLine: "always", next: "*", prev: "if" },
38
+ { blankLine: "any", next: "if", prev: "if" }
39
+ ],
35
40
  "prefer-const": ["error", {
36
41
  destructuring: "all"
37
42
  }],
38
43
  "prefer-template": "error",
39
44
  "@stylistic/array-bracket-spacing": ["error", "never"],
40
45
  "@stylistic/arrow-parens": ["error", "as-needed"],
46
+ "@stylistic/arrow-spacing": "error",
47
+ "@stylistic/block-spacing": "error",
41
48
  "@stylistic/comma-dangle": ["error", "always-multiline"],
42
49
  "@stylistic/comma-spacing": "error",
43
50
  "@stylistic/eol-last": ["error", "always"],
51
+ "@stylistic/function-call-spacing": "error",
44
52
  "@stylistic/indent": ["error", 2, {
45
53
  SwitchCase: 1
46
54
  }],
@@ -15,26 +15,52 @@ const config = [
15
15
  },
16
16
  rules: {
17
17
  "@stylistic/indent": "off",
18
- "@stylistic/object-curly-spacing": "off",
19
18
  "tailwindcss/no-custom-classname": "error",
19
+ "vue/array-bracket-spacing": ["error", "never"],
20
+ "vue/arrow-spacing": "error",
20
21
  "vue/attributes-order": ["error", {
21
22
  alphabetical: true
22
23
  }],
24
+ "vue/block-spacing": "error",
25
+ "vue/comma-dangle": ["error", "always-multiline"],
26
+ "vue/comma-spacing": "error",
23
27
  "vue/component-name-in-template-casing": ["error", "PascalCase", {
24
28
  registeredComponentsOnly: false
25
29
  }],
30
+ "vue/custom-event-name-casing": "error",
31
+ "vue/define-macros-order": ["error", {
32
+ defineExposeLast: true,
33
+ order: ["definePage", "defineOptions", "defineProps", "defineEmits", "defineSlots", "defineModel"]
34
+ }],
35
+ "vue/eqeqeq": ["error", "smart"],
26
36
  "vue/first-attribute-linebreak": ["error", {
27
37
  singleline: "beside"
28
38
  }],
39
+ "vue/func-call-spacing": "error",
40
+ "vue/key-spacing": "error",
29
41
  "vue/multi-word-component-names": "off",
42
+ "vue/multiline-ternary": ["error", "never"],
30
43
  "vue/no-bare-strings-in-template": "error",
44
+ "vue/no-multiple-objects-in-class": "error",
45
+ "vue/no-negated-v-if-condition": "error",
46
+ "vue/no-unused-emit-declarations": "error",
47
+ "vue/no-unused-refs": "error",
31
48
  "vue/object-curly-spacing": ["error", "always"],
49
+ "vue/padding-line-between-blocks": "error",
50
+ "vue/prefer-separate-static-class": "error",
32
51
  "vue/prefer-template": "error",
52
+ "vue/prefer-use-template-ref": "error",
53
+ "vue/quote-props": ["error", "consistent-as-needed"],
33
54
  "vue/require-default-prop": "off",
55
+ "vue/require-macro-variable-name": "error",
34
56
  "vue/script-indent": ["error", 2, {
35
57
  switchCase: 1
36
58
  }],
37
- "vue/template-curly-spacing": ["error", "never"]
59
+ "vue/space-in-parens": ["error", "never"],
60
+ "vue/template-curly-spacing": ["error", "never"],
61
+ "vue/v-bind-style": ["error", "shorthand", {
62
+ sameNameShorthand: "always"
63
+ }]
38
64
  }
39
65
  },
40
66
  {
package/dist/module.d.mts CHANGED
@@ -1,11 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  declare const _default: _nuxt_schema.NuxtModule<{
4
- composables: boolean;
5
- utils: boolean;
4
+ iconDir: string;
6
5
  }, {
7
- composables: boolean;
8
- utils: boolean;
6
+ iconDir: string;
9
7
  }, false>;
10
8
 
11
9
  export { _default as default };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "configKey": "leexi",
3
3
  "name": "@leexi/shared",
4
- "version": "0.5.2",
4
+ "version": "0.7.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,17 +1,17 @@
1
- import { readdirSync, statSync } from 'fs';
2
- import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit';
1
+ import { existsSync, readdirSync, statSync } from 'fs';
2
+ import { defineNuxtModule, createResolver, addTypeTemplate, updateTemplates, addImports } from '@nuxt/kit';
3
3
 
4
4
  const module = defineNuxtModule({
5
5
  defaults: {
6
- composables: true,
7
- utils: true
6
+ iconDir: "app/assets/images/icons"
8
7
  },
9
8
  meta: {
10
9
  configKey: "leexi",
11
10
  name: "@leexi/shared"
12
11
  },
13
- setup: (options) => {
12
+ setup: (options, nuxt) => {
14
13
  const resolver = createResolver(import.meta.url);
14
+ const rootResolver = createResolver(nuxt.options.rootDir);
15
15
  const addImportsDir = (dir) => {
16
16
  const files = readdirSync(dir);
17
17
  files.forEach((file) => {
@@ -27,12 +27,32 @@ const module = defineNuxtModule({
27
27
  addImports({ as: name, from: path, name });
28
28
  });
29
29
  };
30
- if (options.composables) {
31
- addImportsDir(resolver.resolve("./runtime/composables"));
32
- }
33
- if (options.utils) {
34
- addImportsDir(resolver.resolve("./runtime/utils"));
30
+ addImportsDir(resolver.resolve("./runtime/composables"));
31
+ addImportsDir(resolver.resolve("./runtime/utils"));
32
+ const iconDir = rootResolver.resolve(options.iconDir);
33
+ if (!existsSync(iconDir)) {
34
+ return;
35
35
  }
36
+ addTypeTemplate({
37
+ filename: "types/leexi-shared.d.ts",
38
+ getContents: () => {
39
+ const icons = readdirSync(iconDir).map((filename) => filename.replace(".svg", ""));
40
+ return [
41
+ "// Generated by @leexi/shared",
42
+ "",
43
+ "declare module '@leexi/shared' {",
44
+ ` export type IconName = ${icons.map((icon) => `'${icon}'`).join(" | ")}`,
45
+ "}",
46
+ "",
47
+ "export {}"
48
+ ].join("\n");
49
+ }
50
+ });
51
+ nuxt.hook("builder:watch", (event, path) => {
52
+ if (["add", "unlink"].includes(event) && path.includes(options.iconDir)) {
53
+ updateTemplates({ filter: ({ filename }) => filename === "types/leexi-shared.d.ts" });
54
+ }
55
+ });
36
56
  }
37
57
  });
38
58
 
@@ -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 +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));
@@ -1 +1,13 @@
1
- export function uniq(values: any): any[];
1
+ import type { Primitive } from '~/types';
2
+ /**
3
+ * Returns a new array by removing duplicate values in self.
4
+ *
5
+ * @param primitives An array of boolean, number and/or string.
6
+ * @returns The filtered array of primitives.
7
+ *
8
+ * @example
9
+ * const uniq = uniq([true, true, false, 1, 1, 2, 'foo', 'foo', 'bar'])
10
+ *
11
+ * console.log(uniq); // Output: [true, false, 1, 2, 'foo', 'bar']
12
+ */
13
+ export declare const uniq: (primitives: Primitive[]) => Primitive[];
@@ -1 +1 @@
1
- export const uniq = values => [...new Set(values || [])];
1
+ export const uniq = (primitives) => [...new Set(primitives || [])];
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Checks if two objects are the same by comparing their JSON stringified representations.
3
- * Note: This method has limitations and may not accurately compare objects with different key orders, non-primitive values like functions or Dates, or circular references.
3
+ * Note: This method has limitations and may not accurately compare objects with different key orders, complex values like functions or Dates, or circular references.
4
4
  *
5
5
  * @param a The first object to compare.
6
6
  * @param b The second object to compare.
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.2",
5
+ "version": "0.7.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
  }