@leexi/shared 0.2.0 → 0.3.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 +143 -0
- package/dist/module.d.cts +2 -0
- package/dist/module.d.mts +2 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +18 -0
- package/dist/types.d.mts +13 -0
- package/package.json +31 -19
- package/dist/composables/index.d.ts +0 -1
- package/dist/composables/index.js +0 -1
- package/dist/composables/useLocalStorage.d.ts +0 -15
- package/dist/composables/useLocalStorage.js +0 -27
- package/dist/eslint/base.d.ts +0 -1279
- package/dist/eslint/base.js +0 -110
- package/dist/eslint/vue.d.ts +0 -1306
- package/dist/eslint/vue.js +0 -43
- package/dist/module.d.ts +0 -8
- package/dist/module.js +0 -36
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/objects/deepDup.d.ts +0 -12
- package/dist/utils/objects/deepDup.js +0 -28
- package/dist/utils/objects/index.d.ts +0 -2
- package/dist/utils/objects/index.js +0 -2
- package/dist/utils/objects/isSame.d.ts +0 -12
- package/dist/utils/objects/isSame.js +0 -12
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<p align="center"><img src="https://github.com/user-attachments/assets/581a8322-430f-4912-bc11-60fc0ca099f4" width="500"></p><br><br><br>
|
|
2
|
+
|
|
3
|
+
`@leexi/shared` is a collection of config files and utility functions for JavaScript or TypeScript based repositories as well as composables and components for Vue based repositores of the [Leexi-ai](https://github.com/Leexi-ai) organisation.
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
```bash
|
|
7
|
+
yarn add -D @leexi/shared
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# Usage
|
|
11
|
+
## esLint
|
|
12
|
+
There are 2 available esLint configs.
|
|
13
|
+
- **[base](https://github.com/Leexi-ai/shared/blob/master/src/eslint/base.eslint.config.ts)**: for JavaScript/TypeScript based repositories
|
|
14
|
+
- **[vue](https://github.com/Leexi-ai/shared/blob/master/src/eslint/vue.eslint.config.ts)**: for Vue based repositories
|
|
15
|
+
```js
|
|
16
|
+
// eslint.config.js
|
|
17
|
+
import base from '@leexi/shared/eslint/base';
|
|
18
|
+
|
|
19
|
+
export default [
|
|
20
|
+
...base,
|
|
21
|
+
{
|
|
22
|
+
// add custom config here
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Utils
|
|
28
|
+
```js
|
|
29
|
+
import { deepDup, isSame, set } from '@leexi/shared/utils';
|
|
30
|
+
|
|
31
|
+
const foo = { foo: 'bar' };
|
|
32
|
+
const dup = deepDup(foo);
|
|
33
|
+
if (isSame(foo, dup)) {
|
|
34
|
+
set(foo, ['foo'], 'fiz');
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Composables
|
|
39
|
+
```vue
|
|
40
|
+
<script setup>
|
|
41
|
+
import { useLocalStorage } from '@leexi/shared/composables'
|
|
42
|
+
|
|
43
|
+
const mode = useLocalStorage('mode', 'dark')
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Nuxt
|
|
48
|
+
This package provides a module for Nuxt to auto import every component, composable and util in a Nuxt based repository
|
|
49
|
+
```js
|
|
50
|
+
// nuxt.config.ts
|
|
51
|
+
export default defineNuxtConfig({
|
|
52
|
+
modules: [
|
|
53
|
+
'@leexi/shared'
|
|
54
|
+
],
|
|
55
|
+
|
|
56
|
+
leexi: {
|
|
57
|
+
composables: true, // whether composables should be auto-imported. Defaults to true
|
|
58
|
+
utils: true, // whether utils should be auto-imported. Defaults to true
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
# API
|
|
64
|
+
- [Composables](#composables)
|
|
65
|
+
- [useLocalStorage](#uselocalstorage)
|
|
66
|
+
- [Utils](#utils)
|
|
67
|
+
- [Records](#records)
|
|
68
|
+
- [set](#set)
|
|
69
|
+
- [Strings](#strings)
|
|
70
|
+
- [capitalize](#capitalize)
|
|
71
|
+
- [Objects](#objects)
|
|
72
|
+
- [deepDup](#deepdup)
|
|
73
|
+
- [isSame](#issame)
|
|
74
|
+
|
|
75
|
+
## Composables
|
|
76
|
+
### useLocalStorage
|
|
77
|
+
Creates a reactive pointer to a specific localStorage value.
|
|
78
|
+
The value is stored in the localStorage as a JSON stringified data to enable parsing primitives and objects
|
|
79
|
+
- Type
|
|
80
|
+
```ts
|
|
81
|
+
const useLocalStorage: <T>(key: string, defaultValue?: T) => Ref<undefined | T>;
|
|
82
|
+
```
|
|
83
|
+
- Example
|
|
84
|
+
```ts
|
|
85
|
+
const fooOne = useLocalStorage('foo')
|
|
86
|
+
const fooTwo = useLocalStorage('foo', 'bar')
|
|
87
|
+
fooOne.value // => 'bar'
|
|
88
|
+
localStorage.foo // => '"bar"'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Utils
|
|
92
|
+
### Records
|
|
93
|
+
#### set
|
|
94
|
+
Deeply sets an attribute at a specified path within a nested object.
|
|
95
|
+
**This method is destructive.**
|
|
96
|
+
- Type
|
|
97
|
+
```ts
|
|
98
|
+
const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
|
|
99
|
+
```
|
|
100
|
+
- Example
|
|
101
|
+
```ts
|
|
102
|
+
const foo = {}
|
|
103
|
+
set(foo, ['bar', 'biz'], 'fiz')
|
|
104
|
+
foo // => { bar: { biz: 'fiz' } }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Strings
|
|
108
|
+
#### capitalize
|
|
109
|
+
Capitalizes a string
|
|
110
|
+
- Type
|
|
111
|
+
```ts
|
|
112
|
+
const capitalize: (string?: string) => string;
|
|
113
|
+
```
|
|
114
|
+
- Example
|
|
115
|
+
```ts
|
|
116
|
+
capitalize('foo') // => 'Foo'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Objects
|
|
120
|
+
#### deepDup
|
|
121
|
+
Deeply duplicates an object.
|
|
122
|
+
- Type
|
|
123
|
+
```ts
|
|
124
|
+
const deepDup: <T extends object>(object: T) => T;
|
|
125
|
+
```
|
|
126
|
+
- Example
|
|
127
|
+
```ts
|
|
128
|
+
const object = [{ foo: 'bar' }]
|
|
129
|
+
const dup = deepDup(object) // => `[{ foo: 'bar' }]`
|
|
130
|
+
object === dup // => `false`
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### isSame
|
|
134
|
+
Compares whether two objects are identical.
|
|
135
|
+
- Type
|
|
136
|
+
```ts
|
|
137
|
+
const isSame: (a: object, b: object) => boolean;
|
|
138
|
+
```
|
|
139
|
+
- Example
|
|
140
|
+
```ts
|
|
141
|
+
isSame([{ foo: 'bar' }], [{ foo: 'bar' }]) // => `true`
|
|
142
|
+
isSame([{ foo: 'bar' }], [{ bar: 'foo' }]) // => `false`
|
|
143
|
+
```
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createJiti } from "../node_modules/jiti/lib/jiti.mjs";
|
|
2
|
+
|
|
3
|
+
const jiti = createJiti(import.meta.url, {
|
|
4
|
+
"interopDefault": true,
|
|
5
|
+
"alias": {
|
|
6
|
+
"@leexi/shared": "/home/joenn/code/joenn/leexi/shared"
|
|
7
|
+
},
|
|
8
|
+
"transformOptions": {
|
|
9
|
+
"babel": {
|
|
10
|
+
"plugins": []
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
/** @type {import("/home/joenn/code/joenn/leexi/shared/src/module.js")} */
|
|
16
|
+
const _module = await jiti.import("/home/joenn/code/joenn/leexi/shared/src/module.ts");
|
|
17
|
+
|
|
18
|
+
export default _module?.default ?? _module;
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module.mjs'
|
|
2
|
+
|
|
3
|
+
declare module '#app' {
|
|
4
|
+
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare module '@nuxt/schema' {
|
|
8
|
+
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
10
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export * from "./module.mjs"
|
package/package.json
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
+
"license": "UNLICENSED",
|
|
2
3
|
"name": "@leexi/shared",
|
|
3
4
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "yarn lint && yarn test --reporter default && tsc && tsc -p tsconfig.build.json",
|
|
7
|
-
"lint": "eslint .",
|
|
8
|
-
"postinstall": "nuxt prepare",
|
|
9
|
-
"test": "vitest run"
|
|
10
|
-
},
|
|
5
|
+
"version": "0.3.0",
|
|
11
6
|
"exports": {
|
|
12
7
|
"./composables": {
|
|
13
|
-
"import": "./dist/composables/index.js",
|
|
14
|
-
"types": "./dist/composables/index.d.ts"
|
|
8
|
+
"import": "./dist/runtime/composables/index.js",
|
|
9
|
+
"types": "./dist/runtime/composables/index.d.ts"
|
|
15
10
|
},
|
|
16
11
|
"./eslint/base": {
|
|
17
|
-
"import": "./dist/eslint/base.
|
|
18
|
-
"types": "./dist/eslint/base.d.ts"
|
|
12
|
+
"import": "./dist/eslint/base.eslint.config.mjs",
|
|
13
|
+
"types": "./dist/eslint/base.eslint.config.d.ts"
|
|
19
14
|
},
|
|
20
15
|
"./eslint/vue": {
|
|
21
|
-
"import": "./dist/eslint/vue.
|
|
22
|
-
"types": "./dist/eslint/vue.d.ts"
|
|
16
|
+
"import": "./dist/eslint/vue.eslint.config.mjs",
|
|
17
|
+
"types": "./dist/eslint/vue.eslint.config.d.ts"
|
|
23
18
|
},
|
|
24
19
|
"./utils": {
|
|
25
|
-
"import": "./dist/utils/index.js",
|
|
26
|
-
"types": "./dist/utils/index.d.ts"
|
|
20
|
+
"import": "./dist/runtime/utils/index.js",
|
|
21
|
+
"types": "./dist/runtime/utils/index.d.ts"
|
|
27
22
|
},
|
|
28
23
|
".": {
|
|
29
|
-
"import": "./dist/module.
|
|
30
|
-
"types": "./dist/module.d.
|
|
24
|
+
"import": "./dist/module.mjs",
|
|
25
|
+
"types": "./dist/module.d.mts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/module.mjs",
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
"*": {
|
|
31
|
+
".": [
|
|
32
|
+
"./dist/types.d.mts"
|
|
33
|
+
]
|
|
31
34
|
}
|
|
32
35
|
},
|
|
33
36
|
"files": [
|
|
34
37
|
"dist"
|
|
35
38
|
],
|
|
36
|
-
"
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "yarn prepare && yarn lint && yarn test --reporter default && yarn tsc && yarn prepack && bun run lib/readme",
|
|
41
|
+
"dev": "nuxi dev playground",
|
|
42
|
+
"lint": "eslint .",
|
|
43
|
+
"prepack": "nuxt-module-build build",
|
|
44
|
+
"prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"tsc": "vue-tsc --noEmit"
|
|
47
|
+
},
|
|
37
48
|
"dependencies": {
|
|
38
49
|
"@stylistic/eslint-plugin-js": "^4.2.0",
|
|
39
50
|
"@stylistic/eslint-plugin-ts": "^4.2.0",
|
|
@@ -46,6 +57,7 @@
|
|
|
46
57
|
"vue-eslint-parser": "^10.1.1"
|
|
47
58
|
},
|
|
48
59
|
"devDependencies": {
|
|
60
|
+
"@nuxt/module-builder": "^1.0.1",
|
|
49
61
|
"@nuxt/test-utils": "^3.17.2",
|
|
50
62
|
"@types/node": "^22.14.0",
|
|
51
63
|
"eslint": "^9.23.0",
|
|
@@ -53,7 +65,7 @@
|
|
|
53
65
|
"nuxt": "^3.16.2",
|
|
54
66
|
"tailwindcss": "<4.0.0",
|
|
55
67
|
"vitest": "^3.1.1",
|
|
56
|
-
"vue": "^
|
|
68
|
+
"vue-tsc": "^2.2.8"
|
|
57
69
|
},
|
|
58
70
|
"peerDependencies": {
|
|
59
71
|
"eslint": ">9.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useLocalStorage } from './useLocalStorage';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useLocalStorage } from './useLocalStorage';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a reactive pointer to a specific localStorage value.
|
|
3
|
-
* The value is stored in the localStorage as a JSON stringified data to enable parsing primitives and objects
|
|
4
|
-
*
|
|
5
|
-
* @param key - a key pointing to a localStorage value
|
|
6
|
-
* @param defaultValue - an optional default value used if the localStorage value is undefined
|
|
7
|
-
* @returns a reactive variable pointing to that localStorage value
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* const fooOne = useLocalStorage('foo')
|
|
11
|
-
* const fooTwo = useLocalStorage('foo', 'bar')
|
|
12
|
-
* fooOne.value // => 'bar'
|
|
13
|
-
* localStorage.foo // => '"bar"'
|
|
14
|
-
*/
|
|
15
|
-
export declare const useLocalStorage: <T>(key: string, defaultValue?: T) => any;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useState, watch } from '#imports';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a reactive pointer to a specific localStorage value.
|
|
4
|
-
* The value is stored in the localStorage as a JSON stringified data to enable parsing primitives and objects
|
|
5
|
-
*
|
|
6
|
-
* @param key - a key pointing to a localStorage value
|
|
7
|
-
* @param defaultValue - an optional default value used if the localStorage value is undefined
|
|
8
|
-
* @returns a reactive variable pointing to that localStorage value
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const fooOne = useLocalStorage('foo')
|
|
12
|
-
* const fooTwo = useLocalStorage('foo', 'bar')
|
|
13
|
-
* fooOne.value // => 'bar'
|
|
14
|
-
* localStorage.foo // => '"bar"'
|
|
15
|
-
*/
|
|
16
|
-
export const useLocalStorage = (key, defaultValue) => {
|
|
17
|
-
const data = useState(key, () => JSON.parse(localStorage?.getItem(key) || 'null') || defaultValue);
|
|
18
|
-
watch(data, () => {
|
|
19
|
-
if (data.value) {
|
|
20
|
-
localStorage?.setItem(key, JSON.stringify(data.value));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
localStorage?.removeItem(key);
|
|
24
|
-
}
|
|
25
|
-
}, { immediate: true });
|
|
26
|
-
return data;
|
|
27
|
-
};
|