From e53ac429fa61680b47e11aa4b1682252b2f4705a Mon Sep 17 00:00:00 2001 From: saurabhdaware Date: Sat, 18 Nov 2023 18:00:07 +0530 Subject: [PATCH 1/5] reimplement lodash as custom utils --- .../components/Badge/getStyledBadgeStyles.ts | 2 +- .../components/Box/BaseBox/baseBoxStyles.ts | 4 +-- .../Box/BaseBox/getResponsiveValue.native.ts | 2 +- .../Box/BaseBox/getResponsiveValue.web.ts | 2 +- .../Button/BaseButton/BaseButton.tsx | 2 +- .../BaseButton/StyledBaseButton.native.tsx | 2 +- .../BaseButton/StyledBaseButton.web.tsx | 2 +- .../src/components/Carousel/Carousel.web.tsx | 6 ++-- .../src/components/Checkbox/Checkbox.tsx | 4 +-- .../Checkbox/CheckboxIcon/CheckboxIcon.tsx | 2 +- .../CheckboxIcon/CheckboxIconWrapperStyles.ts | 2 +- .../components/Chip/AnimatedChip.native.tsx | 2 +- .../src/components/Chip/AnimatedChip.web.tsx | 2 +- packages/blade/src/components/Chip/Chip.tsx | 2 +- .../Chip/StyledChipWrapper.native.tsx | 2 +- .../components/Chip/StyledChipWrapper.web.tsx | 2 +- .../components/Chip/getAnimatedChipStyles.ts | 2 +- .../blade/src/components/Chip/useChipGroup.ts | 2 +- .../Counter/getStyledCounterStyles.ts | 2 +- .../Form/Selector/SelectorInput.web.tsx | 2 +- .../Icons/useIconProps/useIconProps.tsx | 2 +- .../BaseDropdownInputTrigger.tsx | 2 +- .../components/Input/OTPInput/OTPInput.tsx | 2 +- .../components/Input/TextArea/TextArea.tsx | 2 +- .../components/Input/TextInput/TextInput.tsx | 2 +- .../src/components/Link/BaseLink/BaseLink.tsx | 2 +- .../Link/BaseLink/StyledBaseLink.web.tsx | 2 +- packages/blade/src/components/List/List.tsx | 2 +- .../blade/src/components/List/ListItem.tsx | 2 +- .../components/ProgressBar/ProgressBar.tsx | 2 +- .../ProgressBar/ProgressBarFilled.native.tsx | 2 +- .../ProgressBar/ProgressBarFilled.web.tsx | 2 +- packages/blade/src/components/Radio/Radio.tsx | 2 +- .../Radio/RadioGroup/useRadioGroup.ts | 2 +- .../components/Radio/RadioIcon/RadioIcon.tsx | 2 +- .../Radio/RadioIcon/RadioIconWrapperStyles.ts | 2 +- .../Spinner/BaseSpinner/BaseSpinner.tsx | 2 +- .../BaseSpinner/SpinningBox.native.tsx | 2 +- .../Spinner/BaseSpinner/SpinningBox.web.tsx | 2 +- .../Switch/AnimatedThumb.native.tsx | 4 +-- .../components/Switch/AnimatedThumb.web.tsx | 2 +- .../Switch/AnimatedThumbIcon.native.tsx | 2 +- .../Switch/AnimatedThumbIcon.web.tsx | 2 +- .../components/Switch/SwitchTrack.native.tsx | 2 +- .../blade/src/components/Switch/Thumb.tsx | 4 +-- .../blade/src/components/Switch/ThumbIcon.tsx | 4 +-- .../src/components/Switch/getTrackStyles.ts | 4 +-- .../src/components/Tabs/TabItem.native.tsx | 2 +- .../blade/src/components/Tabs/TabItem.web.tsx | 2 +- .../Typography/BaseText/getBaseTextStyles.ts | 2 +- .../ThemePlayground/ThemeSelector.tsx | 2 +- .../theme/__tests__/overrideTheme.test.ts | 2 +- .../blade/src/tokens/theme/overrideTheme.ts | 4 +-- .../getStringChildren/getStringChildren.ts | 2 +- .../hasSameObjectStructure.ts | 4 +-- .../isPartialMatchObjectKeys.ts | 2 +- .../blade/src/utils/lodashButBetter/clamp.ts | 5 +++ .../src/utils/lodashButBetter/cloneDeep.ts | 28 +++++++++++++++ .../src/utils/lodashButBetter/debounce.ts | 20 +++++++++++ .../blade/src/utils/lodashButBetter/get.ts | 16 +++++++++ .../src/utils/lodashButBetter/isEmpty.ts | 35 +++++++++++++++++++ .../src/utils/lodashButBetter/isNumber.ts | 6 ++++ .../src/utils/lodashButBetter/isObject.ts | 6 ++++ .../src/utils/lodashButBetter/isUndefined.ts | 4 +++ .../blade/src/utils/lodashButBetter/keys.ts | 6 ++++ .../blade/src/utils/lodashButBetter/merge.ts | 6 ++++ .../src/utils/lodashButBetter/throttle.ts | 28 +++++++++++++++ packages/examples/basic/package.json | 2 +- 68 files changed, 227 insertions(+), 67 deletions(-) create mode 100644 packages/blade/src/utils/lodashButBetter/clamp.ts create mode 100644 packages/blade/src/utils/lodashButBetter/cloneDeep.ts create mode 100644 packages/blade/src/utils/lodashButBetter/debounce.ts create mode 100644 packages/blade/src/utils/lodashButBetter/get.ts create mode 100644 packages/blade/src/utils/lodashButBetter/isEmpty.ts create mode 100644 packages/blade/src/utils/lodashButBetter/isNumber.ts create mode 100644 packages/blade/src/utils/lodashButBetter/isObject.ts create mode 100644 packages/blade/src/utils/lodashButBetter/isUndefined.ts create mode 100644 packages/blade/src/utils/lodashButBetter/keys.ts create mode 100644 packages/blade/src/utils/lodashButBetter/merge.ts create mode 100644 packages/blade/src/utils/lodashButBetter/throttle.ts diff --git a/packages/blade/src/components/Badge/getStyledBadgeStyles.ts b/packages/blade/src/components/Badge/getStyledBadgeStyles.ts index 9167e60b906..70043e65312 100644 --- a/packages/blade/src/components/Badge/getStyledBadgeStyles.ts +++ b/packages/blade/src/components/Badge/getStyledBadgeStyles.ts @@ -1,5 +1,5 @@ import type { CSSObject } from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { StyledBadgeProps } from './types'; import { makeBorderSize } from '~utils/makeBorderSize'; diff --git a/packages/blade/src/components/Box/BaseBox/baseBoxStyles.ts b/packages/blade/src/components/Box/BaseBox/baseBoxStyles.ts index fecc49875df..38b55d2a982 100644 --- a/packages/blade/src/components/Box/BaseBox/baseBoxStyles.ts +++ b/packages/blade/src/components/Box/BaseBox/baseBoxStyles.ts @@ -1,6 +1,5 @@ import type { CSSObject } from 'styled-components'; -import getIn from 'lodash/get'; -import isEmpty from 'lodash/isEmpty'; +import getIn from '~utils/lodashButBetter/get'; import type { BaseBoxProps, MakeValueResponsive, @@ -8,6 +7,7 @@ import type { ArrayOfMaxLength4, } from './types'; import { getResponsiveValue } from './getResponsiveValue'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { Breakpoints } from '~tokens/global'; import { breakpoints } from '~tokens/global'; import { isReactNative, getMediaQuery } from '~utils'; diff --git a/packages/blade/src/components/Box/BaseBox/getResponsiveValue.native.ts b/packages/blade/src/components/Box/BaseBox/getResponsiveValue.native.ts index 9ac71db935b..bff32a75409 100644 --- a/packages/blade/src/components/Box/BaseBox/getResponsiveValue.native.ts +++ b/packages/blade/src/components/Box/BaseBox/getResponsiveValue.native.ts @@ -1,4 +1,4 @@ -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import { Animated } from 'react-native'; import type { DimensionValue } from 'react-native'; import type { MakeValueResponsive } from './types'; diff --git a/packages/blade/src/components/Box/BaseBox/getResponsiveValue.web.ts b/packages/blade/src/components/Box/BaseBox/getResponsiveValue.web.ts index 2fc7050684d..6d79fc14440 100644 --- a/packages/blade/src/components/Box/BaseBox/getResponsiveValue.web.ts +++ b/packages/blade/src/components/Box/BaseBox/getResponsiveValue.web.ts @@ -1,4 +1,4 @@ -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { MakeValueResponsive } from './types'; import type { Breakpoints } from '~tokens/global'; diff --git a/packages/blade/src/components/Button/BaseButton/BaseButton.tsx b/packages/blade/src/components/Button/BaseButton/BaseButton.tsx index 6cec57f6a1f..49fcc969fba 100644 --- a/packages/blade/src/components/Button/BaseButton/BaseButton.tsx +++ b/packages/blade/src/components/Button/BaseButton/BaseButton.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import styled from 'styled-components'; import type { GestureResponderEvent } from 'react-native'; diff --git a/packages/blade/src/components/Button/BaseButton/StyledBaseButton.native.tsx b/packages/blade/src/components/Button/BaseButton/StyledBaseButton.native.tsx index f64dd1cdd78..befced03cf1 100644 --- a/packages/blade/src/components/Button/BaseButton/StyledBaseButton.native.tsx +++ b/packages/blade/src/components/Button/BaseButton/StyledBaseButton.native.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import { Linking, Pressable } from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'; import styled from 'styled-components/native'; diff --git a/packages/blade/src/components/Button/BaseButton/StyledBaseButton.web.tsx b/packages/blade/src/components/Button/BaseButton/StyledBaseButton.web.tsx index a5d6d959a0b..5d3c8a1e066 100644 --- a/packages/blade/src/components/Button/BaseButton/StyledBaseButton.web.tsx +++ b/packages/blade/src/components/Button/BaseButton/StyledBaseButton.web.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import styled from 'styled-components'; import getStyledBaseButtonStyles from './getStyledBaseButtonStyles'; import type { StyledBaseButtonProps } from './types'; diff --git a/packages/blade/src/components/Carousel/Carousel.web.tsx b/packages/blade/src/components/Carousel/Carousel.web.tsx index 4bf9539e6c3..62156117f11 100644 --- a/packages/blade/src/components/Carousel/Carousel.web.tsx +++ b/packages/blade/src/components/Carousel/Carousel.web.tsx @@ -6,9 +6,9 @@ import type { CSSObject } from 'styled-components'; import styled from 'styled-components'; import React from 'react'; -import getIn from 'lodash/get'; -import throttle from 'lodash/throttle'; -import debounce from 'lodash/debounce'; +import getIn from '~utils/lodashButBetter/get'; +import throttle from '~utils/lodashButBetter/throttle'; +import debounce from '~utils/lodashButBetter/debounce'; import { Indicators } from './Indicators/Indicators'; import { NavigationButton } from './NavigationButton'; import type { CarouselProps } from './types'; diff --git a/packages/blade/src/components/Checkbox/Checkbox.tsx b/packages/blade/src/components/Checkbox/Checkbox.tsx index be71914bc7b..4fc6b85d2b1 100644 --- a/packages/blade/src/components/Checkbox/Checkbox.tsx +++ b/packages/blade/src/components/Checkbox/Checkbox.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-shadow */ import React from 'react'; -import isUndefined from 'lodash/isUndefined'; -import isEmpty from 'lodash/isEmpty'; +import isUndefined from '~utils/lodashButBetter/isUndefined'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import { useCheckboxGroupContext } from './CheckboxGroup/CheckboxGroupContext'; import { CheckboxIcon } from './CheckboxIcon'; import { useCheckbox } from './useCheckbox'; diff --git a/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIcon.tsx b/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIcon.tsx index 479981a9399..51c49b0103f 100644 --- a/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIcon.tsx +++ b/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIcon.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import { CheckboxIconWrapper } from './CheckboxIconWrapper'; import { Fade } from './Fade'; diff --git a/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIconWrapperStyles.ts b/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIconWrapperStyles.ts index 75d6c1089eb..9f945c21aea 100644 --- a/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIconWrapperStyles.ts +++ b/packages/blade/src/components/Checkbox/CheckboxIcon/CheckboxIconWrapperStyles.ts @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import { checkboxIconColors, checkboxSizes } from '../checkboxTokens'; import type { CheckboxIconProps } from './CheckboxIcon'; diff --git a/packages/blade/src/components/Chip/AnimatedChip.native.tsx b/packages/blade/src/components/Chip/AnimatedChip.native.tsx index ec4fc011fd7..b48ff2d8c7f 100644 --- a/packages/blade/src/components/Chip/AnimatedChip.native.tsx +++ b/packages/blade/src/components/Chip/AnimatedChip.native.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import styled from 'styled-components/native'; import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'; diff --git a/packages/blade/src/components/Chip/AnimatedChip.web.tsx b/packages/blade/src/components/Chip/AnimatedChip.web.tsx index 0a4af1bc1da..b4ee5c26816 100644 --- a/packages/blade/src/components/Chip/AnimatedChip.web.tsx +++ b/packages/blade/src/components/Chip/AnimatedChip.web.tsx @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import { getAnimatedChipStyles } from './getAnimatedChipStyles'; import type { AnimatedChipProps } from './types'; import { chipMotionTokens } from './chipTokens'; diff --git a/packages/blade/src/components/Chip/Chip.tsx b/packages/blade/src/components/Chip/Chip.tsx index 3b5c0e5ac05..a4069e0152d 100644 --- a/packages/blade/src/components/Chip/Chip.tsx +++ b/packages/blade/src/components/Chip/Chip.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import { useChipGroupContext } from './ChipGroupContext'; import { chipIconSizes, diff --git a/packages/blade/src/components/Chip/StyledChipWrapper.native.tsx b/packages/blade/src/components/Chip/StyledChipWrapper.native.tsx index 039880b8e46..11a9cfddef9 100644 --- a/packages/blade/src/components/Chip/StyledChipWrapper.native.tsx +++ b/packages/blade/src/components/Chip/StyledChipWrapper.native.tsx @@ -1,5 +1,5 @@ import styled from 'styled-components/native'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { StyledChipWrapperProps } from './types'; import BaseBox from '~components/Box/BaseBox'; diff --git a/packages/blade/src/components/Chip/StyledChipWrapper.web.tsx b/packages/blade/src/components/Chip/StyledChipWrapper.web.tsx index 6d9a8c5f691..80726b0c516 100644 --- a/packages/blade/src/components/Chip/StyledChipWrapper.web.tsx +++ b/packages/blade/src/components/Chip/StyledChipWrapper.web.tsx @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { StyledChipWrapperProps } from './types'; import { chipMotionTokens, chipColorTokens } from './chipTokens'; import BaseBox from '~components/Box/BaseBox'; diff --git a/packages/blade/src/components/Chip/getAnimatedChipStyles.ts b/packages/blade/src/components/Chip/getAnimatedChipStyles.ts index 9afa8fd7f25..08f6add0a5c 100644 --- a/packages/blade/src/components/Chip/getAnimatedChipStyles.ts +++ b/packages/blade/src/components/Chip/getAnimatedChipStyles.ts @@ -1,5 +1,5 @@ import type { CSSObject } from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { AnimatedChipProps } from './types'; import { makeBorderSize } from '~utils/makeBorderSize'; diff --git a/packages/blade/src/components/Chip/useChipGroup.ts b/packages/blade/src/components/Chip/useChipGroup.ts index 9823766808d..e76d945477f 100644 --- a/packages/blade/src/components/Chip/useChipGroup.ts +++ b/packages/blade/src/components/Chip/useChipGroup.ts @@ -1,5 +1,5 @@ import React from 'react'; -import isUndefined from 'lodash/isUndefined'; +import isUndefined from '~utils/lodashButBetter/isUndefined'; import type { ChipGroupProps, ChipGroupContextType, State } from './types'; import { useControllableState } from '~utils/useControllable'; import { useId } from '~utils/useId'; diff --git a/packages/blade/src/components/Counter/getStyledCounterStyles.ts b/packages/blade/src/components/Counter/getStyledCounterStyles.ts index f310dba0bc4..10818921b22 100644 --- a/packages/blade/src/components/Counter/getStyledCounterStyles.ts +++ b/packages/blade/src/components/Counter/getStyledCounterStyles.ts @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import { maxWidth } from './counterTokens'; import type { StyledCounterProps } from './types'; diff --git a/packages/blade/src/components/Form/Selector/SelectorInput.web.tsx b/packages/blade/src/components/Form/Selector/SelectorInput.web.tsx index 35ebc5d9ded..a4e354ee18e 100644 --- a/packages/blade/src/components/Form/Selector/SelectorInput.web.tsx +++ b/packages/blade/src/components/Form/Selector/SelectorInput.web.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/ban-types */ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import React from 'react'; import styled from 'styled-components'; diff --git a/packages/blade/src/components/Icons/useIconProps/useIconProps.tsx b/packages/blade/src/components/Icons/useIconProps/useIconProps.tsx index fcfd246cd32..ca9fbd28b68 100644 --- a/packages/blade/src/components/Icons/useIconProps/useIconProps.tsx +++ b/packages/blade/src/components/Icons/useIconProps/useIconProps.tsx @@ -1,4 +1,4 @@ -import get from 'lodash/get'; +import get from '~utils/lodashButBetter/get'; import type { IconProps } from '..'; import { useTheme } from '~components/BladeProvider'; import { size } from '~tokens/global'; diff --git a/packages/blade/src/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.tsx b/packages/blade/src/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.tsx index cb9b313f7bc..aa12041a031 100644 --- a/packages/blade/src/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.tsx +++ b/packages/blade/src/components/Input/DropdownInputTriggers/BaseDropdownInputTrigger.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import { BaseInput } from '../BaseInput'; import { InputChevronIcon } from './InputChevronIcon'; import type { BaseDropdownInputTriggerProps } from './types'; diff --git a/packages/blade/src/components/Input/OTPInput/OTPInput.tsx b/packages/blade/src/components/Input/OTPInput/OTPInput.tsx index 13d45bdeba3..e03c130c25a 100644 --- a/packages/blade/src/components/Input/OTPInput/OTPInput.tsx +++ b/packages/blade/src/components/Input/OTPInput/OTPInput.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useImperativeHandle, useState } from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { BaseInputProps } from '../BaseInput'; import { BaseInput } from '../BaseInput'; import { getHintType } from '../BaseInput/BaseInput'; diff --git a/packages/blade/src/components/Input/TextArea/TextArea.tsx b/packages/blade/src/components/Input/TextArea/TextArea.tsx index 0b1b256d057..a53581c5d08 100644 --- a/packages/blade/src/components/Input/TextArea/TextArea.tsx +++ b/packages/blade/src/components/Input/TextArea/TextArea.tsx @@ -1,6 +1,6 @@ /* eslint-disable jsx-a11y/no-autofocus */ import React from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { TextInput as TextInputReactNative } from 'react-native'; import type { BaseInputProps } from '../BaseInput'; import { BaseInput } from '../BaseInput'; diff --git a/packages/blade/src/components/Input/TextInput/TextInput.tsx b/packages/blade/src/components/Input/TextInput/TextInput.tsx index f58ea2eceb7..79929b2dfea 100644 --- a/packages/blade/src/components/Input/TextInput/TextInput.tsx +++ b/packages/blade/src/components/Input/TextInput/TextInput.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { ReactElement, ReactNode } from 'react'; import type { TextInput as TextInputReactNative } from 'react-native'; import type { BaseInputProps } from '../BaseInput'; diff --git a/packages/blade/src/components/Link/BaseLink/BaseLink.tsx b/packages/blade/src/components/Link/BaseLink/BaseLink.tsx index 05cffab5c53..f0aa3bf6920 100644 --- a/packages/blade/src/components/Link/BaseLink/BaseLink.tsx +++ b/packages/blade/src/components/Link/BaseLink/BaseLink.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/prefer-ts-expect-error */ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { SyntheticEvent } from 'react'; import React, { useState } from 'react'; import type { CSSObject } from 'styled-components'; diff --git a/packages/blade/src/components/Link/BaseLink/StyledBaseLink.web.tsx b/packages/blade/src/components/Link/BaseLink/StyledBaseLink.web.tsx index 1acbd80e101..ed310340dd9 100644 --- a/packages/blade/src/components/Link/BaseLink/StyledBaseLink.web.tsx +++ b/packages/blade/src/components/Link/BaseLink/StyledBaseLink.web.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import styled from 'styled-components'; import getStyledLinkStyles from './getStyledLinkStyles'; import type { StyledBaseLinkProps } from './types'; diff --git a/packages/blade/src/components/List/List.tsx b/packages/blade/src/components/List/List.tsx index 39738c3c45f..87ba2bd4238 100644 --- a/packages/blade/src/components/List/List.tsx +++ b/packages/blade/src/components/List/List.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React, { useMemo } from 'react'; import styled from 'styled-components'; import { ListProvider, useListContext } from './ListContext'; diff --git a/packages/blade/src/components/List/ListItem.tsx b/packages/blade/src/components/List/ListItem.tsx index 375db5d42cf..96854d4601b 100644 --- a/packages/blade/src/components/List/ListItem.tsx +++ b/packages/blade/src/components/List/ListItem.tsx @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import { useListContext } from './ListContext'; import { UnorderedItemIcon } from './ListItemIcons'; diff --git a/packages/blade/src/components/ProgressBar/ProgressBar.tsx b/packages/blade/src/components/ProgressBar/ProgressBar.tsx index 4743570dac7..cf1ff92758b 100644 --- a/packages/blade/src/components/ProgressBar/ProgressBar.tsx +++ b/packages/blade/src/components/ProgressBar/ProgressBar.tsx @@ -1,5 +1,5 @@ import type { ReactElement } from 'react'; -import clamp from 'lodash/clamp'; +import clamp from '~utils/lodashButBetter/clamp'; import { ProgressBarFilled } from './ProgressBarFilled'; import { FormLabel } from '~components/Form'; import { metaAttribute, MetaConstants } from '~utils/metaAttribute'; diff --git a/packages/blade/src/components/ProgressBar/ProgressBarFilled.native.tsx b/packages/blade/src/components/ProgressBar/ProgressBarFilled.native.tsx index d63bbad992c..748dee90ff8 100644 --- a/packages/blade/src/components/ProgressBar/ProgressBarFilled.native.tsx +++ b/packages/blade/src/components/ProgressBar/ProgressBarFilled.native.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React, { useEffect } from 'react'; import styled from 'styled-components'; import Animated, { diff --git a/packages/blade/src/components/ProgressBar/ProgressBarFilled.web.tsx b/packages/blade/src/components/ProgressBar/ProgressBarFilled.web.tsx index 2038f1f98df..c3879b4b0d1 100644 --- a/packages/blade/src/components/ProgressBar/ProgressBarFilled.web.tsx +++ b/packages/blade/src/components/ProgressBar/ProgressBarFilled.web.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { FlattenSimpleInterpolation } from 'styled-components'; import styled, { css, keyframes } from 'styled-components'; import React from 'react'; diff --git a/packages/blade/src/components/Radio/Radio.tsx b/packages/blade/src/components/Radio/Radio.tsx index 9b7e688d866..1a3edd880e1 100644 --- a/packages/blade/src/components/Radio/Radio.tsx +++ b/packages/blade/src/components/Radio/Radio.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-shadow */ import React from 'react'; -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { OnChange } from './useRadio'; import { useRadio } from './useRadio'; import { RadioIcon } from './RadioIcon/RadioIcon'; diff --git a/packages/blade/src/components/Radio/RadioGroup/useRadioGroup.ts b/packages/blade/src/components/Radio/RadioGroup/useRadioGroup.ts index 9b2779683c4..e5bbb58d9c8 100644 --- a/packages/blade/src/components/Radio/RadioGroup/useRadioGroup.ts +++ b/packages/blade/src/components/Radio/RadioGroup/useRadioGroup.ts @@ -1,5 +1,5 @@ import React from 'react'; -import isUndefined from 'lodash/isUndefined'; +import isUndefined from '~utils/lodashButBetter/isUndefined'; import type { RadioGroupProps } from './RadioGroup'; import type { RadioGroupContextType } from './RadioContext'; import { useControllableState } from '~utils/useControllable'; diff --git a/packages/blade/src/components/Radio/RadioIcon/RadioIcon.tsx b/packages/blade/src/components/Radio/RadioIcon/RadioIcon.tsx index 94217df8a55..6e6d249405d 100644 --- a/packages/blade/src/components/Radio/RadioIcon/RadioIcon.tsx +++ b/packages/blade/src/components/Radio/RadioIcon/RadioIcon.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import { radioIconColors, radioSizes } from '../radioTokens'; import type { RadioProps } from '../Radio'; diff --git a/packages/blade/src/components/Radio/RadioIcon/RadioIconWrapperStyles.ts b/packages/blade/src/components/Radio/RadioIcon/RadioIconWrapperStyles.ts index c5262ff04ae..0049d7428a7 100644 --- a/packages/blade/src/components/Radio/RadioIcon/RadioIconWrapperStyles.ts +++ b/packages/blade/src/components/Radio/RadioIcon/RadioIconWrapperStyles.ts @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import { radioIconColors, radioSizes } from '../radioTokens'; import type { RadioIconProps } from './RadioIcon'; diff --git a/packages/blade/src/components/Spinner/BaseSpinner/BaseSpinner.tsx b/packages/blade/src/components/Spinner/BaseSpinner/BaseSpinner.tsx index 9c28eecd77a..2a983222ce3 100644 --- a/packages/blade/src/components/Spinner/BaseSpinner/BaseSpinner.tsx +++ b/packages/blade/src/components/Spinner/BaseSpinner/BaseSpinner.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import { dimensions } from './spinnerTokens'; import SpinnerIcon from './SpinnerIcon'; diff --git a/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.native.tsx b/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.native.tsx index 0331006dd43..76c6ba0f8d6 100644 --- a/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.native.tsx +++ b/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.native.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; import type { EasingFactoryFn } from 'react-native-reanimated'; import Animated, { diff --git a/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.web.tsx b/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.web.tsx index dd9dcb15851..bdb7edbd598 100644 --- a/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.web.tsx +++ b/packages/blade/src/components/Spinner/BaseSpinner/SpinningBox.web.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import styled, { css, keyframes } from 'styled-components'; import { motion as spinnerMotion } from './spinnerTokens'; import BaseBox from '~components/Box/BaseBox'; diff --git a/packages/blade/src/components/Switch/AnimatedThumb.native.tsx b/packages/blade/src/components/Switch/AnimatedThumb.native.tsx index c07bacc941b..525756df65e 100644 --- a/packages/blade/src/components/Switch/AnimatedThumb.native.tsx +++ b/packages/blade/src/components/Switch/AnimatedThumb.native.tsx @@ -1,8 +1,8 @@ /* eslint-disable react-hooks/exhaustive-deps */ import styled from 'styled-components/native'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import React from 'react'; -import isNumber from 'lodash/isNumber'; +import isNumber from '~utils/lodashButBetter/isNumber'; import Animated, { interpolate, useAnimatedStyle, diff --git a/packages/blade/src/components/Switch/AnimatedThumb.web.tsx b/packages/blade/src/components/Switch/AnimatedThumb.web.tsx index 1af027316c5..f7fff5bc06d 100644 --- a/packages/blade/src/components/Switch/AnimatedThumb.web.tsx +++ b/packages/blade/src/components/Switch/AnimatedThumb.web.tsx @@ -1,5 +1,5 @@ import styled, { css } from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import { switchColors, switchMotion } from './switchTokens'; import type { AnimatedThumbProps } from './types'; import { BaseBox } from '~components/Box/BaseBox'; diff --git a/packages/blade/src/components/Switch/AnimatedThumbIcon.native.tsx b/packages/blade/src/components/Switch/AnimatedThumbIcon.native.tsx index 8a815012d0d..7b4fd5b43e0 100644 --- a/packages/blade/src/components/Switch/AnimatedThumbIcon.native.tsx +++ b/packages/blade/src/components/Switch/AnimatedThumbIcon.native.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import Animated, { interpolate, useAnimatedStyle, diff --git a/packages/blade/src/components/Switch/AnimatedThumbIcon.web.tsx b/packages/blade/src/components/Switch/AnimatedThumbIcon.web.tsx index 44693b2f202..ddd18639779 100644 --- a/packages/blade/src/components/Switch/AnimatedThumbIcon.web.tsx +++ b/packages/blade/src/components/Switch/AnimatedThumbIcon.web.tsx @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import styled from 'styled-components'; import { switchMotion } from './switchTokens'; import Svg from '~components/Icons/_Svg'; diff --git a/packages/blade/src/components/Switch/SwitchTrack.native.tsx b/packages/blade/src/components/Switch/SwitchTrack.native.tsx index fa040986af6..c35db0f21ec 100644 --- a/packages/blade/src/components/Switch/SwitchTrack.native.tsx +++ b/packages/blade/src/components/Switch/SwitchTrack.native.tsx @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import Animated, { interpolateColor, useAnimatedStyle, diff --git a/packages/blade/src/components/Switch/Thumb.tsx b/packages/blade/src/components/Switch/Thumb.tsx index 002f0f2eeee..ccf68332255 100644 --- a/packages/blade/src/components/Switch/Thumb.tsx +++ b/packages/blade/src/components/Switch/Thumb.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -import isNumber from 'lodash/isNumber'; -import getIn from 'lodash/get'; +import isNumber from '~utils/lodashButBetter/isNumber'; +import getIn from '~utils/lodashButBetter/get'; import styled from 'styled-components'; import type { ThumbProps } from './types'; import { switchSizes } from './switchTokens'; diff --git a/packages/blade/src/components/Switch/ThumbIcon.tsx b/packages/blade/src/components/Switch/ThumbIcon.tsx index d7b52db8581..cce745f6efa 100644 --- a/packages/blade/src/components/Switch/ThumbIcon.tsx +++ b/packages/blade/src/components/Switch/ThumbIcon.tsx @@ -1,5 +1,5 @@ -import isNumber from 'lodash/isNumber'; -import getIn from 'lodash/get'; +import isNumber from '~utils/lodashButBetter/isNumber'; +import getIn from '~utils/lodashButBetter/get'; import type { SwitchProps } from './types'; import { AnimatedThumbIcon } from './AnimatedThumbIcon'; import { switchColors } from './switchTokens'; diff --git a/packages/blade/src/components/Switch/getTrackStyles.ts b/packages/blade/src/components/Switch/getTrackStyles.ts index 561f30488d9..e37558e5a6a 100644 --- a/packages/blade/src/components/Switch/getTrackStyles.ts +++ b/packages/blade/src/components/Switch/getTrackStyles.ts @@ -1,5 +1,5 @@ -import isNumber from 'lodash/isNumber'; -import getIn from 'lodash/get'; +import isNumber from '~utils/lodashButBetter/isNumber'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import type { TrackProps } from './types'; import { switchColors, switchSizes } from './switchTokens'; diff --git a/packages/blade/src/components/Tabs/TabItem.native.tsx b/packages/blade/src/components/Tabs/TabItem.native.tsx index 3e6ac0de7f7..082e522fef1 100644 --- a/packages/blade/src/components/Tabs/TabItem.native.tsx +++ b/packages/blade/src/components/Tabs/TabItem.native.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ import styled from 'styled-components'; -import get from 'lodash/get'; +import get from '~utils/lodashButBetter/get'; import React from 'react'; import type { TabItemProps, TabsProps } from './types'; import { paddingX, paddingY } from './tabTokens'; diff --git a/packages/blade/src/components/Tabs/TabItem.web.tsx b/packages/blade/src/components/Tabs/TabItem.web.tsx index cc646b16f91..608a9f4e813 100644 --- a/packages/blade/src/components/Tabs/TabItem.web.tsx +++ b/packages/blade/src/components/Tabs/TabItem.web.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */ import styled from 'styled-components'; -import get from 'lodash/get'; +import get from '~utils/lodashButBetter/get'; import React from 'react'; import { CompositeItem } from '@floating-ui/react'; import type { TabItemProps, TabsProps } from './types'; diff --git a/packages/blade/src/components/Typography/BaseText/getBaseTextStyles.ts b/packages/blade/src/components/Typography/BaseText/getBaseTextStyles.ts index 20fd25d5975..2e59af57a5e 100644 --- a/packages/blade/src/components/Typography/BaseText/getBaseTextStyles.ts +++ b/packages/blade/src/components/Typography/BaseText/getBaseTextStyles.ts @@ -1,4 +1,4 @@ -import getIn from 'lodash/get'; +import getIn from '~utils/lodashButBetter/get'; import type { CSSObject } from 'styled-components'; import type { StyledBaseTextProps } from './types'; import { makeTypographySize } from '~utils/makeTypographySize'; diff --git a/packages/blade/src/storybook-recipes/ThemePlayground/ThemeSelector.tsx b/packages/blade/src/storybook-recipes/ThemePlayground/ThemeSelector.tsx index a9951cb74b5..f0ca720d659 100644 --- a/packages/blade/src/storybook-recipes/ThemePlayground/ThemeSelector.tsx +++ b/packages/blade/src/storybook-recipes/ThemePlayground/ThemeSelector.tsx @@ -1,4 +1,4 @@ -import debounce from 'lodash/debounce'; +import debounce from '~utils/lodashButBetter/debounce'; import { useEffect } from 'react'; import styled from 'styled-components'; import { Box } from '~components/Box'; diff --git a/packages/blade/src/tokens/theme/__tests__/overrideTheme.test.ts b/packages/blade/src/tokens/theme/__tests__/overrideTheme.test.ts index bf7a777bb82..3db69b4291b 100644 --- a/packages/blade/src/tokens/theme/__tests__/overrideTheme.test.ts +++ b/packages/blade/src/tokens/theme/__tests__/overrideTheme.test.ts @@ -1,4 +1,4 @@ -import cloneDeep from 'lodash/cloneDeep'; +import cloneDeep from '~utils/lodashButBetter/cloneDeep'; import overrideTheme from '../overrideTheme'; import { paymentTheme, bankingTheme } from '../'; import type { ThemeTokens } from '../../theme'; diff --git a/packages/blade/src/tokens/theme/overrideTheme.ts b/packages/blade/src/tokens/theme/overrideTheme.ts index 6b6a02a7b5b..39ec524a0cd 100644 --- a/packages/blade/src/tokens/theme/overrideTheme.ts +++ b/packages/blade/src/tokens/theme/overrideTheme.ts @@ -1,5 +1,5 @@ -import cloneDeep from 'lodash/cloneDeep'; -import merge from 'lodash/merge'; +import cloneDeep from '~utils/lodashButBetter/cloneDeep'; +import merge from '~utils/lodashButBetter/merge'; import paymentTheme from './paymentTheme'; import type { ThemeTokens } from './theme'; import { hasSameObjectStructure } from '~utils/hasSameObjectStructure'; diff --git a/packages/blade/src/utils/getStringChildren/getStringChildren.ts b/packages/blade/src/utils/getStringChildren/getStringChildren.ts index da087eeada3..1bfd1865c5b 100644 --- a/packages/blade/src/utils/getStringChildren/getStringChildren.ts +++ b/packages/blade/src/utils/getStringChildren/getStringChildren.ts @@ -1,4 +1,4 @@ -import isEmpty from 'lodash/isEmpty'; +import isEmpty from '~utils/lodashButBetter/isEmpty'; import type { StringChildrenType } from '~utils/types'; const getStringFromReactText = ( diff --git a/packages/blade/src/utils/hasSameObjectStructure/hasSameObjectStructure.ts b/packages/blade/src/utils/hasSameObjectStructure/hasSameObjectStructure.ts index 56c401b4ef5..51a7ab7c2d1 100644 --- a/packages/blade/src/utils/hasSameObjectStructure/hasSameObjectStructure.ts +++ b/packages/blade/src/utils/hasSameObjectStructure/hasSameObjectStructure.ts @@ -1,5 +1,5 @@ -import isObject from 'lodash/isObject'; -import keys from 'lodash/keys'; +import isObject from '~utils/lodashButBetter/isObject'; +import keys from '~utils/lodashButBetter/keys'; export interface ObjectWithKeys { [key: string | number]: ObjectWithKeys | number | string; diff --git a/packages/blade/src/utils/isPartialMatchObjectKeys/isPartialMatchObjectKeys.ts b/packages/blade/src/utils/isPartialMatchObjectKeys/isPartialMatchObjectKeys.ts index d8b0107eebf..20e4ead8017 100644 --- a/packages/blade/src/utils/isPartialMatchObjectKeys/isPartialMatchObjectKeys.ts +++ b/packages/blade/src/utils/isPartialMatchObjectKeys/isPartialMatchObjectKeys.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import isObject from 'lodash/isObject'; +import isObject from '~utils/lodashButBetter/isObject'; import { logger } from '~utils/logger'; export type DeepPartial = { diff --git a/packages/blade/src/utils/lodashButBetter/clamp.ts b/packages/blade/src/utils/lodashButBetter/clamp.ts new file mode 100644 index 00000000000..fa4eb79c9ae --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/clamp.ts @@ -0,0 +1,5 @@ +function clamp(number: number, lower: number, upper: number): number { + return Math.min(Math.max(number, lower), upper); +} + +export default clamp; diff --git a/packages/blade/src/utils/lodashButBetter/cloneDeep.ts b/packages/blade/src/utils/lodashButBetter/cloneDeep.ts new file mode 100644 index 00000000000..88abcb34875 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/cloneDeep.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function cloneDeep(source: T): T { + if (source === null || typeof source !== 'object') { + return source; + } + + if (Array.isArray(source)) { + const newArray: any[] = []; + for (const item of source) { + newArray.push(cloneDeep(item)); + } + return newArray as T; + } + + if (typeof source === 'object') { + const newObject: Record = {}; + for (const key in source) { + if (source.hasOwnProperty(key)) { + newObject[key] = cloneDeep(source[key]); + } + } + return newObject as T; + } + + return source; +} + +export default cloneDeep; diff --git a/packages/blade/src/utils/lodashButBetter/debounce.ts b/packages/blade/src/utils/lodashButBetter/debounce.ts new file mode 100644 index 00000000000..c30ff189114 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/debounce.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +function debounce(func: (...args: any[]) => void, wait: number): (...args: any[]) => void { + let timeoutId: NodeJS.Timeout | null; + + function wrapper(...args: any[]) { + if (timeoutId) { + clearTimeout(timeoutId); + } + + timeoutId = setTimeout(() => { + func(...args); + timeoutId = null; + }, wait); + } + + return wrapper; +} + +export default debounce; diff --git a/packages/blade/src/utils/lodashButBetter/get.ts b/packages/blade/src/utils/lodashButBetter/get.ts new file mode 100644 index 00000000000..2c1bca38a62 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/get.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function getIn(obj: Record, path: string, defaultValue?: any): any { + const keys = path.split('.'); + let result = obj; + + for (const key of keys) { + result = result?.[key]; + if (result === undefined) { + return defaultValue; + } + } + + return result !== undefined ? result : defaultValue; +} + +export default getIn; diff --git a/packages/blade/src/utils/lodashButBetter/isEmpty.ts b/packages/blade/src/utils/lodashButBetter/isEmpty.ts new file mode 100644 index 00000000000..16009261839 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/isEmpty.ts @@ -0,0 +1,35 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +type Collection = + | Record + | any[] + | Set + | Map + | string + | null + | undefined; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export default function isEmpty(value: Collection): boolean { + // Check if the value is null or undefined + if (value == null) { + return true; + } + + // Check if the value is an object and has no own enumerable properties + if (typeof value === 'object' && Object.keys(value).length === 0) { + return true; + } + + // Check if the value is a string and has zero length + if (typeof value === 'string' && value.length === 0) { + return true; + } + + // Check if the value is a collection, map, or set and has zero size + if (value instanceof Map || value instanceof Set || Array.isArray(value)) { + // @ts-expect-error + return value.length === 0; + } + + return false; +} diff --git a/packages/blade/src/utils/lodashButBetter/isNumber.ts b/packages/blade/src/utils/lodashButBetter/isNumber.ts new file mode 100644 index 00000000000..72c1537472e --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/isNumber.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function isNumber(value: any): value is number { + return typeof value === 'number' && isFinite(value); +} + +export default isNumber; diff --git a/packages/blade/src/utils/lodashButBetter/isObject.ts b/packages/blade/src/utils/lodashButBetter/isObject.ts new file mode 100644 index 00000000000..78503e305c8 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/isObject.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function isObject(value: any): value is Record { + return typeof value === 'object' && value !== null; +} + +export default isObject; diff --git a/packages/blade/src/utils/lodashButBetter/isUndefined.ts b/packages/blade/src/utils/lodashButBetter/isUndefined.ts new file mode 100644 index 00000000000..7ba67e1ba8f --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/isUndefined.ts @@ -0,0 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +export default function isUndefined(value: any): boolean { + return typeof value === 'undefined'; +} diff --git a/packages/blade/src/utils/lodashButBetter/keys.ts b/packages/blade/src/utils/lodashButBetter/keys.ts new file mode 100644 index 00000000000..1f6485cfde9 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/keys.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function keys>(obj: T): Array { + return Object.keys(obj) as Array; +} + +export default keys; diff --git a/packages/blade/src/utils/lodashButBetter/merge.ts b/packages/blade/src/utils/lodashButBetter/merge.ts new file mode 100644 index 00000000000..4259b6a5cd1 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/merge.ts @@ -0,0 +1,6 @@ +/* eslint-disable prefer-object-spread */ +function merge(target: T, source: U): T & U { + return Object.assign({}, target, source); +} + +export default merge; diff --git a/packages/blade/src/utils/lodashButBetter/throttle.ts b/packages/blade/src/utils/lodashButBetter/throttle.ts new file mode 100644 index 00000000000..b58130f6b53 --- /dev/null +++ b/packages/blade/src/utils/lodashButBetter/throttle.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +function throttle(func: (...args: any[]) => void, wait: number): (...args: any[]) => void { + let isThrottled = false; + let lastArgs: any[] | null = null; + + function wrapper(...args: any[]) { + if (isThrottled) { + lastArgs = args; + return; + } + + func(...args); + isThrottled = true; + + setTimeout(() => { + isThrottled = false; + if (lastArgs) { + wrapper(...lastArgs); + lastArgs = null; + } + }, wait); + } + + return wrapper; +} + +export default throttle; diff --git a/packages/examples/basic/package.json b/packages/examples/basic/package.json index 9634e2555ae..6b4926bd6f7 100644 --- a/packages/examples/basic/package.json +++ b/packages/examples/basic/package.json @@ -2,7 +2,7 @@ "private": "true", "scripts": { "start": "DISABLE_ESLINT_PLUGIN=true react-scripts start", - "build": "yarn build && yarn build:app", + "build": "yarn build:blade && yarn build:app", "build:blade": "cd ../../blade && yarn build", "build:app": "DISABLE_ESLINT_PLUGIN=true react-scripts build", "analyze:only": "source-map-explorer 'build/static/js/*.js' --gzip", From 3d00f1907908b771c98e6e2bdc462bb11d105d29 Mon Sep 17 00:00:00 2001 From: saurabhdaware Date: Sat, 18 Nov 2023 18:02:38 +0530 Subject: [PATCH 2/5] fix: build error --- packages/blade/src/utils/lodashButBetter/isEmpty.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/blade/src/utils/lodashButBetter/isEmpty.ts b/packages/blade/src/utils/lodashButBetter/isEmpty.ts index 16009261839..db19477076b 100644 --- a/packages/blade/src/utils/lodashButBetter/isEmpty.ts +++ b/packages/blade/src/utils/lodashButBetter/isEmpty.ts @@ -5,6 +5,7 @@ type Collection = | Set | Map | string + | number | null | undefined; From 734f218c615aedf17ef37014308d550b6953f2f5 Mon Sep 17 00:00:00 2001 From: saurabhdaware Date: Sun, 19 Nov 2023 13:37:08 +0530 Subject: [PATCH 3/5] fix: isEmpty implementation --- packages/blade/src/utils/lodashButBetter/isEmpty.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/blade/src/utils/lodashButBetter/isEmpty.ts b/packages/blade/src/utils/lodashButBetter/isEmpty.ts index db19477076b..6b23b3e33e7 100644 --- a/packages/blade/src/utils/lodashButBetter/isEmpty.ts +++ b/packages/blade/src/utils/lodashButBetter/isEmpty.ts @@ -6,6 +6,7 @@ type Collection = | Map | string | number + | boolean | null | undefined; @@ -26,6 +27,11 @@ export default function isEmpty(value: Collection): boolean { return true; } + // https://github.com/lodash/lodash/issues/496#issuecomment-37692727 + if (typeof value === 'number' || typeof value === 'boolean') { + return true; + } + // Check if the value is a collection, map, or set and has zero size if (value instanceof Map || value instanceof Set || Array.isArray(value)) { // @ts-expect-error From 4b68e60378ddaca1278c762f7f2252649699e74e Mon Sep 17 00:00:00 2001 From: saurabhdaware Date: Sun, 19 Nov 2023 13:50:24 +0530 Subject: [PATCH 4/5] fix: get function --- packages/blade/src/utils/lodashButBetter/get.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/blade/src/utils/lodashButBetter/get.ts b/packages/blade/src/utils/lodashButBetter/get.ts index 2c1bca38a62..bf95c1f477a 100644 --- a/packages/blade/src/utils/lodashButBetter/get.ts +++ b/packages/blade/src/utils/lodashButBetter/get.ts @@ -1,16 +1,20 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -function getIn(obj: Record, path: string, defaultValue?: any): any { +function getIn(obj: Record, path: string): any { + if (!path) { + return undefined; + } + const keys = path.split('.'); let result = obj; for (const key of keys) { result = result?.[key]; if (result === undefined) { - return defaultValue; + return undefined; } } - return result !== undefined ? result : defaultValue; + return result; } export default getIn; From ffedda30c22a27da82668eec03e8b61b3d2bb101 Mon Sep 17 00:00:00 2001 From: saurabhdaware Date: Sun, 19 Nov 2023 13:58:21 +0530 Subject: [PATCH 5/5] fix: broken types --- packages/blade/src/utils/lodashButBetter/get.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/blade/src/utils/lodashButBetter/get.ts b/packages/blade/src/utils/lodashButBetter/get.ts index bf95c1f477a..09502e6a5a4 100644 --- a/packages/blade/src/utils/lodashButBetter/get.ts +++ b/packages/blade/src/utils/lodashButBetter/get.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -function getIn(obj: Record, path: string): any { +function getIn(obj: Record, path: string, defaultValue?: any): any { if (!path) { - return undefined; + return defaultValue; } const keys = path.split('.'); @@ -10,11 +10,11 @@ function getIn(obj: Record, path: string): any { for (const key of keys) { result = result?.[key]; if (result === undefined) { - return undefined; + return defaultValue; } } - return result; + return result !== undefined ? result : defaultValue; } export default getIn;