@leexi/shared 0.3.0 → 0.3.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/dist/eslint/base.eslint.config.d.ts +1341 -0
- package/dist/eslint/base.eslint.config.mjs +123 -0
- package/dist/eslint/vue.eslint.config.d.ts +1375 -0
- package/dist/eslint/vue.eslint.config.mjs +48 -0
- package/dist/module.d.mts +11 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +34 -13
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useLocalStorage.d.ts +16 -0
- package/dist/runtime/composables/useLocalStorage.js +12 -0
- package/dist/runtime/utils/index.d.ts +3 -0
- package/dist/runtime/utils/index.js +3 -0
- package/dist/runtime/utils/objects/deepDup.d.ts +9 -0
- package/dist/runtime/utils/objects/deepDup.js +17 -0
- package/dist/runtime/utils/objects/index.d.ts +2 -0
- package/dist/runtime/utils/objects/index.js +2 -0
- package/dist/runtime/utils/objects/isSame.d.ts +8 -0
- package/dist/runtime/utils/objects/isSame.js +1 -0
- package/dist/runtime/utils/records/index.d.ts +1 -0
- package/dist/runtime/utils/records/index.js +1 -0
- package/dist/runtime/utils/records/set.d.ts +19 -0
- package/dist/runtime/utils/records/set.js +5 -0
- package/dist/runtime/utils/strings/capitalize.d.ts +7 -0
- package/dist/runtime/utils/strings/capitalize.js +1 -0
- package/dist/runtime/utils/strings/index.d.ts +1 -0
- package/dist/runtime/utils/strings/index.js +1 -0
- package/dist/types.d.mts +4 -10
- package/package.json +4 -4
- package/dist/module.d.cts +0 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import tailwind from "eslint-plugin-tailwindcss";
|
|
2
|
+
import tseslint from "typescript-eslint";
|
|
3
|
+
import vue from "eslint-plugin-vue";
|
|
4
|
+
import base from "./base.eslint.config.mjs";
|
|
5
|
+
export default [
|
|
6
|
+
...base,
|
|
7
|
+
...tailwind.configs["flat/recommended"],
|
|
8
|
+
...vue.configs["flat/recommended"],
|
|
9
|
+
{
|
|
10
|
+
files: ["**/*.vue"],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parserOptions: {
|
|
13
|
+
parser: tseslint.parser
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
rules: {
|
|
17
|
+
"@stylistic/js/indent": "off",
|
|
18
|
+
"@stylistic/js/object-curly-spacing": "off",
|
|
19
|
+
"@stylistic/ts/indent": "off",
|
|
20
|
+
"tailwindcss/no-custom-classname": "error",
|
|
21
|
+
"vue/attributes-order": ["error", {
|
|
22
|
+
alphabetical: true
|
|
23
|
+
}],
|
|
24
|
+
"vue/component-name-in-template-casing": ["error", "PascalCase", {
|
|
25
|
+
registeredComponentsOnly: false
|
|
26
|
+
}],
|
|
27
|
+
"vue/first-attribute-linebreak": ["error", {
|
|
28
|
+
singleline: "beside"
|
|
29
|
+
}],
|
|
30
|
+
"vue/multi-word-component-names": "off",
|
|
31
|
+
"vue/no-bare-strings-in-template": "error",
|
|
32
|
+
"vue/object-curly-spacing": ["error", "always"],
|
|
33
|
+
"vue/prefer-template": "error",
|
|
34
|
+
"vue/require-default-prop": "off",
|
|
35
|
+
"vue/script-indent": ["error", 2, {
|
|
36
|
+
switchCase: 1
|
|
37
|
+
}],
|
|
38
|
+
"vue/template-curly-spacing": ["error", "never"]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
ignores: [
|
|
43
|
+
"**/.nuxt/",
|
|
44
|
+
"**/.output/",
|
|
45
|
+
"**/dist/"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
];
|
package/dist/module.d.mts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
|
|
3
|
+
declare const _default: _nuxt_schema.NuxtModule<{
|
|
4
|
+
composables: boolean;
|
|
5
|
+
utils: boolean;
|
|
6
|
+
}, {
|
|
7
|
+
composables: boolean;
|
|
8
|
+
utils: boolean;
|
|
9
|
+
}, false>;
|
|
10
|
+
|
|
11
|
+
export { _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,18 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readdirSync, statSync } from 'fs';
|
|
2
|
+
import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit';
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const module = defineNuxtModule({
|
|
5
|
+
defaults: {
|
|
6
|
+
composables: true,
|
|
7
|
+
utils: true
|
|
7
8
|
},
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
9
|
+
meta: {
|
|
10
|
+
configKey: "leexi",
|
|
11
|
+
name: "@leexi/shared"
|
|
12
|
+
},
|
|
13
|
+
setup: (options) => {
|
|
14
|
+
const resolver = createResolver(import.meta.url);
|
|
15
|
+
const addImportsDir = (dir) => {
|
|
16
|
+
const files = readdirSync(dir);
|
|
17
|
+
files.forEach((file) => {
|
|
18
|
+
if (/index/.test(file) || /\.d\.ts/.test(file)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const path = resolver.resolve(`${dir}/${file}`);
|
|
22
|
+
const stat = statSync(path);
|
|
23
|
+
if (stat.isDirectory()) {
|
|
24
|
+
return addImportsDir(path);
|
|
25
|
+
}
|
|
26
|
+
const [name] = file.split(".");
|
|
27
|
+
addImports({ as: name, from: path, name });
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
if (options.composables) {
|
|
31
|
+
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
32
|
+
}
|
|
33
|
+
if (options.utils) {
|
|
34
|
+
addImportsDir(resolver.resolve("./runtime/utils"));
|
|
11
35
|
}
|
|
12
36
|
}
|
|
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");
|
|
37
|
+
});
|
|
17
38
|
|
|
18
|
-
export
|
|
39
|
+
export { module as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from './useLocalStorage.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocalStorage } from "./useLocalStorage.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
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 declare const useLocalStorage: <T>(key: string, defaultValue?: T) => Ref<undefined | T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useState, watch } from "#imports";
|
|
2
|
+
export const useLocalStorage = (key, defaultValue) => {
|
|
3
|
+
const data = useState(key, () => JSON.parse(localStorage?.getItem(key) || "null") || defaultValue);
|
|
4
|
+
watch(data, () => {
|
|
5
|
+
if (data.value) {
|
|
6
|
+
localStorage?.setItem(key, JSON.stringify(data.value));
|
|
7
|
+
} else {
|
|
8
|
+
localStorage?.removeItem(key);
|
|
9
|
+
}
|
|
10
|
+
}, { immediate: true });
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const deepDup = (object) => {
|
|
2
|
+
if (!object || typeof object !== "object") {
|
|
3
|
+
return object;
|
|
4
|
+
}
|
|
5
|
+
const duplicate = (value) => value && typeof value === "object" ? deepDup(value) : value;
|
|
6
|
+
if (Array.isArray(object)) {
|
|
7
|
+
return object.map(duplicate);
|
|
8
|
+
}
|
|
9
|
+
if (object instanceof Set) {
|
|
10
|
+
return new Set([...object].map(duplicate));
|
|
11
|
+
}
|
|
12
|
+
if (Object.getPrototypeOf(object) === Object.prototype) {
|
|
13
|
+
const dup = Object.entries(object).map(([key, value]) => [key, duplicate(value)]);
|
|
14
|
+
return Object.fromEntries(dup);
|
|
15
|
+
}
|
|
16
|
+
return object;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isSame = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { set } from './set.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { set } from "./set.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type SetRecord<T extends Record<string, unknown>, P extends readonly string[], V> = P extends [infer F extends string, ...infer R extends readonly string[]] ? T & {
|
|
2
|
+
[K in F]: R extends [] ? V : SetRecord<T[K] extends T ? T[K] : {}, R, V>;
|
|
3
|
+
} : T;
|
|
4
|
+
/**
|
|
5
|
+
* Deeply sets an attribute at a specified path within a nested object.
|
|
6
|
+
* **This method is destructive.**
|
|
7
|
+
*
|
|
8
|
+
* @param record - a record
|
|
9
|
+
* @param path - an array of strings leading to a deeply nested key in the record
|
|
10
|
+
* @param value - a value to be set at the given path
|
|
11
|
+
* @returns the mutated record
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const foo = {}
|
|
15
|
+
* set(foo, ['bar', 'biz'], 'fiz')
|
|
16
|
+
* foo // => { bar: { biz: 'fiz' } }
|
|
17
|
+
*/
|
|
18
|
+
export declare const set: <T extends Record<string, unknown>, const P extends string[], V>(record: T, path: P, value: V) => SetRecord<T, P, V>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const capitalize = (string = "") => `${string.charAt(0).toUpperCase()}${string.slice(1)}`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capitalize } from './capitalize.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capitalize } from "./capitalize.js";
|
package/dist/types.d.mts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
|
|
5
|
-
}
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
interface NuxtHooks extends ModuleHooks {}
|
|
9
|
-
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
10
|
-
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
11
|
-
}
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
12
6
|
|
|
13
|
-
export
|
|
7
|
+
export { default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"license": "UNLICENSED",
|
|
3
3
|
"name": "@leexi/shared",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.2",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./composables": {
|
|
8
8
|
"import": "./dist/runtime/composables/index.js",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
40
|
+
"build": "nuxt-module-build build && bun run lib/readme",
|
|
41
41
|
"dev": "nuxi dev playground",
|
|
42
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
42
43
|
"lint": "eslint .",
|
|
43
|
-
"prepack": "
|
|
44
|
-
"prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
44
|
+
"prepack": "yarn lint && yarn test --reporter default && yarn tsc && yarn build",
|
|
45
45
|
"test": "vitest run",
|
|
46
46
|
"tsc": "vue-tsc --noEmit"
|
|
47
47
|
},
|
package/dist/module.d.cts
DELETED