@leexi/shared 0.0.6 → 0.1.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/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "@leexi/shared",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.1.0",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
7
7
  "test": "vitest run"
8
8
  },
9
+ "exports": {
10
+ "./composables": "./src/composables/index.js",
11
+ "./eslint/base": "./src/eslint/base.js",
12
+ "./eslint/vue": "./src/eslint/vue.js",
13
+ "./utils": "./src/utils/index.js",
14
+ ".": "./src/module.js"
15
+ },
16
+ "files": [
17
+ "src"
18
+ ],
19
+ "main": "./src/module.js",
9
20
  "dependencies": {
10
21
  "@stylistic/eslint-plugin-js": "^4.2.0",
11
22
  "@stylistic/eslint-plugin-ts": "^4.2.0",
@@ -18,21 +29,16 @@
18
29
  "vue-eslint-parser": "^10.1.1"
19
30
  },
20
31
  "devDependencies": {
32
+ "@leexi/shared": "^0.0.6",
33
+ "@nuxt/test-utils": "^3.17.2",
21
34
  "eslint": "^9.23.0",
22
35
  "happy-dom": "^17.4.4",
36
+ "nuxt": "^3.16.2",
23
37
  "tailwindcss": "<4.0.0",
24
- "vitest": "^3.1.1"
38
+ "vitest": "^3.1.1",
39
+ "vue": "^3.5.13"
25
40
  },
26
41
  "peerDependencies": {
27
42
  "eslint": ">9.0.0"
28
- },
29
- "exports": {
30
- "./eslint/base": "./eslint/base.js",
31
- "./eslint/vue": "./eslint/vue.js",
32
- "./utils": "./utils/index.js"
33
- },
34
- "files": [
35
- "eslint",
36
- "utils"
37
- ]
43
+ }
38
44
  }
@@ -0,0 +1 @@
1
+ export { useLocalStorage } from './useLocalStorage.js';
@@ -0,0 +1,30 @@
1
+ import { useState, watch } from '#imports';
2
+
3
+ /**
4
+ * Creates a reactive pointer to a specific localStorage value.
5
+ * The value is stored in the localStorage as a JSON stringified data to enable parsing primitives and objects
6
+ *
7
+ * @template T extends unknown
8
+ * @param {string} key - a key pointing to a localStorage value
9
+ * @param {T} [defaultValue] - an optional default value used if the localStorage value is undefined
10
+ * @returns {Ref<T>} a reactive variable pointing to that localStorage value
11
+ *
12
+ * @example
13
+ * const fooOne = useLocalStorage('foo')
14
+ * const fooTwo = useLocalStorage('foo', 'bar')
15
+ * fooOne.value // => 'bar'
16
+ * localStorage.foo // => '"bar"'
17
+ */
18
+ export const useLocalStorage = (key, defaultValue) => {
19
+ const data = useState(key, () => JSON.parse(localStorage?.getItem(key) || null) || defaultValue);
20
+
21
+ watch(data, () => {
22
+ if (data.value) {
23
+ localStorage?.setItem(key, JSON.stringify(data.value));
24
+ } else {
25
+ localStorage?.removeItem(key);
26
+ }
27
+ }, { immediate: true });
28
+
29
+ return data;
30
+ };
package/src/module.js ADDED
@@ -0,0 +1,18 @@
1
+ import { addImportsDir, createResolver, defineNuxtModule } from '@nuxt/kit';
2
+
3
+ export default defineNuxtModule({
4
+ meta: {
5
+ configKey: 'leexi',
6
+ defaults: {
7
+ composables: true,
8
+ utils: true,
9
+ },
10
+ name: '@leexi/shared',
11
+ },
12
+ setup (options) {
13
+ const resolver = createResolver(import.meta.url);
14
+
15
+ if (options.composables) { addImportsDir(resolver.resolve('./composables')); }
16
+ if (options.utils) { addImportsDir(resolver.resolve('./utils')); }
17
+ },
18
+ });
@@ -0,0 +1 @@
1
+ export * from './objects/index.js';
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Deeply duplicates an object.
3
+ *
4
+ * @param {object} object - an object
5
+ * @returns {object} a duplicate of the same object
6
+ *
7
+ * @example
8
+ * const object = [{ foo: 'bar' }]
9
+ * const dup = deepDup(object) // => `[{ foo: 'bar' }]`
10
+ * object === dup // => `false`
11
+ */
1
12
  export const deepDup = object => {
2
13
  if (!object || typeof object !== 'object') { return object; }
3
14
 
@@ -0,0 +1,2 @@
1
+ export { deepDup } from './deepDup.js';
2
+ export { isSame } from './isSame.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Compares whether two objects are identical.
3
+ *
4
+ * @param {object} a - an object
5
+ * @param {object} b - another object
6
+ * @returns {boolean} whether these objects are identical
7
+ *
8
+ * @example
9
+ * isSame([{ foo: 'bar' }], [{ foo: 'bar' }]) // => `true`
10
+ * isSame([{ foo: 'bar' }], [{ bar: 'foo' }]) // => `false`
11
+ */
12
+ export const isSame = (a, b) => JSON.stringify(a) === JSON.stringify(b);
package/utils/index.js DELETED
@@ -1 +0,0 @@
1
- export { deepDup } from './objects/deepDup.js';
File without changes
File without changes