diff --git a/README.md b/README.md index 4720713e..3d2da009 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,6 @@ npm run test ```bash ๐Ÿ“‚ ./src โ”œโ”€โ”€ ๐Ÿ“‚ useHookName -โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ index.ts # used for exports โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ useHookName.demo.tsx # working demo โ”‚ โ”œโ”€โ”€ ๐Ÿ“ useHookName.mdx # the documentation content โ”‚ โ”œโ”€โ”€ ๐Ÿงช useHookName.test.ts # unit tests diff --git a/plopfile.js b/plopfile.js index d48df30c..9bdcd11c 100644 --- a/plopfile.js +++ b/plopfile.js @@ -11,13 +11,6 @@ module.exports = function (plop) { }, ], actions: [ - // Create the hook index file (for quick export) - { - type: 'add', - path: 'src/{{camelCase name}}/index.ts', - templateFile: 'templates/plop/hooks/hook/index.ts.hbs', - }, - // Create the hook file itself { type: 'add', diff --git a/scripts/copyHooks.ts b/scripts/copyHooks.ts index 96fbc40a..ca3a9ffb 100644 --- a/scripts/copyHooks.ts +++ b/scripts/copyHooks.ts @@ -101,10 +101,14 @@ function copyFile({ source, dest, useSandbox, toMarkdown }: CopyFileProps) { if (toMarkdown) { // rename import from "from '..'" to "from 'usehooks-ts'" - const re = new RegExp("^import { (use[A-Z][a-zA-Z]*..)+ } from '..'$") + const regex = new RegExp("from '..'$") + const transform = (line: string) => { - return line.replace(re, match => match.replace('..', 'usehooks-ts')) + return regex.test(line) + ? line.replace("from '..'", "from 'usehooks-ts'") + : line } + data = data.split('\n').map(transform).join('\n') // wrap code into markdown code tags diff --git a/src/index.ts b/src/index.ts index 26d25667..c94fdb4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,35 +1,70 @@ -export * from './useBoolean' -export * from './useClickAnyWhere' -export * from './useCopyToClipboard' -export * from './useCountdown' -export * from './useCounter' -export * from './useDarkMode' -export * from './useDebounce' -export * from './useEffectOnce' -export * from './useElementSize' -export * from './useEventCallback' -export * from './useEventListener' -export * from './useFetch' -export * from './useHover' -export * from './useImageOnLoad' -export * from './useIntersectionObserver' -export * from './useInterval' -export * from './useIsClient' -export * from './useIsFirstRender' -export * from './useIsMounted' -export * from './useIsomorphicLayoutEffect' -export * from './useLocalStorage' -export * from './useLockedBody' -export * from './useMap' -export * from './useMediaQuery' -export * from './useOnClickOutside' -export * from './useReadLocalStorage' -export * from './useScreen' -export * from './useScript' -export * from './useSessionStorage' -export * from './useSsr' -export * from './useStep' -export * from './useTernaryDarkMode' -export * from './useTimeout' -export * from './useUpdateEffect' -export * from './useWindowSize' +export { default as useBoolean } from './useBoolean/useBoolean' +export * from './useBoolean/useBoolean' +export { default as useClickAnyWhere } from './useClickAnyWhere/useClickAnyWhere' +export * from './useClickAnyWhere/useClickAnyWhere' +export { default as useCopyToClipboard } from './useCopyToClipboard/useCopyToClipboard' +export * from './useCopyToClipboard/useCopyToClipboard' +export { default as useCountdown } from './useCountdown/useCountdown' +export * from './useCountdown/useCountdown' +export { default as useCounter } from './useCounter/useCounter' +export * from './useCounter/useCounter' +export { default as useDarkMode } from './useDarkMode/useDarkMode' +export * from './useDarkMode/useDarkMode' +export { default as useDebounce } from './useDebounce/useDebounce' +export * from './useDebounce/useDebounce' +export { default as useEffectOnce } from './useEffectOnce/useEffectOnce' +export * from './useEffectOnce/useEffectOnce' +export { default as useElementSize } from './useElementSize/useElementSize' +export * from './useElementSize/useElementSize' +export { default as useEventCallback } from './useEventCallback/useEventCallback' +export * from './useEventCallback/useEventCallback' +export { default as useEventListener } from './useEventListener/useEventListener' +export * from './useEventListener/useEventListener' +export { default as useFetch } from './useFetch/useFetch' +export * from './useFetch/useFetch' +export { default as useHover } from './useHover/useHover' +export * from './useHover/useHover' +export { default as useImageOnLoad } from './useImageOnLoad/useImageOnLoad' +export * from './useImageOnLoad/useImageOnLoad' +export { default as useIntersectionObserver } from './useIntersectionObserver/useIntersectionObserver' +export * from './useIntersectionObserver/useIntersectionObserver' +export { default as useInterval } from './useInterval/useInterval' +export * from './useInterval/useInterval' +export { default as useIsClient } from './useIsClient/useIsClient' +export * from './useIsClient/useIsClient' +export { default as useIsFirstRender } from './useIsFirstRender/useIsFirstRender' +export * from './useIsFirstRender/useIsFirstRender' +export { default as useIsMounted } from './useIsMounted/useIsMounted' +export * from './useIsMounted/useIsMounted' +export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect' +export * from './useIsomorphicLayoutEffect/useIsomorphicLayoutEffect' +export { default as useLocalStorage } from './useLocalStorage/useLocalStorage' +export * from './useLocalStorage/useLocalStorage' +export { default as useLockedBody } from './useLockedBody/useLockedBody' +export * from './useLockedBody/useLockedBody' +export { default as useMap } from './useMap/useMap' +export * from './useMap/useMap' +export { default as useMediaQuery } from './useMediaQuery/useMediaQuery' +export * from './useMediaQuery/useMediaQuery' +export { default as useOnClickOutside } from './useOnClickOutside/useOnClickOutside' +export * from './useOnClickOutside/useOnClickOutside' +export { default as useReadLocalStorage } from './useReadLocalStorage/useReadLocalStorage' +export * from './useReadLocalStorage/useReadLocalStorage' +export { default as useScreen } from './useScreen/useScreen' +export * from './useScreen/useScreen' +export { default as useScript } from './useScript/useScript' +export * from './useScript/useScript' +export { default as useSessionStorage } from './useSessionStorage/useSessionStorage' +export * from './useSessionStorage/useSessionStorage' +export { default as useSsr } from './useSsr/useSsr' +export * from './useSsr/useSsr' +export { default as useStep } from './useStep/useStep' +export * from './useStep/useStep' +export { default as useTernaryDarkMode } from './useTernaryDarkMode/useTernaryDarkMode' +export * from './useTernaryDarkMode/useTernaryDarkMode' +export { default as useTimeout } from './useTimeout/useTimeout' +export * from './useTimeout/useTimeout' +export { default as useUpdateEffect } from './useUpdateEffect/useUpdateEffect' +export * from './useUpdateEffect/useUpdateEffect' +export { default as useWindowSize } from './useWindowSize/useWindowSize' +export * from './useWindowSize/useWindowSize' diff --git a/src/useBoolean/index.ts b/src/useBoolean/index.ts deleted file mode 100644 index a7e4df90..00000000 --- a/src/useBoolean/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useBoolean } from './useBoolean' -export * from './useBoolean' diff --git a/src/useClickAnyWhere/index.ts b/src/useClickAnyWhere/index.ts deleted file mode 100644 index 62cb5aae..00000000 --- a/src/useClickAnyWhere/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useClickAnyWhere } from './useClickAnyWhere' -export * from './useClickAnyWhere' diff --git a/src/useCopyToClipboard/index.ts b/src/useCopyToClipboard/index.ts deleted file mode 100644 index 2e61f909..00000000 --- a/src/useCopyToClipboard/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useCopyToClipboard } from './useCopyToClipboard' -export * from './useCopyToClipboard' diff --git a/src/useCountdown/index.ts b/src/useCountdown/index.ts deleted file mode 100644 index 4e3d6798..00000000 --- a/src/useCountdown/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useCountdown } from './useCountdown' -export * from './useCountdown' diff --git a/src/useCounter/index.ts b/src/useCounter/index.ts deleted file mode 100644 index 90133f15..00000000 --- a/src/useCounter/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useCounter } from './useCounter' -export * from './useCounter' diff --git a/src/useDarkMode/index.ts b/src/useDarkMode/index.ts deleted file mode 100644 index 5d424f5b..00000000 --- a/src/useDarkMode/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useDarkMode } from './useDarkMode' -export * from './useDarkMode' diff --git a/src/useDebounce/index.ts b/src/useDebounce/index.ts deleted file mode 100644 index aaa97fce..00000000 --- a/src/useDebounce/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useDebounce } from './useDebounce' -export * from './useDebounce' diff --git a/src/useEffectOnce/index.ts b/src/useEffectOnce/index.ts deleted file mode 100644 index b59b98f6..00000000 --- a/src/useEffectOnce/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useEffectOnce } from './useEffectOnce' -export * from './useEffectOnce' diff --git a/src/useElementSize/index.ts b/src/useElementSize/index.ts deleted file mode 100644 index e3def90f..00000000 --- a/src/useElementSize/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useElementSize } from './useElementSize' -export * from './useElementSize' diff --git a/src/useElementSize/useElementSize.test.ts b/src/useElementSize/useElementSize.test.ts index ce3f14a2..9a0f5916 100644 --- a/src/useElementSize/useElementSize.test.ts +++ b/src/useElementSize/useElementSize.test.ts @@ -1,6 +1,6 @@ import { act, renderHook } from '@testing-library/react-hooks' -import { useElementSize } from '.' +import { useElementSize } from '..' const setupHook = () => renderHook(() => useElementSize()) diff --git a/src/useEventCallback/index.ts b/src/useEventCallback/index.ts deleted file mode 100644 index 943b09e8..00000000 --- a/src/useEventCallback/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as useEventCallback } from './useEventCallback' diff --git a/src/useEventListener/index.ts b/src/useEventListener/index.ts deleted file mode 100644 index d4482e93..00000000 --- a/src/useEventListener/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useEventListener } from './useEventListener' -export * from './useEventListener' diff --git a/src/useFetch/index.ts b/src/useFetch/index.ts deleted file mode 100644 index 4b84b810..00000000 --- a/src/useFetch/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useFetch } from './useFetch' -export * from './useFetch' diff --git a/src/useHover/index.ts b/src/useHover/index.ts deleted file mode 100644 index d8fdad0c..00000000 --- a/src/useHover/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useHover } from './useHover' -export * from './useHover' diff --git a/src/useImageOnLoad/index.ts b/src/useImageOnLoad/index.ts deleted file mode 100644 index 2812965e..00000000 --- a/src/useImageOnLoad/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useImageOnLoad } from './useImageOnLoad' -export * from './useImageOnLoad' diff --git a/src/useIntersectionObserver/index.ts b/src/useIntersectionObserver/index.ts deleted file mode 100644 index 3f06b79c..00000000 --- a/src/useIntersectionObserver/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useIntersectionObserver } from './useIntersectionObserver' -export * from './useIntersectionObserver' diff --git a/src/useInterval/index.ts b/src/useInterval/index.ts deleted file mode 100644 index 1754aafd..00000000 --- a/src/useInterval/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useInterval } from './useInterval' -export * from './useInterval' diff --git a/src/useIsClient/index.ts b/src/useIsClient/index.ts deleted file mode 100644 index 353fb8ba..00000000 --- a/src/useIsClient/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useIsClient } from './useIsClient' -export * from './useIsClient' diff --git a/src/useIsFirstRender/index.ts b/src/useIsFirstRender/index.ts deleted file mode 100644 index 0ffa7ed1..00000000 --- a/src/useIsFirstRender/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useIsFirstRender } from './useIsFirstRender' -export * from './useIsFirstRender' diff --git a/src/useIsMounted/index.ts b/src/useIsMounted/index.ts deleted file mode 100644 index d66d5cd2..00000000 --- a/src/useIsMounted/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useIsMounted } from './useIsMounted' -export * from './useIsMounted' diff --git a/src/useIsomorphicLayoutEffect/index.ts b/src/useIsomorphicLayoutEffect/index.ts deleted file mode 100644 index 58ae8f42..00000000 --- a/src/useIsomorphicLayoutEffect/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect' -export * from './useIsomorphicLayoutEffect' diff --git a/src/useLocalStorage/index.ts b/src/useLocalStorage/index.ts deleted file mode 100644 index 1132a4f4..00000000 --- a/src/useLocalStorage/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useLocalStorage } from './useLocalStorage' -export * from './useLocalStorage' diff --git a/src/useLockedBody/index.ts b/src/useLockedBody/index.ts deleted file mode 100644 index cba852c2..00000000 --- a/src/useLockedBody/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useLockedBody } from './useLockedBody' -export * from './useLockedBody' diff --git a/src/useMap/index.ts b/src/useMap/index.ts deleted file mode 100644 index bf1b127a..00000000 --- a/src/useMap/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useMap } from './useMap' -export * from './useMap' diff --git a/src/useMediaQuery/index.ts b/src/useMediaQuery/index.ts deleted file mode 100644 index 17c7f955..00000000 --- a/src/useMediaQuery/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useMediaQuery } from './useMediaQuery' -export * from './useMediaQuery' diff --git a/src/useOnClickOutside/index.ts b/src/useOnClickOutside/index.ts deleted file mode 100644 index dd28b9b7..00000000 --- a/src/useOnClickOutside/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useOnClickOutside } from './useOnClickOutside' -export * from './useOnClickOutside' diff --git a/src/useReadLocalStorage/index.ts b/src/useReadLocalStorage/index.ts deleted file mode 100644 index 7d4a3a5d..00000000 --- a/src/useReadLocalStorage/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useReadLocalStorage } from './useReadLocalStorage' -export * from './useReadLocalStorage' diff --git a/src/useScreen/index.ts b/src/useScreen/index.ts deleted file mode 100644 index 8a8e5d22..00000000 --- a/src/useScreen/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useScreen } from './useScreen' -export * from './useScreen' diff --git a/src/useScript/index.ts b/src/useScript/index.ts deleted file mode 100644 index d5b34ea8..00000000 --- a/src/useScript/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useScript } from './useScript' -export * from './useScript' diff --git a/src/useSessionStorage/index.ts b/src/useSessionStorage/index.ts deleted file mode 100644 index 4e47da51..00000000 --- a/src/useSessionStorage/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useSessionStorage } from './useSessionStorage' -export * from './useSessionStorage' diff --git a/src/useSsr/index.ts b/src/useSsr/index.ts deleted file mode 100644 index 930caa32..00000000 --- a/src/useSsr/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useSsr } from './useSsr' -export * from './useSsr' diff --git a/src/useStep/index.ts b/src/useStep/index.ts deleted file mode 100644 index e779118f..00000000 --- a/src/useStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useStep } from './useStep' -export * from './useStep' diff --git a/src/useTernaryDarkMode/index.ts b/src/useTernaryDarkMode/index.ts deleted file mode 100644 index 2dcd890a..00000000 --- a/src/useTernaryDarkMode/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useTernaryDarkMode } from './useTernaryDarkMode' -export * from './useTernaryDarkMode' diff --git a/src/useTimeout/index.ts b/src/useTimeout/index.ts deleted file mode 100644 index 8faa76b0..00000000 --- a/src/useTimeout/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useTimeout } from './useTimeout' -export * from './useTimeout' diff --git a/src/useUpdateEffect/index.ts b/src/useUpdateEffect/index.ts deleted file mode 100644 index 715f6fd1..00000000 --- a/src/useUpdateEffect/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useUpdateEffect } from './useUpdateEffect' -export * from './useUpdateEffect' diff --git a/src/useWindowSize/index.ts b/src/useWindowSize/index.ts deleted file mode 100644 index 425cd39d..00000000 --- a/src/useWindowSize/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as useWindowSize } from './useWindowSize' -export * from './useWindowSize' diff --git a/templates/plop/hooks/hook/demo.tsx.hbs b/templates/plop/hooks/hook/demo.tsx.hbs index 800f342f..eb5bda66 100644 --- a/templates/plop/hooks/hook/demo.tsx.hbs +++ b/templates/plop/hooks/hook/demo.tsx.hbs @@ -1,6 +1,6 @@ import React from 'react' -import { {{camelCase name}} } from './index' +import { {{camelCase name}} } from '..' export default function Component() { const [two] = {{camelCase name}}() diff --git a/templates/plop/hooks/hook/index.ts.hbs b/templates/plop/hooks/hook/index.ts.hbs deleted file mode 100644 index b5bec49f..00000000 --- a/templates/plop/hooks/hook/index.ts.hbs +++ /dev/null @@ -1,2 +0,0 @@ -export { default as {{camelCase name}} } from './{{camelCase name}}' -export * from './{{camelCase name}}' diff --git a/templates/plop/hooks/index.ts.hbs b/templates/plop/hooks/index.ts.hbs index 94f02587..47d7125c 100644 --- a/templates/plop/hooks/index.ts.hbs +++ b/templates/plop/hooks/index.ts.hbs @@ -1 +1,2 @@ -export * from './{{camelCase name}}' +export { default as {{camelCase name}} } from './{{camelCase name}}/{{camelCase name}}' +export * from './{{camelCase name}}/{{camelCase name}}'