Skip to content

Commit

Permalink
more tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 20, 2024
1 parent 2a36129 commit b47812b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
6 changes: 5 additions & 1 deletion packages/bits-ui/src/lib/internal/afterTick.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { tick } from "svelte";
import type { AnyFn } from "./types.js";

export function afterTick(cb: () => void) {
/**
* Calls the provided callback after the current tick.
*/
export function afterTick(cb: AnyFn) {
tick().then(cb);
}
3 changes: 3 additions & 0 deletions packages/bits-ui/src/lib/internal/arrays.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Checks if two arrays are equal by comparing their values.
*/
export function arraysAreEqual<T extends Array<unknown>>(arr1: T, arr2: T): boolean {
if (arr1.length !== arr2.length) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions packages/bits-ui/src/lib/internal/clamp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Clamps a number between a minimum and maximum value.
*/
export function clamp(n: number, min: number, max: number) {
return Math.min(max, Math.max(min, n));
}
8 changes: 6 additions & 2 deletions packages/bits-ui/src/lib/internal/floating-svelte/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function get<T>(valueOrGetValue: T | (() => T)): T {
return typeof valueOrGetValue === "function" ? (valueOrGetValue as () => T)() : valueOrGetValue;
import type { Getter, MaybeGetter } from "svelte-toolbelt";

export function get<T>(valueOrGetValue: MaybeGetter<T>): T {
return typeof valueOrGetValue === "function"
? (valueOrGetValue as Getter<T>)()
: valueOrGetValue;
}

export function getDPR(element: Element): number {
Expand Down
18 changes: 9 additions & 9 deletions packages/bits-ui/src/lib/shared/date/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { hasTime, isZonedDateTime, toDate } from "./index.js";

export type Formatter = ReturnType<typeof createFormatter>;

const defaultPartOptions: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
};

/**
* Creates a wrapper around the `DateFormatter`, which is
* an improved version of the {@link Intl.DateTimeFormat} API,
Expand Down Expand Up @@ -78,15 +87,6 @@ export function createFormatter(initialLocale: string) {
return "AM";
}

const defaultPartOptions: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
};

function part(
dateObj: DateValue,
type: Intl.DateTimeFormatPartTypes,
Expand Down
12 changes: 3 additions & 9 deletions packages/bits-ui/src/lib/shared/date/placeholders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,9 @@ export function getPlaceholder(
// eslint-disable-next-line @typescript-eslint/ban-types
locale: SupportedLocale | (string & {})
) {
if (isPlaceholderField(field)) {
return getPlaceholderObj(locale)[field];
}
if (isDefaultField(field)) {
return value;
}
if (isTimeField(field)) {
return "––";
}
if (isPlaceholderField(field)) return getPlaceholderObj(locale)[field];
if (isDefaultField(field)) return value;
if (isTimeField(field)) return "––";
return "";
}

Expand Down

0 comments on commit b47812b

Please sign in to comment.