@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.
@@ -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
- export * from "/home/joenn/code/joenn/leexi/shared/src/module.js";
2
- export { default } from "/home/joenn/code/joenn/leexi/shared/src/module.js";
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "configKey": "leexi",
3
3
  "name": "@leexi/shared",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -1,18 +1,39 @@
1
- import { createJiti } from "../node_modules/jiti/lib/jiti.mjs";
1
+ import { readdirSync, statSync } from 'fs';
2
+ import { defineNuxtModule, createResolver, addImports } from '@nuxt/kit';
2
3
 
3
- const jiti = createJiti(import.meta.url, {
4
- "interopDefault": true,
5
- "alias": {
6
- "@leexi/shared": "/home/joenn/code/joenn/leexi/shared"
4
+ const module = defineNuxtModule({
5
+ defaults: {
6
+ composables: true,
7
+ utils: true
7
8
  },
8
- "transformOptions": {
9
- "babel": {
10
- "plugins": []
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 default _module?.default ?? _module;
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,3 @@
1
+ export * from './objects/index.js';
2
+ export * from './records/index.js';
3
+ export * from './strings/index.js';
@@ -0,0 +1,3 @@
1
+ export * from "./objects/index.js";
2
+ export * from "./records/index.js";
3
+ export * from "./strings/index.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Deeply duplicates an object.
3
+ *
4
+ * @example
5
+ * const object = [{ foo: 'bar' }]
6
+ * const dup = deepDup(object) // => `[{ foo: 'bar' }]`
7
+ * object === dup // => `false`
8
+ */
9
+ export declare const deepDup: <T extends object>(object: T) => T;
@@ -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,2 @@
1
+ export { deepDup } from './deepDup.js';
2
+ export { isSame } from './isSame.js';
@@ -0,0 +1,2 @@
1
+ export { deepDup } from "./deepDup.js";
2
+ export { isSame } from "./isSame.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Compares whether two objects are identical.
3
+ *
4
+ * @example
5
+ * isSame([{ foo: 'bar' }], [{ foo: 'bar' }]) // => `true`
6
+ * isSame([{ foo: 'bar' }], [{ bar: 'foo' }]) // => `false`
7
+ */
8
+ export declare const isSame: (a: object, b: object) => boolean;
@@ -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,5 @@
1
+ export const set = (record, path, value) => {
2
+ const [key, ...rest] = path;
3
+ Object.assign(record, { ...record, [key]: rest.length ? set(record[key] ?? {}, rest, value) : value });
4
+ return record;
5
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Capitalizes a string
3
+ *
4
+ * @example
5
+ * capitalize('foo') // => 'Foo'
6
+ */
7
+ export declare const capitalize: (string?: string) => string;
@@ -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 { ModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module.mjs'
1
+ import type { NuxtModule } from '@nuxt/schema'
2
2
 
3
- declare module '#app' {
4
- interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
5
- }
3
+ import type { default as Module } from './module.mjs'
6
4
 
7
- declare module '@nuxt/schema' {
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 * from "./module.mjs"
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.0",
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": "yarn prepare && yarn lint && yarn test --reporter default && yarn tsc && yarn prepack && bun run lib/readme",
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": "nuxt-module-build build",
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
@@ -1,2 +0,0 @@
1
- export * from "/home/joenn/code/joenn/leexi/shared/src/module.js";
2
- export { default } from "/home/joenn/code/joenn/leexi/shared/src/module.js";