New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@yamada-ui/utils

Package Overview
Dependencies
Maintainers
1
Versions
551
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yamada-ui/utils - npm Package Compare versions

Comparing version 0.0.0-dev-20230606151107 to 0.0.0-dev-20230714125059

dist/chunk-VPOQGCMS.mjs

2

dist/assertion.d.ts

@@ -9,3 +9,3 @@ import { Dict } from './index.types.js';

declare const isNull: (value: any) => value is null;
declare const isObject: <T extends Dict<any>>(value: any) => value is T;
declare const isObject: <T extends Dict>(value: any) => value is T;
declare const isArray: <T extends any[]>(value: any) => value is T;

@@ -12,0 +12,0 @@ declare const isEmpty: (value: any) => boolean;

@@ -5,3 +5,3 @@ export { Dict, DynamicRecord, Length, Path, StringLiteral, Union } from './index.types.js';

export { funcAll, handlerAll, noop, runIfFunc } from './function.js';
export { DOMAttributes, MaybeRenderProp, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js';
export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect } from './react.js';
export { FocusableElement, ariaAttr, createdDom, dataAttr, getActiveElement, getAllFocusable, getEventRelatedTarget, getOwnerDocument, getOwnerWindow, getPlatform, hasNegativeTabIndex, hasTabIndex, isActiveElement, isApple, isContains, isContentEditable, isDisabled, isElement, isFocusable, isHTMLElement, isHidden, isMac, isSafari, isTabbable, platform, vendor } from './dom.js';

@@ -8,0 +8,0 @@ export { escape } from './string.js';

@@ -126,2 +126,5 @@ "use strict";

transparentizeColor: () => transparentizeColor,
useAsync: () => useAsync,
useAsyncFunc: () => useAsyncFunc,
useAsyncRetry: () => useAsyncRetry,
useCallbackRef: () => useCallbackRef,

@@ -396,2 +399,44 @@ useIsMounted: () => useIsMounted,

};
var useAsync = (func, deps = []) => {
const [state, callback] = useAsyncFunc(func, deps, { loading: true });
React.useEffect(() => {
callback();
}, [callback]);
return state;
};
var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
const lastCallId = React.useRef(0);
const isMounted = useIsMounted();
const [state, setState] = React.useState(initialState);
const callback = React.useCallback((...args) => {
const callId = ++lastCallId.current;
if (!state.loading) {
setState((prevState) => ({ ...prevState, loading: true }));
}
return func(...args).then(
(value) => {
if (isMounted.current && callId === lastCallId.current)
setState({ value, loading: false });
return value;
},
(error) => {
if (isMounted.current && callId === lastCallId.current)
setState({ error, loading: false });
return error;
}
);
}, deps);
return [state, callback];
};
var useAsyncRetry = (func, deps = []) => {
const [attempt, setAttempt] = React.useState(0);
const state = useAsync(func, [...deps, attempt]);
const stateLoading = state.loading;
const retry = React.useCallback(() => {
if (stateLoading)
return;
setAttempt((currentAttempt) => currentAttempt + 1);
}, [...deps, stateLoading]);
return { ...state, retry };
};

@@ -792,2 +837,5 @@ // src/dom.ts

transparentizeColor,
useAsync,
useAsyncFunc,
useAsyncRetry,
useCallbackRef,

@@ -794,0 +842,0 @@ useIsMounted,

import { Dict } from './index.types.js';
declare const omitObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
declare const pickObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => { [P in K]: T[P]; };
declare const splitObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
declare const filterObject: <T extends Dict<any>, K extends Dict<any>>(obj: T, func: (key: keyof T, value: T[keyof T], obj: T) => boolean) => K;
declare const filterUndefined: <T extends Dict<any>>(obj: T) => T;
declare const merge: <T extends Dict<any>>(target: any, source: any, overrideArray?: boolean) => T;
declare const flattenObject: <T extends Dict<any>>(obj: any, maxDepth?: number) => T;
declare const objectFromEntries: <T extends Dict<any>>(entries: any[][]) => T;
declare const keysFormObject: <T extends Dict<any>>(obj: T) => (keyof T)[];
declare const omitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
declare const pickObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => { [P in K]: T[P]; };
declare const splitObject: <T extends Dict, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
declare const filterObject: <T extends Dict, K extends Dict>(obj: T, func: (key: keyof T, value: T[keyof T], obj: T) => boolean) => K;
declare const filterUndefined: <T extends Dict>(obj: T) => T;
declare const merge: <T extends Dict>(target: any, source: any, overrideArray?: boolean) => T;
declare const flattenObject: <T extends Dict>(obj: any, maxDepth?: number) => T;
declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;

