From 51c010ddfe75b59426a8562de42a152ba61a8703 Mon Sep 17 00:00:00 2001 From: Barbapapazes Date: Mon, 17 Jul 2023 11:24:00 +0200 Subject: [PATCH 1/3] docs: add about utils directory --- docs/content/1.guide/6.utils.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/content/1.guide/6.utils.md diff --git a/docs/content/1.guide/6.utils.md b/docs/content/1.guide/6.utils.md new file mode 100644 index 0000000000..73a9bcb394 --- /dev/null +++ b/docs/content/1.guide/6.utils.md @@ -0,0 +1,27 @@ +--- +title: Utils +icon: ri:tools-line +--- + +# Utils + +Nitro helps you to stay organized allowing you to take advantage of the [`auto-imports`](auto-imports.md) feature. + +Every exports in `utils/**`, you can create sub-folders, will be detected by Nitro and available globally in your application through `auto-imports`. + +## Example + +You can create a `utils/sum.ts` file where a function `useSum` is exported: + +```ts [utils/sum.ts] +export function useSum(a: number, b: number) { return a + b } +``` + +Then, you can use it in your `routes/index.ts` file without importing it: + +```ts [routes/index.ts] +export default defineEventHandler(() => { + const sum = useSum(1, 2) // auto-imported + return { sum } +}) +``` From 438d968d4eeb14dc87e24ae815cf60dd8fe2dfa1 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Mon, 17 Jul 2023 11:56:24 +0200 Subject: [PATCH 2/3] Update docs/content/1.guide/6.utils.md Co-authored-by: Heb --- docs/content/1.guide/6.utils.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/1.guide/6.utils.md b/docs/content/1.guide/6.utils.md index 73a9bcb394..3de38a6fda 100644 --- a/docs/content/1.guide/6.utils.md +++ b/docs/content/1.guide/6.utils.md @@ -7,7 +7,7 @@ icon: ri:tools-line Nitro helps you to stay organized allowing you to take advantage of the [`auto-imports`](auto-imports.md) feature. -Every exports in `utils/**`, you can create sub-folders, will be detected by Nitro and available globally in your application through `auto-imports`. +Every export in the `utils` directory and its subdirectories will become available globally in your application. ## Example From 8e1cf0aa357d06701250421f98c023c031c96c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A9ban?= Date: Mon, 17 Jul 2023 11:57:40 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Heb --- docs/content/1.guide/6.utils.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/1.guide/6.utils.md b/docs/content/1.guide/6.utils.md index 3de38a6fda..17dcdb1686 100644 --- a/docs/content/1.guide/6.utils.md +++ b/docs/content/1.guide/6.utils.md @@ -11,13 +11,13 @@ Every export in the `utils` directory and its subdirectories will become availab ## Example -You can create a `utils/sum.ts` file where a function `useSum` is exported: +Create a `utils/sum.ts` file where a function `useSum` is exported: ```ts [utils/sum.ts] export function useSum(a: number, b: number) { return a + b } ``` -Then, you can use it in your `routes/index.ts` file without importing it: +Use it in your `routes/index.ts` file without importing it: ```ts [routes/index.ts] export default defineEventHandler(() => {