Skip to content

Commit

Permalink
chore(monorepo): Reformat previously updated files
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Oct 8, 2024
1 parent 7136dec commit 6daa183
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/errors/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-------------------------------------------------------------------*/

import { ValidationDetails } from "@storm-stack/types";
import { ValidationDetails } from "@storm-stack/types/utility-types/validations";

export type StormErrorOptions<
TErrorType extends ErrorType = typeof ErrorType.EXCEPTION,
Expand Down
3 changes: 1 addition & 2 deletions packages/hooks/src/use-escape-keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
-------------------------------------------------------------------*/

import React from "react"; // via radix-ui

import React from "react";
import { useCallbackRef } from "./use-callback-ref";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/server-result/src/server-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-------------------------------------------------------------------*/

import { StormDateTime } from "@storm-stack/date-time/storm-date-time";
import { StormError } from "@storm-stack/errors";
import { StormError } from "@storm-stack/errors/storm-error";
import { MessageDetails } from "@storm-stack/types/utility-types/messages";
import { ServerResultType } from "./types";

Expand Down
4 changes: 3 additions & 1 deletion packages/types/src/type-checks/is-object-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
* @param value - The value to check.
* @returns Returns `true` if the value is an object index, otherwise `false`.
*/
export function isObjectIndex(value: PropertyKey): boolean {
export function isObjectIndex(
value: PropertyKey
): value is string | number | symbol {
switch (typeof value) {
case "number": {
return (
Expand Down
3 changes: 0 additions & 3 deletions packages/types/src/utility-types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

/* eslint-disable tsdoc/syntax */
/* eslint-disable @cspell/spellchecker */
/* eslint-disable @typescript-eslint/ban-types */

import type {
StaticPartOfArray,
Expand All @@ -41,8 +40,6 @@ import type { Numeric } from "./number";
import type { StringDigit } from "./string";
import type { Index40, Nullable } from "./utilities";

export type ObjectIndex = string | number | symbol;

/**
* Returns a boolean for whether the given type is an empty object.
*/
Expand Down
29 changes: 19 additions & 10 deletions packages/utilities/src/helper-fns/flatten-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ import { DeepKey, DeepValue, isPlainObject } from "@storm-stack/types";
* @param object - The object to flatten.
* @returns - The flattened object.
*/
export function flattenObject<TObject extends Record<string, any> = Record<string, any>, TDeepKeyObject extends { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> } = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }>(object: TObject): TDeepKeyObject {
export function flattenObject<
TObject extends Record<string, any> = Record<string, any>,
TDeepKeyObject extends {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
} = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }
>(object: TObject): TDeepKeyObject {
return flattenObjectImpl<TObject, TDeepKeyObject>(object);
}

function flattenObjectImpl<TObject extends Record<string, any> = Record<string, any>, TDeepKeyObject extends { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> } = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }>(object: TObject, prefix = ""): TDeepKeyObject {
function flattenObjectImpl<
TObject extends Record<string, any> = Record<string, any>,
TDeepKeyObject extends {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
} = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }
>(object: TObject, prefix = ""): TDeepKeyObject {
const result = {} as TDeepKeyObject;
const keys = Object.keys(object);

Expand All @@ -58,18 +68,17 @@ function flattenObjectImpl<TObject extends Record<string, any> = Record<string,
const prefixedKey = prefix ? `${prefix}.${key}` : key;

if (isPlainObject(value) && Object.keys(value).length > 0) {
Object.assign(result, flattenObjectImpl<typeof value>(value, prefixedKey));
continue;
}

if (Array.isArray(value)) {
Object.assign(
result,
flattenObjectImpl<typeof value>(value, prefixedKey)
);
} else if (Array.isArray(value)) {
for (const [index, element_] of value.entries()) {
result[`${prefixedKey}.${index}` as DeepKey<TObject>] = element_;
}
continue;
} else {
result[prefixedKey as DeepKey<TObject>] = value;
}

result[prefixedKey as DeepKey<TObject>] = value;
}

return result;
Expand Down
2 changes: 2 additions & 0 deletions packages/utilities/src/helper-fns/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
-------------------------------------------------------------------*/

/* eslint-disable no-param-reassign */

import { isDeepKey, isNumber, toStringKey } from "@storm-stack/types";
import { toObjectPath } from "./to-object-path";

Expand Down
2 changes: 1 addition & 1 deletion packages/utilities/src/helper-fns/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function set<TObject extends Record<string, any> = Record<string, any>>(
const key = resolvedPath[i];
const nextKey = resolvedPath[i + 1];

if (current[key] == null) {
if (current[key] === null) {
current[key] = isObjectIndex(nextKey) ? [] : {};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utilities/src/helper-fns/to-object-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const DOTS_KEY = /^[\w.]+$/g;

const ESCAPE_REGEXP = /\\(\\)?/g;
const ESCAPE_REGEXP = /\\(?<temp1>\\)?/g;
const PROPERTY_REGEXP = new RegExp(
// Match anything that isn't a dot or bracket.
String.raw`[^.[\]]+` +
Expand Down

0 comments on commit 6daa183

Please sign in to comment.