@@ -13,0 +13,0 @@ declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;

@@ -43,3 +43,53 @@ import * as React from 'react';

declare const useUpdateEffect: (callback: React.EffectCallback, deps: React.DependencyList) => void;
type FunctionReturningPromise = (...args: any[]) => Promise<any>;
declare const useAsync: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList) => StateFromFunctionReturningPromise<T>;
type AsyncState<T> = {
loading: boolean;
error?: undefined;
value?: undefined;
} | {
loading: true;
error?: Error | undefined;
value?: T;
} | {
loading: false;
error: Error;
value?: undefined;
} | {
loading: false;
error?: undefined;
value: T;
};
type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
StateFromFunctionReturningPromise<T>,
T
];
declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
type AsyncStateRetry<T> = AsyncState<T> & {
retry(): void;
};
declare const useAsyncRetry: <T>(func: () => Promise<T>, deps?: React.DependencyList) => {
retry: () => void;
loading: boolean;
error?: undefined;
value?: undefined;
} | {
retry: () => void;
loading: false;
error: Error;
value?: undefined;
} | {
retry: () => void;
loading: true;
error?: Error | undefined;
value?: T | undefined;
} | {
retry: () => void;
loading: false;
error?: undefined;
value: T;
};
export { DOMAttributes, MaybeRenderProp, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect };
export { AsyncFnReturn, AsyncState, AsyncStateRetry, DOMAttributes, FunctionReturningPromise, MaybeRenderProp, PromiseType, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useAsync, useAsyncFunc, useAsyncRetry, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect };

@@ -44,2 +44,5 @@ "use strict";

pickChildren: () => pickChildren,
useAsync: () => useAsync,
useAsyncFunc: () => useAsyncFunc,
useAsyncRetry: () => useAsyncRetry,
useCallbackRef: () => useCallbackRef,

@@ -158,2 +161,44 @@ useIsMounted: () => useIsMounted,

};
var useAsync = (func, deps = []) => {
const [state, callback] = useAsyncFunc(func, deps, { loading: true });
React.useEffect(() => {
callback();
}, [callback]);
return state;
};
var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
const lastCallId = React.useRef(0);
const isMounted = useIsMounted();
const [state, setState] = React.useState(initialState);
const callback = React.useCallback((...args) => {
const callId = ++lastCallId.current;
if (!state.loading) {
setState((prevState) => ({ ...prevState, loading: true }));
}
return func(...args).then(
(value) => {
if (isMounted.current && callId === lastCallId.current)
setState({ value, loading: false });
return value;
},
(error) => {
if (isMounted.current && callId === lastCallId.current)
setState({ error, loading: false });
return error;
}
);
}, deps);
return [state, callback];
};
var useAsyncRetry = (func, deps = []) => {
const [attempt, setAttempt] = React.useState(0);
const state = useAsync(func, [...deps, attempt]);
const stateLoading = state.loading;
const retry = React.useCallback(() => {
if (stateLoading)
return;
setAttempt((currentAttempt) => currentAttempt + 1);
}, [...deps, stateLoading]);
return { ...state, retry };
};
// Annotate the CommonJS export names for ESM import in node:

@@ -172,2 +217,5 @@ 0 && (module.exports = {

pickChildren,
useAsync,
useAsyncFunc,
useAsyncRetry,
useCallbackRef,

@@ -174,0 +222,0 @@ useIsMounted,

{
"name": "@yamada-ui/utils",
"version": "0.0.0-dev-20230606151107",
"version": "0.0.0-dev-20230714125059",
"description": "Yamada UI utils",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc