Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add several utils #233

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-trees-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": patch
---

change extract types
5 changes: 5 additions & 0 deletions .changeset/shaggy-paws-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": minor
---

add textarea autosize
5 changes: 5 additions & 0 deletions .changeset/six-flies-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": minor
---

add extract
5 changes: 5 additions & 0 deletions .changeset/slow-islands-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": minor
---

add scroll state
5 changes: 5 additions & 0 deletions .changeset/ten-eyes-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"runed": minor
---

export getter and maybegetter types
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"format": "prettier --write .",
"check": "pnpm -r check",
"sync": "pnpm -r sync",
"new": "node ./scripts/add-utility.mjs"
"add": "node ./scripts/add-utility.mjs"
},
"license": "MIT",
"devDependencies": {
Expand All @@ -49,7 +49,7 @@
"@typescript-eslint/utils": "^8.10.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.46.1",
"eslint-plugin-svelte": "^3.3.3",
"globals": "^15.11.0",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.3.2",
Expand Down
1 change: 1 addition & 0 deletions packages/runed/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./utilities/index.js";
export type { MaybeGetter, Getter, Setter } from "./internal/types.js";
16 changes: 11 additions & 5 deletions packages/runed/src/lib/utilities/extract/extract.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import type { Getter, MaybeGetter } from "$lib/internal/types.js";
import type { MaybeGetter } from "$lib/internal/types.js";
import { isFunction } from "$lib/internal/utils/is.js";

export function extract<T>(value: MaybeGetter<T>): T;
export function extract<T>(value: MaybeGetter<T | undefined>, defaultValue: T): T;

/**
* Extracts the value from a getter or a value.
* Optionally, a default value can be provided.
*/
export function extract<T>(value: MaybeGetter<T>, defaultValue?: T): T {
export function extract(value: unknown, defaultValue?: unknown) {
if (isFunction(value)) {
const getter = value as Getter<T>;
return getter() ?? defaultValue ?? getter();
const getter = value;
const gotten = getter();
if (gotten === undefined) return defaultValue;
return gotten;
}

return value ?? defaultValue ?? value;
if (value === undefined) return defaultValue;
return value;
}
38 changes: 21 additions & 17 deletions packages/runed/src/lib/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
export * from "./active-element/index.js";
export * from "./on-click-outside/index.js";
export * from "./use-debounce/index.js";
export * from "./animation-frames/index.js";
export * from "./context/index.js";
export * from "./debounced/index.js";
export * from "./element-rect/index.js";
export * from "./element-size/index.js";
export * from "./use-event-listener/index.js";
export * from "./extract/index.js";
export * from "./finite-state-machine/index.js";
export * from "./is-focus-within/index.js";
export * from "./is-idle/index.js";
export * from "./is-in-viewport/index.js";
export * from "./is-mounted/index.js";
export * from "./state-history/index.js";
export * from "./previous/index.js";
export * from "./watch/index.js";
export * from "./debounced/index.js";
export * from "./on-click-outside/index.js";
export * from "./persisted-state/index.js";
export * from "./pressed-keys/index.js";
export * from "./element-rect/index.js";
export * from "./previous/index.js";
export * from "./resource/index.js";
export * from "./state-history/index.js";
export * from "./textarea-autosize/index.js";
export * from "./use-debounce/index.js";
export * from "./use-event-listener/index.js";
export * from "./use-geolocation/index.js";
export * from "./use-intersection-observer/index.js";
export * from "./use-mutation-observer/index.js";
export * from "./use-resize-observer/index.js";
export * from "./animation-frames/index.js";
export * from "./use-intersection-observer/index.js";
export * from "./is-focus-within/index.js";
export * from "./finite-state-machine/index.js";
export * from "./persisted-state/index.js";
export * from "./use-geolocation/index.js";
export * from "./context/index.js";
export * from "./is-in-viewport/index.js";
export * from "./resource/index.js";
export * from "./watch/index.js";

export * from "./scroll-state/index.js";
1 change: 1 addition & 0 deletions packages/runed/src/lib/utilities/scroll-state/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./scroll-state.svelte.js";
Loading
Loading