# VDL Plugin SDK Build VDL plugins in TypeScript with a focused CLI, typed IR access, utility helpers, and test builders. This document is an AI-oriented entry layer for the SDK. Use it to quickly determine: 1. What the package does. 2. Which import path matches the current task. 3. Which documentation links to read next. Read only the sections and links relevant to your task. ## About the project ### What is VDL? VDL is the open-source cross-language definition engine for modern stacks. Define your data structures, APIs, contracts, and generate type-safe code for your backend and frontend instantly. - VDL GitHub: https://github.com/varavelio/vdl - SDK GitHub: https://github.com/varavelio/vdl-plugin-sdk ### What is VDL Plugin SDK (this package) VDL Plugin SDK is a TypeScript library for building VDL plugins (plugins are code generators). ## Task to entry-point map - Write or update plugin runtime logic in `src/index.ts` -> `@varavel/vdl-plugin-sdk` - Reuse helper utilities in plugin logic -> `@varavel/vdl-plugin-sdk/utils/` - Build test fixtures and synthetic IR in tests -> `@varavel/vdl-plugin-sdk/testing` - Type-check and bundle plugin output -> `vdl-plugin` CLI (`check`, `build`) ## Quick Start A VDL plugin exports a `generate` handler created with `definePlugin(...)` from `src/index.ts`. ```ts import { definePlugin } from "@varavel/vdl-plugin-sdk"; export const generate = definePlugin((input) => { // Your plugin logic goes here // Explore plugin input as needed console.log(input.version); // The VDL version without the v prefix console.log(input.options); // Plugin options from vdl.config.vdl console.log(input.ir); // Typed VDL intermediate representation return { files: [ { path: "hello.txt", content: "Hello from VDL Plugin SDK", }, ], }; }); ``` Then run: ```bash npx vdl-plugin check npx vdl-plugin build ``` - `check` validates your TypeScript during development. - `build` generates the release-ready plugin bundle at `dist/index.js`. Output contract reminder: - A plugin returns generated files. - VDL consumes the built artifact at `dist/index.js`. ## What This Package Includes Think of the SDK as five pieces that work together: - The main package for authoring a plugin handler and working with the typed VDL IR. - Built-in error primitives for clear diagnostics (`PluginError`, `fail`, `assert`). - Tree-shakeable utility subpaths for reusable helper functions used in plugin logic. - A separate `testing` entry point for building realistic IR fixtures in unit tests. - A small CLI plus shared `tsconfig` presets for the normal plugin build workflow. ### Entry Points | Import | Use for | | -------------------------------------------- | -------------------------------------------------------------------------------------------------- | | `@varavel/vdl-plugin-sdk` | Main plugin authoring surface: define your plugin, receive typed input, and return generated files | | `@varavel/vdl-plugin-sdk/utils/` | Tree-shakeable utility imports for one helper category | | `@varavel/vdl-plugin-sdk/testing` | Test-only builders for creating plugin input and IR fixtures quickly | #### `@varavel/vdl-plugin-sdk` Use `@varavel/vdl-plugin-sdk` in your plugin runtime code. This is the package surface you start from when writing `src/index.ts`. #### `@varavel/vdl-plugin-sdk/utils/` Use utility subpaths when your plugin code needs reusable transformations, string helpers, option helpers, or IR-oriented convenience functions. Prefer specific imports for clarity and better tree-shaking. #### `@varavel/vdl-plugin-sdk/testing` Use `@varavel/vdl-plugin-sdk/testing` only in tests. It exposes independent IR builder functions for creating realistic plugin input and schema fixtures without hand-writing large object graphs. Do not import this entry point in production plugin runtime code. ### Mental Model - Reach for `@varavel/vdl-plugin-sdk` when you are writing the plugin itself. - Reach for `@varavel/vdl-plugin-sdk/utils/` when your plugin logic needs shared helper functions. - Reach for `@varavel/vdl-plugin-sdk/testing` when you are constructing test fixtures. - Treat the CLI and `tsconfig` presets as project scaffolding around those imports, not as part of your runtime code. ## CLI Use the bundled binary in scripts or with `npx`: ```bash npx vdl-plugin check npx vdl-plugin build # Or with custom entry/out paths: npx vdl-plugin build --entry packages/my-plugin/src/main.ts --out ../../dist/index.js ``` - `check` runs TypeScript without emitting files. - `build` bundles the required `src/index.ts` entry into `dist/index.js` by default. You can override these defaults using the `--entry ` and `--out ` options. - **Note**: Remember that the final built plugin must always be located at `dist/index.js` relative to your project's root directory so that VDL can automatically discover and load it. ## Importing Raw Files The SDK's builder includes out-of-the-box support for importing files as raw plaintext strings. This is extremely useful for bundling templates, HTML, or SQL queries directly into your plugin without needing the `fs` module at runtime. Simply append `?raw` to any relative import path: ```ts import { definePlugin } from "@varavel/vdl-plugin-sdk"; import query from "./query.sql?raw"; export const generate = definePlugin((input) => { return { files: [ { path: "output.sql", content: query, }, ], }; }); ``` ## Error handling `definePlugin` wraps your handler with a global safety boundary. - Throw `PluginError` (or use `fail` or `assert`) for user-facing generation diagnostics. - Use `assert` when validating required conditions while keeping TypeScript narrowing. - Any unexpected thrown value is converted into a safe `errors` payload. Example: ```ts import { assert, definePlugin, fail } from "@varavel/vdl-plugin-sdk"; export const generate = definePlugin((input) => { const serviceType = input.ir.types.find((typeDef) => typeDef.name === "Service"); assert(serviceType, 'Missing required type "Service".', input.ir.position); if (serviceType.type.kind !== "object") { fail('Type "Service" must be an object.', serviceType.position); } return { files: [{ path: "service.txt", content: "ok" }], }; }); ``` For RPC plugins, use an `assertValidIrForRpc` validation call: ```ts import { definePlugin } from "@varavel/vdl-plugin-sdk"; import { assertValidIrForRpc } from "@varavel/vdl-plugin-sdk/utils/rpc"; export const generate = definePlugin((input) => { assertValidIrForRpc(input.ir); return { files: [{ path: "rpc.ts", content: "// generated" }], }; }); ``` ## Agent checklist Before writing code or answering SDK usage questions, verify: 1. Correct entry point selected for the task. 2. Runtime and test imports are not mixed. 3. Workflow commands follow `check` then `build`. ## Core import: `@varavel/vdl-plugin-sdk` _Import from `@varavel/vdl-plugin-sdk`._ Define plugins and use the typed VDL IR surface exported by the main SDK entry point. ## Functions - [assert](https://vdl-plugin-sdk.varavel.com/llms/api/core/functions/assert.md) - [definePlugin](https://vdl-plugin-sdk.varavel.com/llms/api/core/functions/definePlugin.md) - [fail](https://vdl-plugin-sdk.varavel.com/llms/api/core/functions/fail.md) ## Variables - [Annotation](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/Annotation.md) - [ConstantDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/ConstantDef.md) - [EnumDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/EnumDef.md) - [EnumMember](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/EnumMember.md) - [EnumValueType](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/EnumValueType.md) - [Field](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/Field.md) - [IrSchema](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/IrSchema.md) - [LiteralKind](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/LiteralKind.md) - [LiteralValue](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/LiteralValue.md) - [ObjectEntry](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/ObjectEntry.md) - [PluginInput](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/PluginInput.md) - [PluginOutput](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/PluginOutput.md) - [PluginOutputError](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/PluginOutputError.md) - [PluginOutputFile](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/PluginOutputFile.md) - [Position](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/Position.md) - [PrimitiveType](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/PrimitiveType.md) - [TopLevelDoc](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/TopLevelDoc.md) - [TypeDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/TypeDef.md) - [TypeKind](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/TypeKind.md) - [TypeRef](https://vdl-plugin-sdk.varavel.com/llms/api/core/variables/TypeRef.md) ## Type Aliases - [Annotation](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md) - [ConstantDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md) - [EnumDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md) - [EnumMember](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md) - [EnumValueType](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) - [Field](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md) - [IrSchema](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) - [LiteralKind](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) - [LiteralValue](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) - [ObjectEntry](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ObjectEntry.md) - [PluginInput](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md) - [PluginOutput](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutput.md) - [PluginOutputError](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputError.md) - [PluginOutputFile](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputFile.md) - [Position](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) - [PrimitiveType](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) - [TopLevelDoc](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TopLevelDoc.md) - [TypeDef](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md) - [TypeKind](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) - [TypeRef](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) - [VdlPluginHandler](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/VdlPluginHandler.md) ## Classes - [PluginError](https://vdl-plugin-sdk.varavel.com/llms/api/core/classes/PluginError.md) ### Functions #### assert _Import from `@varavel/vdl-plugin-sdk`._ ```ts function assert( condition, message, position?): asserts condition; ``` Ensures `condition` is truthy, otherwise throws a `PluginError`. The `asserts condition` return type enables TypeScript narrowing in plugin code after this function returns. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `condition` | `unknown` | Condition that must hold. | | `message` | `string` | Diagnostic message when the condition fails. | | `position?` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Optional source location for precise diagnostics. | ## Returns `asserts condition` #### definePlugin _Import from `@varavel/vdl-plugin-sdk`._ ```ts function definePlugin(handler): VdlPluginHandler; ``` Wraps a plugin handler so it can be exported as the canonical VDL entry point. `definePlugin` wraps your implementation with a global safety net. Any thrown error is converted into the `PluginOutput` diagnostic contract, so VDL can report failures cleanly instead of crashing with a raw stack trace. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `handler` | [`VdlPluginHandler`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/VdlPluginHandler.md) | The plugin implementation to expose as the runtime entry point. | ## Returns [`VdlPluginHandler`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/VdlPluginHandler.md) A safe handler that always returns `PluginOutput`. ## Example ```ts import { definePlugin } from "@varavel/vdl-plugin-sdk"; export const generate = definePlugin((input) => { return { files: [ { path: "schema-summary.txt", content: `VDL ${input.version}`, }, ], }; }); ``` #### fail _Import from `@varavel/vdl-plugin-sdk`._ ```ts function fail(message, position?): never; ``` Immediately aborts generation by throwing a `PluginError`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `message` | `string` | Human-readable description of what failed. | | `position?` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Optional source location for precise diagnostics. | ## Returns `never` ### Variables #### Annotation _Import from `@varavel/vdl-plugin-sdk`._ ```ts Annotation: object; ``` Annotation exposes the generated runtime helpers for Annotation. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md) | Hydrates a validated Annotation value into its runtime representation. | | `parse()` | (`json`) => [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md) | Parses a JSON string into a validated and hydrated Annotation value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for Annotation (required field presence and basic type shape only); it does not enforce business rules. | #### ConstantDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts ConstantDef: object; ``` ConstantDef exposes the generated runtime helpers for ConstantDef. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`ConstantDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md) | Hydrates a validated ConstantDef value into its runtime representation. | | `parse()` | (`json`) => [`ConstantDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md) | Parses a JSON string into a validated and hydrated ConstantDef value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for ConstantDef (required field presence and basic type shape only); it does not enforce business rules. | #### EnumDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts EnumDef: object; ``` EnumDef exposes the generated runtime helpers for EnumDef. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`EnumDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md) | Hydrates a validated EnumDef value into its runtime representation. | | `parse()` | (`json`) => [`EnumDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md) | Parses a JSON string into a validated and hydrated EnumDef value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for EnumDef (required field presence and basic type shape only); it does not enforce business rules. | #### EnumMember _Import from `@varavel/vdl-plugin-sdk`._ ```ts EnumMember: object; ``` EnumMember exposes the generated runtime helpers for EnumMember. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md) | Hydrates a validated EnumMember value into its runtime representation. | | `parse()` | (`json`) => [`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md) | Parses a JSON string into a validated and hydrated EnumMember value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for EnumMember (required field presence and basic type shape only); it does not enforce business rules. | #### EnumValueType _Import from `@varavel/vdl-plugin-sdk`._ ```ts EnumValueType: object; ``` EnumValueType exposes the generated enum values and runtime helpers for EnumValueType. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Hydrates a validated EnumValueType value. Enums return the input unchanged to keep the generated API uniform. | | `Int` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Represents the Int member of the EnumValueType enum. | | `parse()` | (`json`) => [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Parses a JSON string into a validated and hydrated EnumValueType value. | | `String` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Represents the String member of the EnumValueType enum. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural enum validation only (membership in EnumValueType); it does not enforce business rules. | | `values()` | () => [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md)[] | Returns every declared EnumValueType value in definition order. | #### Field _Import from `@varavel/vdl-plugin-sdk`._ ```ts Field: object; ``` Field exposes the generated runtime helpers for Field. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md) | Hydrates a validated Field value into its runtime representation. | | `parse()` | (`json`) => [`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md) | Parses a JSON string into a validated and hydrated Field value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for Field (required field presence and basic type shape only); it does not enforce business rules. | #### IrSchema _Import from `@varavel/vdl-plugin-sdk`._ ```ts IrSchema: object; ``` IrSchema exposes the generated runtime helpers for IrSchema. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) | Hydrates a validated IrSchema value into its runtime representation. | | `parse()` | (`json`) => [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) | Parses a JSON string into a validated and hydrated IrSchema value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for IrSchema (required field presence and basic type shape only); it does not enforce business rules. | #### LiteralKind _Import from `@varavel/vdl-plugin-sdk`._ ```ts LiteralKind: object; ``` LiteralKind exposes the generated enum values and runtime helpers for LiteralKind. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `Array` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the Array member of the LiteralKind enum. | | `Bool` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the Bool member of the LiteralKind enum. | | `Float` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the Float member of the LiteralKind enum. | | `hydrate()` | (`input`) => [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Hydrates a validated LiteralKind value. Enums return the input unchanged to keep the generated API uniform. | | `Int` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the Int member of the LiteralKind enum. | | `Object` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the Object member of the LiteralKind enum. | | `parse()` | (`json`) => [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Parses a JSON string into a validated and hydrated LiteralKind value. | | `String` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Represents the String member of the LiteralKind enum. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural enum validation only (membership in LiteralKind); it does not enforce business rules. | | `values()` | () => [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md)[] | Returns every declared LiteralKind value in definition order. | #### LiteralValue _Import from `@varavel/vdl-plugin-sdk`._ ```ts LiteralValue: object; ``` LiteralValue exposes the generated runtime helpers for LiteralValue. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Hydrates a validated LiteralValue value into its runtime representation. | | `parse()` | (`json`) => [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Parses a JSON string into a validated and hydrated LiteralValue value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for LiteralValue (required field presence and basic type shape only); it does not enforce business rules. | #### ObjectEntry _Import from `@varavel/vdl-plugin-sdk`._ ```ts ObjectEntry: object; ``` ObjectEntry exposes the generated runtime helpers for ObjectEntry. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`ObjectEntry`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ObjectEntry.md) | Hydrates a validated ObjectEntry value into its runtime representation. | | `parse()` | (`json`) => [`ObjectEntry`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ObjectEntry.md) | Parses a JSON string into a validated and hydrated ObjectEntry value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for ObjectEntry (required field presence and basic type shape only); it does not enforce business rules. | #### PluginInput _Import from `@varavel/vdl-plugin-sdk`._ ```ts PluginInput: object; ``` PluginInput exposes the generated runtime helpers for PluginInput. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`PluginInput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md) | Hydrates a validated PluginInput value into its runtime representation. | | `parse()` | (`json`) => [`PluginInput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md) | Parses a JSON string into a validated and hydrated PluginInput value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for PluginInput (required field presence and basic type shape only); it does not enforce business rules. | #### PluginOutput _Import from `@varavel/vdl-plugin-sdk`._ ```ts PluginOutput: object; ``` PluginOutput exposes the generated runtime helpers for PluginOutput. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`PluginOutput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutput.md) | Hydrates a validated PluginOutput value into its runtime representation. | | `parse()` | (`json`) => [`PluginOutput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutput.md) | Parses a JSON string into a validated and hydrated PluginOutput value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for PluginOutput (required field presence and basic type shape only); it does not enforce business rules. | #### PluginOutputError _Import from `@varavel/vdl-plugin-sdk`._ ```ts PluginOutputError: object; ``` PluginOutputError exposes the generated runtime helpers for PluginOutputError. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`PluginOutputError`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputError.md) | Hydrates a validated PluginOutputError value into its runtime representation. | | `parse()` | (`json`) => [`PluginOutputError`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputError.md) | Parses a JSON string into a validated and hydrated PluginOutputError value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for PluginOutputError (required field presence and basic type shape only); it does not enforce business rules. | #### PluginOutputFile _Import from `@varavel/vdl-plugin-sdk`._ ```ts PluginOutputFile: object; ``` PluginOutputFile exposes the generated runtime helpers for PluginOutputFile. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`PluginOutputFile`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputFile.md) | Hydrates a validated PluginOutputFile value into its runtime representation. | | `parse()` | (`json`) => [`PluginOutputFile`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputFile.md) | Parses a JSON string into a validated and hydrated PluginOutputFile value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for PluginOutputFile (required field presence and basic type shape only); it does not enforce business rules. | #### Position _Import from `@varavel/vdl-plugin-sdk`._ ```ts Position: object; ``` Position exposes the generated runtime helpers for Position. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Hydrates a validated Position value into its runtime representation. | | `parse()` | (`json`) => [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Parses a JSON string into a validated and hydrated Position value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for Position (required field presence and basic type shape only); it does not enforce business rules. | #### PrimitiveType _Import from `@varavel/vdl-plugin-sdk`._ ```ts PrimitiveType: object; ``` PrimitiveType exposes the generated enum values and runtime helpers for PrimitiveType. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `Bool` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Represents the Bool member of the PrimitiveType enum. | | `Datetime` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Represents the Datetime member of the PrimitiveType enum. | | `Float` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Represents the Float member of the PrimitiveType enum. | | `hydrate()` | (`input`) => [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Hydrates a validated PrimitiveType value. Enums return the input unchanged to keep the generated API uniform. | | `Int` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Represents the Int member of the PrimitiveType enum. | | `parse()` | (`json`) => [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Parses a JSON string into a validated and hydrated PrimitiveType value. | | `String` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Represents the String member of the PrimitiveType enum. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural enum validation only (membership in PrimitiveType); it does not enforce business rules. | | `values()` | () => [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md)[] | Returns every declared PrimitiveType value in definition order. | #### TopLevelDoc _Import from `@varavel/vdl-plugin-sdk`._ ```ts TopLevelDoc: object; ``` TopLevelDoc exposes the generated runtime helpers for TopLevelDoc. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`TopLevelDoc`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TopLevelDoc.md) | Hydrates a validated TopLevelDoc value into its runtime representation. | | `parse()` | (`json`) => [`TopLevelDoc`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TopLevelDoc.md) | Parses a JSON string into a validated and hydrated TopLevelDoc value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for TopLevelDoc (required field presence and basic type shape only); it does not enforce business rules. | #### TypeDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts TypeDef: object; ``` TypeDef exposes the generated runtime helpers for TypeDef. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`TypeDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md) | Hydrates a validated TypeDef value into its runtime representation. | | `parse()` | (`json`) => [`TypeDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md) | Parses a JSON string into a validated and hydrated TypeDef value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for TypeDef (required field presence and basic type shape only); it does not enforce business rules. | #### TypeKind _Import from `@varavel/vdl-plugin-sdk`._ ```ts TypeKind: object; ``` TypeKind exposes the generated enum values and runtime helpers for TypeKind. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `Array` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Array member of the TypeKind enum. | | `Enum` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Enum member of the TypeKind enum. | | `hydrate()` | (`input`) => [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Hydrates a validated TypeKind value. Enums return the input unchanged to keep the generated API uniform. | | `Map` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Map member of the TypeKind enum. | | `Object` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Object member of the TypeKind enum. | | `parse()` | (`json`) => [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Parses a JSON string into a validated and hydrated TypeKind value. | | `Primitive` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Primitive member of the TypeKind enum. | | `Type` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Represents the Type member of the TypeKind enum. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural enum validation only (membership in TypeKind); it does not enforce business rules. | | `values()` | () => [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md)[] | Returns every declared TypeKind value in definition order. | #### TypeRef _Import from `@varavel/vdl-plugin-sdk`._ ```ts TypeRef: object; ``` TypeRef exposes the generated runtime helpers for TypeRef. ## Type Declaration | Name | Type | Description | | :------ | :------ | :------ | | `hydrate()` | (`input`) => [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Hydrates a validated TypeRef value into its runtime representation. | | `parse()` | (`json`) => [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Parses a JSON string into a validated and hydrated TypeRef value. | | `validate()` | (`input`, `path?`) => `string` \| `null` | Performs structural validation for TypeRef (required field presence and basic type shape only); it does not enforce business rules. | ### Type Aliases #### Annotation _Import from `@varavel/vdl-plugin-sdk`._ ```ts type Annotation = object; ``` Annotation metadata preserved in IR. `name` is the annotation identifier without the `@` prefix. `argument`, when present, is fully resolved as a LiteralValue. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `argument?` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Optional resolved argument payload | | `name` | `string` | Annotation name without `@` | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this annotation | #### ConstantDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts type ConstantDef = object; ``` Fully resolved constant definition. `value` contains the fully resolved literal payload. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] | Constant annotations in source order | | `doc?` | `string` | Optional constant documentation | | `name` | `string` | Constant name | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this definition | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Fully resolved constant value | #### EnumDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts type EnumDef = object; ``` Flattened enum definition. All enum spreads are already expanded into `members`. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] | Enum annotations in source order | | `doc?` | `string` | Optional enum documentation | | `enumType` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Enum underlying storage kind | | `members` | [`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md)[] | Enum members in source order after spread expansion | | `name` | `string` | Enum name | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this definition | #### EnumMember _Import from `@varavel/vdl-plugin-sdk`._ ```ts type EnumMember = object; ``` Enum member definition ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] | Member annotations in source order | | `doc?` | `string` | Optional member documentation | | `name` | `string` | Member name | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this member | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Fully resolved member value | #### EnumValueType _Import from `@varavel/vdl-plugin-sdk`._ ```ts type EnumValueType = "string" | "int"; ``` Underlying storage kind used by an enum #### Field _Import from `@varavel/vdl-plugin-sdk`._ ```ts type Field = object; ``` Flattened object/type field definition ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] | Field annotations in source order | | `doc?` | `string` | Optional field documentation | | `name` | `string` | Field name | | `optional` | `boolean` | True when the field is optional (`?`) | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this field | | `typeRef` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Normalized field type reference | #### IrSchema _Import from `@varavel/vdl-plugin-sdk`._ ```ts type IrSchema = object; ``` IrSchema is the generator-facing representation of a VDL program. This model is intentionally "flat" and "resolved": - spreads are already expanded - references are already resolved - collections are in deterministic order A code generator should be able to consume IrSchema directly, without needing to re-run parser or semantic-analysis logic. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `constants` | [`ConstantDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md)[] | Constant definitions, sorted by name | | `docs` | [`TopLevelDoc`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TopLevelDoc.md)[] | Standalone documentation blocks in source traversal order | | `entryPoint` | `string` | Absolute path to the main file that triggered the compilation | | `enums` | [`EnumDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md)[] | Enum definitions, sorted by name | | `types` | [`TypeDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md)[] | Type definitions, sorted by name | #### LiteralKind _Import from `@varavel/vdl-plugin-sdk`._ ```ts type LiteralKind = "string" | "int" | "float" | "bool" | "object" | "array"; ``` Kind discriminator for LiteralValue. LiteralValue is used for fully resolved literal data in: - constant values - annotation arguments #### LiteralValue _Import from `@varavel/vdl-plugin-sdk`._ ```ts type LiteralValue = object; ``` Fully resolved literal value. The selected payload is determined by `kind`: - `string` -\> `stringValue` - `int` -\> `intValue` - `float` -\> `floatValue` - `bool` -\> `boolValue` - `object` -\> `objectEntries` - `array` -\> `arrayItems` ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `arrayItems?` | `LiteralValue`[] | Payload for `kind = array` | | `boolValue?` | `boolean` | Payload for `kind = bool` | | `floatValue?` | `number` | Payload for `kind = float` | | `intValue?` | `number` | Payload for `kind = int` | | `kind` | [`LiteralKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralKind.md) | Value category discriminator | | `objectEntries?` | [`ObjectEntry`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ObjectEntry.md)[] | Payload for `kind = object` | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this literal value | | `stringValue?` | `string` | Payload for `kind = string` | #### ObjectEntry _Import from `@varavel/vdl-plugin-sdk`._ ```ts type ObjectEntry = object; ``` Key/value pair inside an object LiteralValue payload ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `key` | `string` | Object key | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this key-value pair | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Fully resolved value for this key | #### PluginInput _Import from `@varavel/vdl-plugin-sdk`._ ```ts type PluginInput = object; ``` PluginInput represents the data payload sent to a plugin. The plugin receives this as a single argument containing the complete Intermediate Representation of the VDL schema along with any user-defined configuration options from `vdl.config.vdl`. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `ir` | [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) | The complete VDL Intermediate Representation. Contains all types, enums, constants, and documentation from the compiled schema, fully resolved and ready for code generation. | | `options` | `Record`\<`string`, `string`\> | Arbitrary key-value options passed from the `vdl.config.vdl` plugin configuration. These allow users to customize plugin behavior without modifying the plugin itself. Common use cases include specifying target frameworks, API versions, naming conventions, or feature flags. | | `version` | `string` | The VDL binary version (without v prefix, e.g. 1.0.0) | #### PluginOutput _Import from `@varavel/vdl-plugin-sdk`._ ```ts type PluginOutput = object; ``` PluginOutput represents the response payload returned by the `plugin` function. After processing the input schema, the plugin outputs this object containing all files to be generated or errors to be displayed to the user. If there are no errors and at least one file is returned, VDL will write each file to the specified path within the output directory. If there are errors, VDL will display them to the user and not write any files. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `errors?` | [`PluginOutputError`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputError.md)[] | List of semantic errors encountered by the plugin. If present, VDL will stop the compilation and display them to the user. | | `files?` | [`PluginOutputFile`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutputFile.md)[] | List of virtual files generated by the plugin. Each file specifies a relative path within the output directory and its complete textual content. Paths may include subdirectories which VDL will create automatically. If no files are returned, VDL will not write anything. | #### PluginOutputError _Import from `@varavel/vdl-plugin-sdk`._ ```ts type PluginOutputError = object; ``` A structured error reported by the plugin. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `message` | `string` | Human-readable error message explaining what went wrong | | `position?` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Optional source position associated with this error. If provided, VDL will print a beautiful snippet highlighting the exact code. If omitted, the error is treated as a global configuration/plugin error. | #### PluginOutputFile _Import from `@varavel/vdl-plugin-sdk`._ ```ts type PluginOutputFile = object; ``` PluginOutputFile represents a single generated file produced by the plugin. This abstraction allows plugins to generate multiple files from a single invocation, enabling patterns like one-file-per-type or splitting large outputs across multiple modules. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `content` | `string` | The complete textual content of the generated file. This should be the final, formatted output ready to be written to disk. VDL writes this content as-is without additional processing. | | `path` | `string` | Relative path from the output directory where this file should be written. May include subdirectory separators (e.g., "src/models/user.py"). Forward slashes are normalized to the appropriate separator for the current operating system. | #### Position _Import from `@varavel/vdl-plugin-sdk`._ ```ts type Position = object; ``` It represents a position within a file and is used for error reporting, diagnostics, plugins, and tooling support. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `column` | `number` | Column number (1-indexed) | | `file` | `string` | Absolute file path | | `line` | `number` | Line number (1-indexed) | #### PrimitiveType _Import from `@varavel/vdl-plugin-sdk`._ ```ts type PrimitiveType = "string" | "int" | "float" | "bool" | "datetime"; ``` Primitive scalar type names #### TopLevelDoc _Import from `@varavel/vdl-plugin-sdk`._ ```ts type TopLevelDoc = object; ``` Standalone documentation block. Used for top-level docstrings that are not attached to a type/enum/constant. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `content` | `string` | Resolved documentation content | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this documentation block | #### TypeDef _Import from `@varavel/vdl-plugin-sdk`._ ```ts type TypeDef = object; ``` Flattened type definition. All spreads are already expanded. The unified `typeRef` describes what this type IS, a primitive, custom reference, map, array, or object with fields. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] | Type annotations in source order | | `doc?` | `string` | Optional type documentation | | `name` | `string` | Type name | | `position` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | Source position of this type definition. Will be zero valued if the type was inferred by the compiler. | | `typeRef` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Unified type reference describing what this type IS | #### TypeKind _Import from `@varavel/vdl-plugin-sdk`._ ```ts type TypeKind = "primitive" | "type" | "enum" | "array" | "map" | "object"; ``` Kind discriminator for TypeRef #### TypeRef _Import from `@varavel/vdl-plugin-sdk`._ ```ts type TypeRef = object; ``` Normalized type reference used by fields. `kind` selects which payload fields are meaningful. Generators should inspect `kind` first, then read the related payload fields. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `arrayDims?` | `number` | Array rank when `kind` is `array` (for example, 2 for `T[][]`) | | `arrayType?` | `TypeRef` | Element type when `kind` is `array` | | `enumName?` | `string` | Referenced enum name when `kind` is `enum` | | `enumType?` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Referenced enum underlying kind when `kind` is `enum` | | `kind` | [`TypeKind`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeKind.md) | Type category discriminator | | `mapType?` | `TypeRef` | Map value type when `kind` is `map` | | `objectFields?` | [`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md)[] | Inline object fields when `kind` is `object` | | `primitiveName?` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Primitive type name when `kind` is `primitive` | | `typeName?` | `string` | Referenced type name when `kind` is `type` | #### VdlPluginHandler _Import from `@varavel/vdl-plugin-sdk`._ ```ts type VdlPluginHandler = (input) => PluginOutput; ``` Function signature implemented by every VDL plugin entry point. The handler receives the typed plugin input produced by VDL and returns the generated files and any diagnostics for the current run. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | [`PluginInput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md) | The plugin invocation context, including version, options, and IR. | ## Returns [`PluginOutput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginOutput.md) The files and errors produced by the plugin. ## Example ```ts const generate: VdlPluginHandler = (input) => { return { files: [{ path: "hello.txt", content: input.version }], }; }; ``` ### Classes #### PluginError _Import from `@varavel/vdl-plugin-sdk`._ Error type for plugin generation failures that should be surfaced as structured VDL diagnostics. Use this when you need to preserve an optional source `position`. ## Extends - `Error` ## Constructors ### Constructor ```ts new PluginError(message, position?): PluginError; ``` #### Parameters | Parameter | Type | | :------ | :------ | | `message` | `string` | | `position?` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | #### Returns `PluginError` #### Overrides ```ts Error.constructor ``` ## Properties ### message ```ts message: string; ``` #### Inherited from ```ts Error.message ``` *** ### name ```ts name: string; ``` #### Inherited from ```ts Error.name ``` *** ### position? ```ts readonly optional position?: Position; ``` *** ### stack? ```ts optional stack?: string; ``` #### Inherited from ```ts Error.stack ``` ## Utilities ### IR import: `@varavel/vdl-plugin-sdk/utils/ir` _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ## Functions - [anonymizeIr](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/functions/anonymizeIr.md) - [getAnnotation](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/functions/getAnnotation.md) - [getAnnotationArg](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/functions/getAnnotationArg.md) - [hoistAnonymousTypes](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/functions/hoistAnonymousTypes.md) - [unwrapLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/functions/unwrapLiteral.md) ## Type Aliases - [AnonymizableIr](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/type-aliases/AnonymizableIr.md) - [HoistNameContext](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/type-aliases/HoistNameContext.md) #### Functions ##### anonymizeIr _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ## Call Signature ```ts function anonymizeIr(input): T; ``` Returns a deep-cloned copy of an object with source metadata redacted. Redaction rules: - every `entryPoint` string is replaced with `""` - every `position` object is replaced with `{ file: "schema.vdl", line: 1, column: 1 }` The traversal is recursive, covers nested objects and arrays, and never mutates the input value. Non-object values are returned as-is. This helper is useful before snapshotting, hashing, logging, or emitting IR outside trusted boundaries where absolute file paths should not leak. ### Type Parameters | Type Parameter | | :------ | | `T` *extends* [`AnonymizableIr`](https://vdl-plugin-sdk.varavel.com/llms/api/utils/ir/type-aliases/AnonymizableIr.md) | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | `T` | Object to sanitize. | ### Returns `T` A new object with the same structure and redacted IR metadata. ### Example ```ts const safeIr = anonymizeIr(irSchema); // safeIr.entryPoint === "" // safeIr.types[0].position.file === "schema.vdl" ``` ## Call Signature ```ts function anonymizeIr(input): T; ``` Returns a deep-cloned copy of an object with source metadata redacted. Redaction rules: - every `entryPoint` string is replaced with `""` - every `position` object is replaced with `{ file: "schema.vdl", line: 1, column: 1 }` The traversal is recursive, covers nested objects and arrays, and never mutates the input value. Non-object values are returned as-is. This helper is useful before snapshotting, hashing, logging, or emitting IR outside trusted boundaries where absolute file paths should not leak. ### Type Parameters | Type Parameter | | :------ | | `T` *extends* `object` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | `T` | Object to sanitize. | ### Returns `T` A new object with the same structure and redacted IR metadata. ### Example ```ts const safeIr = anonymizeIr(irSchema); // safeIr.entryPoint === "" // safeIr.types[0].position.file === "schema.vdl" ``` ##### getAnnotation _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts function getAnnotation(annotations, name): Annotation | undefined; ``` Returns the first annotation that matches the provided name. Annotation names are compared exactly as stored in the IR, without adding or removing an `@` prefix. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] \| `undefined` | Annotation list to search. | | `name` | `string` | Annotation name to match. | ## Returns [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md) \| `undefined` The matching annotation, or `undefined` when it is not present. ## Example ```ts const annotation = getAnnotation(field.annotations, "deprecated"); // returns the first `deprecated` annotation or undefined ``` ##### getAnnotationArg _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts function getAnnotationArg(annotations, name): | LiteralValue | undefined; ``` Returns the raw literal argument stored in an annotation. VDL annotations currently expose a single literal argument. Pair this helper with `unwrapLiteral` when you need a plain JavaScript value. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `annotations` | [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md)[] \| `undefined` | Annotation list to search. | | `name` | `string` | Annotation name whose argument should be returned. | ## Returns \| [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) \| `undefined` The annotation argument as a `LiteralValue`, or `undefined` when the annotation or argument is missing. ## Example ```ts const arg = getAnnotationArg(field.annotations, "length"); // returns the raw annotation literal, such as { kind: "int", intValue: 64, ... } ``` ##### hoistAnonymousTypes _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts function hoistAnonymousTypes(schema, nameFn?): IrSchema; ``` Hoists anonymous inline object types into generated top-level `TypeDef`s. This helper converts nested anonymous object types into named top-level IR types. It exists for plugin authors who want a flatter, easier-to-generate type graph without changing the compiler's canonical IR format. In other words: the compiler can keep emitting faithful nested IR, and a plugin can call this helper when it wants to treat inline object shapes as "syntactic sugar" and work only with named types. What the helper does: - walks `schema.types` - finds anonymous inline objects nested inside those top-level types - creates a new synthetic top-level `TypeDef` for each one - replaces the original inline object with a `kind: "type"` reference to the generated type name - repeats the same process recursively for deeper nested objects - also hoists anonymous objects that appear inside arrays and maps - never mutates the input schema Default naming behavior: - nested field objects become names like `MyRpcBarProcInput` - anonymous array item objects end with `Item` - anonymous map value objects end with `Value` - name conflicts are resolved automatically with `2`, `3`, and so on Scope and non-goals: - only anonymous objects reachable from `schema.types` are hoisted - constants, enums, docs, and already named type references are left alone - identical object shapes are not deduplicated; each anonymous occurrence is treated as its own generated type This makes the function especially useful for languages or generators that do not want to preserve nested inline object syntax in the output. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `schema` | [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) | IR schema to transform. | | `nameFn?` | (`context`) => `string` | Optional callback that returns the base name to use for each generated type before uniqueness suffixes are applied. | ## Returns [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) A new schema where nested anonymous object types have been hoisted to top-level named types. ## Examples ```ts const flatSchema = ir.hoistAnonymousTypes(schema); flatSchema.types.map((typeDef) => typeDef.name); // ['FooType', 'MyRpc', 'MyRpcBarProc', 'MyRpcBarProcInput', 'MyRpcBarProcOutput'] ``` ```ts const flatSchema = ir.hoistAnonymousTypes(schema, ({ defaultName }) => { return `${defaultName}Dto`; }); // Example: // Request.payload { ... } // becomes a generated type named RequestPayloadDto ``` ```ts // Before hoisting: // type Api { // request { // payload { // id string // } // } // } const flatSchema = ir.hoistAnonymousTypes(schema); // After hoisting, the plugin can work with top-level names like: // - Api // - ApiRequest // - ApiRequestPayload ``` ##### unwrapLiteral _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts function unwrapLiteral(value): T; ``` Resolves a `LiteralValue` into its native JavaScript representation. Pass a generic when you already know the expected shape. Omit it to get `unknown` and narrow the result yourself. The generic only affects TypeScript types. It does not validate the runtime value. ## Type Parameters | Type Parameter | Default type | | :------ | :------ | | `T` | `unknown` | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | The VDL literal to convert. | ## Returns `T` The recursively unwrapped JavaScript value. ## Examples ```ts const raw = unwrapLiteral({ position: { file: "schema.vdl", line: 1, column: 1 }, kind: "string", stringValue: "hello", }); // returns "hello" ``` ```ts const value = unwrapLiteral<{ enabled: boolean }>( { position: { file: "schema.vdl", line: 1, column: 1 }, kind: "object", objectEntries: [ { position: { file: "schema.vdl", line: 1, column: 1 }, key: "enabled", value: { position: { file: "schema.vdl", line: 1, column: 1 }, kind: "bool", boolValue: true, }, }, ], }, ); // returns { enabled: true } ``` #### Type Aliases ##### AnonymizableIr _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts type AnonymizableIr = object; ``` Object shape that explicitly carries IR source metadata. This type is used to provide stronger TypeScript guidance when callers pass known IR-like objects. `anonymizeIr` also accepts generic objects through a fallback overload, so this type is opt-in and non-breaking. ## Properties | Property | Type | | :------ | :------ | | `entryPoint?` | `string` | | `position?` | [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) | ##### HoistNameContext _Import from `@varavel/vdl-plugin-sdk/utils/ir`._ ```ts type HoistNameContext = object; ``` Naming information passed to the optional `nameFn` callback used by `hoistAnonymousTypes`. The callback is invoked once for every anonymous inline object that is about to become a generated top-level type. You can think of this object as the "naming explanation" for a single hoist operation: it tells you where the anonymous object came from, what its parent named type is, and which name the SDK would use if you do nothing. The callback runs before the SDK resolves collisions. This means: - return `defaultName` to keep the built-in behavior - return a custom base name to override it - if the returned name already exists, the SDK will still make it unique by appending `2`, `3`, and so on - if the returned name is blank after trimming, `hoistAnonymousTypes` throws This type is intentionally small so plugin authors can understand it quickly from the docs alone. ## Examples ```ts const flatSchema = ir.hoistAnonymousTypes(schema, ({ defaultName }) => { return `${defaultName}Dto`; }); ``` ```ts const flatSchema = ir.hoistAnonymousTypes(schema, ({ parts, defaultName }) => { if (parts.at(-1) === "input") return `${defaultName}Request`; if (parts.at(-1) === "output") return `${defaultName}Response`; return defaultName; }); ``` ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `defaultName` | `string` | Name the SDK would use if no custom `nameFn` were provided. This is usually the best starting point for custom naming. Most callbacks only need to add a prefix/suffix or swap a few special cases. | | `parentName` | `string` | Name of the nearest named parent type being traversed. For a direct child of an existing top-level type, this is that top-level type name. For an anonymous object nested inside another anonymous object that was already hoisted, this becomes the generated name of that synthetic parent type. | | `parts` | `string`[] | Source path used to derive the generated type name. Each item represents one naming segment. For regular nested object fields, `parts` follows the field path. For anonymous objects inside arrays or maps, the SDK appends a synthetic segment so the generated name stays readable and deterministic: - array item objects append `Item` - map value objects append `Value` Examples: - `MyRpc.barProc.input` -\> `['MyRpc', 'barProc', 'input']` - `Response.items[]` -\> `['Response', 'items', 'Item']` - `Response.meta{}` -\> `['Response', 'meta', 'Value']` | ### RPC import: `@varavel/vdl-plugin-sdk/utils/rpc` _Import from `@varavel/vdl-plugin-sdk/utils/rpc`._ ## Functions - [assertValidIrForRpc](https://vdl-plugin-sdk.varavel.com/llms/api/utils/rpc/functions/assertValidIrForRpc.md) #### Functions ##### assertValidIrForRpc _Import from `@varavel/vdl-plugin-sdk/utils/rpc`._ ```ts function assertValidIrForRpc(ir): void; ``` Asserts that RPC-annotated IR structures follow SDK RPC conventions. This helper is intended for RPC-oriented plugins that want a single fail-fast validation call before generation starts. Validation rules: 1. If no type is annotated with `@rpc`, validation is skipped. 2. Every `@rpc` type must be an object type. 3. Inside each `@rpc` object, only fields annotated with `@proc` or `@stream` are validated as RPC operations. 4. An operation field cannot have both `@proc` and `@stream`. 5. Every `@proc` or `@stream` field must be an object type. 6. If an operation declares `input` or `output` fields, each one must be an object type. 7. The contents inside valid `input`/`output` objects are intentionally not validated by this helper and can be anything. The function is fail-fast and non-returning for invalid input: - It returns `void` when RPC structures are valid. - It throws `PluginError` on the first violation. - `definePlugin` catches that error and turns it into plugin diagnostics. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `ir` | [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) | Fully resolved VDL IR schema to validate. | ## Returns `void` ## Example ```ts import { definePlugin } from "@varavel/vdl-plugin-sdk"; import { assertValidIrForRpc } from "@varavel/vdl-plugin-sdk/utils/rpc"; export const generate = definePlugin((input) => { assertValidIrForRpc(input.ir); return { files: [{ path: "rpc.ts", content: "// ..." }], }; }); ``` ### Options import: `@varavel/vdl-plugin-sdk/utils/options` _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ## Functions - [getOptionArray](https://vdl-plugin-sdk.varavel.com/llms/api/utils/options/functions/getOptionArray.md) - [getOptionBool](https://vdl-plugin-sdk.varavel.com/llms/api/utils/options/functions/getOptionBool.md) - [getOptionEnum](https://vdl-plugin-sdk.varavel.com/llms/api/utils/options/functions/getOptionEnum.md) - [getOptionNumber](https://vdl-plugin-sdk.varavel.com/llms/api/utils/options/functions/getOptionNumber.md) - [getOptionString](https://vdl-plugin-sdk.varavel.com/llms/api/utils/options/functions/getOptionString.md) #### Functions ##### getOptionArray _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ```ts function getOptionArray( options, key, defaultValue?, separator?): string[]; ``` Returns a string array option from a separator-delimited value. Empty items are removed and each entry is trimmed. Missing values return the provided default. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `options` | `Record`\<`string`, `string`\> \| `undefined` | `undefined` | Plugin options record. | | `key` | `string` | `undefined` | Option name to read. | | `defaultValue` | `string`[] | `[]` | Value returned when the option is missing. | | `separator` | `string` | `","` | Delimiter used to split the raw string. | ## Returns `string`[] A trimmed array of non-empty entries, an empty array for blank values, or the default when the key is missing. ## Example ```ts // For options: { "features": "feature1, feature2, feature3" } getOptionArray(options, "features", [], ",") // returns ["feature1", "feature2", "feature3"] ``` ##### getOptionBool _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ```ts function getOptionBool( options, key, defaultValue): boolean; ``` Returns a boolean option using common truthy and falsy string values. Accepted truthy values: `true`, `1`, `yes`, `on`, `enable`, `enabled`, `y`. Accepted falsy values: `false`, `0`, `no`, `off`, `disable`, `disabled`, `n`. Invalid values fall back to the provided default. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `options` | `Record`\<`string`, `string`\> \| `undefined` | Plugin options record. | | `key` | `string` | Option name to read. | | `defaultValue` | `boolean` | Value returned when the option is missing or invalid. | ## Returns `boolean` The parsed boolean value, or the default when parsing fails. ## Example ```ts getOptionBool({ watch: "yes" }, "watch", false); // returns true ``` ##### getOptionEnum _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ```ts function getOptionEnum( options, key, allowedValues, defaultValue): T; ``` Returns a string option constrained to a known set of allowed values. Missing, blank, and unsupported values fall back to the provided default. ## Type Parameters | Type Parameter | | :------ | | `T` *extends* `string` | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `options` | `Record`\<`string`, `string`\> \| `undefined` | Plugin options record. | | `key` | `string` | Option name to read. | | `allowedValues` | readonly `T`[] | Supported string values for the option. | | `defaultValue` | `T` | Value returned when the option is missing or invalid. | ## Returns `T` A valid enum-like string from `allowedValues`. ## Example ```ts getOptionEnum({ format: "esm" }, "format", ["cjs", "esm"] as const, "cjs"); // returns "esm" ``` ##### getOptionNumber _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ```ts function getOptionNumber( options, key, defaultValue): number; ``` Returns a numeric option or the provided fallback when parsing fails. Empty, invalid, and non-finite values fall back to the default. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `options` | `Record`\<`string`, `string`\> \| `undefined` | Plugin options record. | | `key` | `string` | Option name to read. | | `defaultValue` | `number` | Value returned when the option is missing or invalid. | ## Returns `number` The parsed finite number, or the default when parsing fails. ## Example ```ts getOptionNumber({ retries: "3" }, "retries", 0); // returns 3 ``` ##### getOptionString _Import from `@varavel/vdl-plugin-sdk/utils/options`._ ```ts function getOptionString( options, key, defaultValue): string; ``` Returns a string option or the provided fallback when the key is missing. Unlike the numeric and enum helpers, this function preserves the raw option value exactly as provided, including empty strings. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `options` | `Record`\<`string`, `string`\> \| `undefined` | Plugin options record. | | `key` | `string` | Option name to read. | | `defaultValue` | `string` | Value returned when the option is missing. | ## Returns `string` The raw option string, or the default when the key is missing. ## Example ```ts getOptionString({ prefix: "Api" }, "prefix", "Model"); // returns "Api" ``` ### Strings import: `@varavel/vdl-plugin-sdk/utils/strings` _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ## Functions - [camelCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/camelCase.md) - [dedent](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/dedent.md) - [ensurePrefix](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/ensurePrefix.md) - [ensureSuffix](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/ensureSuffix.md) - [escapeHtml](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/escapeHtml.md) - [escapeScriptTag](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/escapeScriptTag.md) - [firstNChars](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/firstNChars.md) - [firstNWords](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/firstNWords.md) - [fuzzySearch](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/fuzzySearch.md) - [indent](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/indent.md) - [joinLines](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/joinLines.md) - [kebabCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/kebabCase.md) - [lastNChars](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/lastNChars.md) - [lastNWords](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/lastNWords.md) - [limitBlankLines](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/limitBlankLines.md) - [lowerCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/lowerCase.md) - [pad](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/pad.md) - [padLeft](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/padLeft.md) - [padRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/padRight.md) - [pascalCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/pascalCase.md) - [pluralize](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/pluralize.md) - [slugify](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/slugify.md) - [snakeCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/snakeCase.md) - [trim](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/trim.md) - [trimEnd](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/trimEnd.md) - [trimStart](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/trimStart.md) - [upperCase](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/upperCase.md) - [words](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/functions/words.md) ## Type Aliases - [FuzzySearchResult](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/type-aliases/FuzzySearchResult.md) #### Functions ##### camelCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function camelCase(str): string; ``` Converts a string to `camelCase`. Tokenization is delegated to `words`, so mixed input styles such as `snake_case`, `kebab-case`, `PascalCase`, `camelCase`, and separator-heavy strings are normalized first and then reassembled. The first token is lowercased. Every following token is capitalized with the remainder lowercased. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to normalize. | ## Returns `string` The `camelCase` representation of `str`. ## Example ```ts camelCase("user_profile-name") // "userProfileName" ``` ##### dedent _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function dedent(input): string; ``` Removes shared indentation from a multi-line string. This helper is useful for generating readable code templates, markdown, or text fixtures inside plugins without carrying indentation from the source file into the final output. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | `string` | Multi-line string to dedent. | ## Returns `string` The same text with common indentation removed. ## Example ```ts dedent(` export interface User { id: string; } `); // returns "export interface User {\n id: string;\n}" ``` ## See Powered by `dedent` (MIT License): [https://github.com/dmnd/dedent](https://github.com/dmnd/dedent) ##### ensurePrefix _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function ensurePrefix(str, prefix): string; ``` Ensures that a string starts with a specific prefix. If the string already starts with the prefix, it is returned as is. Otherwise, the prefix is prepended to the string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | The string to check. | | `prefix` | `string` | The prefix to ensure. | ## Returns `string` The string with the prefix ensured. ## Example ```ts ensurePrefix('User', 'I') // "IUser" ensurePrefix('IUser', 'I') // "IUser" ``` ##### ensureSuffix _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function ensureSuffix(str, suffix): string; ``` Ensures that a string ends with a specific suffix. If the string already ends with the suffix, it is returned as is. Otherwise, the suffix is appended to the string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | The string to check. | | `suffix` | `string` | The suffix to ensure. | ## Returns `string` The string with the suffix ensured. ## Example ```ts ensureSuffix('User', 'Error') // "UserError" ensureSuffix('UserError', 'Error') // "UserError" ``` ##### escapeHtml _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function escapeHtml(str): string; ``` Converts special characters into safe HTML entities. Prevents basic XSS when rendering user-provided text in the DOM. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | The string to escape. | ## Returns `string` The escaped string safe for HTML rendering. ##### escapeScriptTag _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function escapeScriptTag(str): string; ``` Escapes sequences that could prematurely close an HTML \ tag. Use this when injecting JSON data or raw strings into embedded scripts. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | The string to escape. | ## Returns `string` The escaped string safe for embedding in a script tag. ##### firstNChars _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function firstNChars( str, n, ellipsis?): string; ``` Returns the first `n` characters from a string. When truncation happens, an ellipsis is appended by default so generated labels and previews can communicate that more content exists beyond the returned segment. Non-positive and non-finite lengths return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | Source string to shorten. | | `n` | `number` | `undefined` | Maximum number of leading characters to keep. | | `ellipsis` | `boolean` | `true` | When `true`, appends `...` if truncation occurs. | ## Returns `string` The leading character slice, optionally suffixed with an ellipsis. ## Example ```ts firstNChars("Hello world", 5); // "Hello..." ``` ##### firstNWords _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function firstNWords( str, n, ellipsis?): string; ``` Returns the first `n` normalized words from a string. Word boundaries are determined by the shared `words` tokenizer, which makes this helper suitable for preview text, normalized identifiers, and compact labels derived from mixed-case or separator-heavy inputs. When truncation happens, an ellipsis is appended by default. Non-positive and non-finite lengths return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | Source string to tokenize and shorten. | | `n` | `number` | `undefined` | Maximum number of leading words to keep. | | `ellipsis` | `boolean` | `true` | When `true`, appends `...` if truncation occurs. | ## Returns `string` The leading normalized words, optionally suffixed with an ellipsis. ## Example ```ts firstNWords("HTTPServer_URL-v2", 2); // "HTTP Server..." ``` ##### fuzzySearch _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function fuzzySearch(data, query): FuzzySearchResult; ``` Performs a fuzzy search that combines structural matching with a bounded Damerau-Levenshtein distance. Ranking priority, from best to worst: 1. Exact normalized match 2. Prefix match 3. Suffix match 4. Contains match 5. Edit-distance match The edit-distance threshold adapts to the normalized query length: - `<= 4` code points: `1` - `<= 8` code points: `2` - `> 8` code points: `3` The implementation is optimized for interactive lookups: - normalization work is cached per distinct input word - structural matches short-circuit before edit-distance work - edit-distance evaluation is banded and threshold-aware - only the best three matches are retained during the scan ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `data` | readonly `string`[] | Candidate words to search. | | `query` | `string` | Search query. | ## Returns [`FuzzySearchResult`](https://vdl-plugin-sdk.varavel.com/llms/api/utils/strings/type-aliases/FuzzySearchResult.md) The best matches plus the literal exact-match flag. ## Example ```ts fuzzySearch(["User", "UserService", "SuperUser"], "user") // { // matches: ["User", "UserService", "SuperUser"], // exactMatchFound: false, // } ``` ##### indent _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function indent(input, prefix?): string; ``` Adds an indentation prefix to every non-blank line in a multi-line string. This is the inverse operation of `dedent` and is useful when injecting a generated block inside a nested structure (for example, inside a class, interface, or function body). Empty and whitespace-only lines are preserved without extra indentation to avoid introducing trailing spaces. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `input` | `string` | `undefined` | Multi-line string to indent. | | `prefix` | `string` | `" "` | String to prepend to each non-blank line. Defaults to two spaces. | ## Returns `string` The input text with indentation applied line by line. ## Examples ```ts indent("name: string;\nactive: boolean;"); // returns " name: string;\n active: boolean;" ``` ```ts indent("field string\nfield int", "\t"); // returns "\tfield string\n\tfield int" ``` ##### joinLines _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function joinLines(lines): string; ``` Joins lines into one string after removing blank entries. A line is considered blank when it is empty or contains only whitespace. Non-blank lines keep their original content and ordering. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `lines` | `string`[] | Array of lines to normalize and join. | ## Returns `string` The resulting multi-line string with blank lines removed. ## Example ```ts joinLines(["first", "", " ", "second"]); // returns "first\nsecond" ``` ##### kebabCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function kebabCase(str, upperCase?): string; ``` Converts a string to `kebab-case`. The function tokenizes the input with `words`, lowercases every token, and joins the result with hyphens. This allows mixed casing conventions and noisy separators to converge into a consistent kebab-cased string. When `upperCase` is `true`, the same tokenization and joining rules are used, but the final tokens are uppercased instead. This is useful for constants, identifiers, or file names that still need kebab separators. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | String to normalize. | | `upperCase` | `boolean` | `false` | When `true`, uppercases each token before joining. | ## Returns `string` The `kebab-case` representation of `str`. ## Examples ```ts kebabCase("UserProfileName") // "user-profile-name" ``` ```ts kebabCase("UserProfileName", true) // "USER-PROFILE-NAME" ``` ##### lastNChars _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function lastNChars( str, n, ellipsis?): string; ``` Returns the last `n` characters from a string. When truncation happens, an ellipsis is appended by default so generated labels and previews can communicate that the returned segment is partial. Non-positive and non-finite lengths return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | Source string to shorten. | | `n` | `number` | `undefined` | Maximum number of trailing characters to keep. | | `ellipsis` | `boolean` | `true` | When `true`, appends `...` if truncation occurs. | ## Returns `string` The trailing character slice, optionally suffixed with an ellipsis. ## Example ```ts lastNChars("Hello world", 5); // "world..." ``` ##### lastNWords _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function lastNWords( str, n, ellipsis?): string; ``` Returns the last `n` normalized words from a string. Word boundaries are determined by the shared `words` tokenizer, which makes this helper suitable for preview text, normalized identifiers, and compact labels derived from mixed-case or separator-heavy inputs. When truncation happens, an ellipsis is appended by default. Non-positive and non-finite lengths return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | Source string to tokenize and shorten. | | `n` | `number` | `undefined` | Maximum number of trailing words to keep. | | `ellipsis` | `boolean` | `true` | When `true`, appends `...` if truncation occurs. | ## Returns `string` The trailing normalized words, optionally suffixed with an ellipsis. ## Example ```ts lastNWords("HTTPServer_URL-v2", 2); // "URL v2..." ``` ##### limitBlankLines _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function limitBlankLines(str, maxConsecutive?): string; ``` Limits the number of consecutive blank lines in a string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | The string to process. | | `maxConsecutive` | `number` | `0` | The maximum number of consecutive blank lines allowed. Defaults to 0 (no blank lines allowed). | ## Returns `string` The string with consecutive blank lines limited. ## Examples ```ts limitBlankLines("a\n\n\nb", 2) // "a\n\n\nb" ``` ```ts limitBlankLines("a\n\n\n\nb", 2) // "a\n\n\nb" ``` ```ts limitBlankLines("a\n\n\nb", 1) // "a\n\nb" ``` ```ts limitBlankLines("a\n\n\nb", 0) // "a\nb" ``` ##### lowerCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function lowerCase(str): string; ``` Converts a string to lowercase words separated by spaces. The input is normalized with `words`, then each token is lowercased and joined using a single space. This is useful when a readable, sentence-like representation is preferred over identifier-style separators. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to normalize. | ## Returns `string` The lowercased space-separated representation of `str`. ## Example ```ts lowerCase("userProfileName") // "user profile name" ``` ##### pad _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function pad( str, length, chars?): string; ``` Pads both sides of a string until it reaches the requested length. Padding is only added when the string is shorter than `length`. The padding pattern repeats as needed and is truncated to fit exactly. When the total number of padding characters cannot be split evenly, the right side receives one more character than the left side. By default, spaces are used as padding. Pass `chars` to use a custom padding pattern. If `chars` is an empty string, the input is returned unchanged. The target length is truncated with `Math.trunc`, so decimal lengths behave predictably. Non-finite lengths are ignored and return the original string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to pad. | | `length` | `number` | Final string length to target. | | `chars?` | `string` | Optional padding characters to repeat. | ## Returns `string` `str` centered within the requested width. ## Examples ```ts pad("cat", 7) // " cat " ``` ```ts pad("cat", 8, "_-") // "_-cat_-_" ``` ##### padLeft _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function padLeft( str, length, chars?): string; ``` Pads the left side of a string until it reaches the requested length. Padding is added only when the string is shorter than `length`. The padding pattern repeats as needed and is truncated to fit exactly. By default, spaces are used as padding. Pass `chars` to use a custom padding pattern. If `chars` is an empty string, the input is returned unchanged. The target length is truncated with `Math.trunc`, and non-finite lengths are ignored by returning the original string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to pad. | | `length` | `number` | Final string length to target. | | `chars?` | `string` | Optional padding characters to repeat. | ## Returns `string` `str` padded on the left up to `length` characters. ## Example ```ts padLeft("cat", 5, "0") // "00cat" ``` ##### padRight _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function padRight( str, length, chars?): string; ``` Pads the right side of a string until it reaches the requested length. Padding is added only when the string is shorter than `length`. The padding pattern repeats as needed and is truncated to fit exactly. By default, spaces are used as padding. Pass `chars` to use a custom padding pattern. If `chars` is an empty string, the input is returned unchanged. The target length is truncated with `Math.trunc`, and non-finite lengths are ignored by returning the original string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to pad. | | `length` | `number` | Final string length to target. | | `chars?` | `string` | Optional padding characters to repeat. | ## Returns `string` `str` padded on the right up to `length` characters. ## Example ```ts padRight("cat", 5, "0") // "cat00" ``` ##### pascalCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function pascalCase(str): string; ``` Converts a string to `PascalCase`. The input is first tokenized with `words`, allowing the function to accept a wide range of source formats such as `snake_case`, `kebab-case`, spaced strings, `camelCase`, or acronym-heavy identifiers. Every token is normalized to an initial uppercase letter followed by a lowercased remainder. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to normalize. | ## Returns `string` The `PascalCase` representation of `str`. ## Example ```ts pascalCase("user_profile-name") // "UserProfileName" ``` ##### pluralize _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function pluralize( word, count?, inclusive?): string; ``` Pluralize or singularize a word based on a count. This function uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `word` | `string` | The word to pluralize or singularize. | | `count?` | `number` | Optional number indicating how many of the word exist. - If `1`, returns the singular form. - If other than `1`, returns the plural form. | | `inclusive?` | `boolean` | Whether to prefix the result with the number (e.g., "3 ducks"). Defaults to `false`. | ## Returns `string` The pluralized or singularized word, optionally prefixed by the count. ## Example ```ts pluralize('test') // "tests" pluralize('test', 1) // "test" pluralize('test', 5, true) // "5 tests" pluralize('person', 2) // "people" ``` ## See Powered by `pluralize` (MIT License): [https://github.com/plurals/pluralize](https://github.com/plurals/pluralize) ##### slugify _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function slugify(str): string; ``` Converts text into a stricter kebab-style slug. This helper is intended for identifiers that must be more conservative than regular `kebabCase`, such as URL slugs, file-safe names, anchors, and stable external keys. Diacritics are flattened to their ASCII counterparts, unsupported characters are removed, and any surrounding hyphens are discarded from the final value. Empty or symbol-only inputs return an empty string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | Text to normalize into slug form. | ## Returns `string` A lowercase slug containing only ASCII letters, digits, and hyphens. ## Example ```ts slugify("Canción Número 1"); // "cancion-numero-1" ``` ##### snakeCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function snakeCase(str, upperCase?): string; ``` Converts a string to `snake_case`. The input is tokenized with `words`, each token is lowercased, and the final string is joined with underscores. This keeps the behavior aligned with the shared SDK word-splitting rules. When `upperCase` is `true`, the same tokenization and joining behavior is preserved but the final tokens are uppercased instead. This is useful for environment variable names and constant-like identifiers. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `str` | `string` | `undefined` | String to normalize. | | `upperCase` | `boolean` | `false` | When `true`, uppercases each token before joining. | ## Returns `string` The `snake_case` representation of `str`. ## Examples ```ts snakeCase("UserProfileName") // "user_profile_name" ``` ```ts snakeCase("UserProfileName", true) // "USER_PROFILE_NAME" ``` ##### trim _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function trim(str, chars?): string; ``` Removes matching characters from both ends of a string. By default, the function trims leading and trailing whitespace using the platform's built-in whitespace semantics. When `chars` is provided, only those characters are trimmed from the start and end of the string. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries. For example, `trim("__value--", "_-")` and `trim("__value--", ["_", "-"])` both return `"value"`. Characters are removed only at the outer edges; matching characters inside the string are preserved. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to trim. | | `chars?` | `string` \| readonly `string`[] | Optional characters to remove instead of whitespace. | ## Returns `string` A copy of `str` without the matching leading and trailing characters. ## Examples ```ts trim(" hello ") // "hello" ``` ```ts trim("__hello--", ["_", "-"]) // "hello" ``` ##### trimEnd _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function trimEnd(str, chars?): string; ``` Removes matching characters from the end of a string. By default, the function trims trailing whitespace using the platform's built-in whitespace semantics. When `chars` is provided, only those characters are removed from the end. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries. Matching characters that appear earlier in the string are preserved. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to trim. | | `chars?` | `string` \| readonly `string`[] | Optional characters to remove instead of whitespace. | ## Returns `string` A copy of `str` without the matching trailing characters. ## Examples ```ts trimEnd(" hello ") // " hello" ``` ```ts trimEnd("__hello__", "_") // "__hello" ``` ##### trimStart _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function trimStart(str, chars?): string; ``` Removes matching characters from the start of a string. By default, the function trims leading whitespace using the platform's built-in whitespace semantics. When `chars` is provided, only those characters are removed from the start. A string value is interpreted as a set of individual characters, and an array combines all characters from all entries. Matching characters that appear later in the string are preserved. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to trim. | | `chars?` | `string` \| readonly `string`[] | Optional characters to remove instead of whitespace. | ## Returns `string` A copy of `str` without the matching leading characters. ## Examples ```ts trimStart(" hello ") // "hello " ``` ```ts trimStart("__hello__", "_") // "hello__" ``` ##### upperCase _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function upperCase(str): string; ``` Converts a string to uppercase words separated by spaces. The input is normalized with `words`, then each token is uppercased and joined using a single space. This is useful for readable labels, headings, or enum-like display values derived from mixed naming conventions. Empty or separator-only inputs return an empty string. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to normalize. | ## Returns `string` The uppercased space-separated representation of `str`. ## Example ```ts upperCase("userProfileName") // "USER PROFILE NAME" ``` ##### words _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts function words(str): string[]; ``` Splits a string into normalized word tokens. The function preserves the current tokenization rules used by the SDK: it inserts spaces at camelCase and acronym-to-word boundaries, converts any non-alphanumeric separator to a space, trims the result, and then splits on whitespace. This makes it suitable for inputs such as `camelCase`, `PascalCase`, `HTTPServer`, `snake_case`, `kebab-case`, and mixed separator variants. Empty or separator-only inputs return an empty array. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `str` | `string` | String to tokenize. | ## Returns `string`[] An array of normalized word tokens. ## Example ```ts words("HTTPServer_error-code"); // returns ["HTTP", "Server", "error", "code"] ``` #### Type Aliases ##### FuzzySearchResult _Import from `@varavel/vdl-plugin-sdk/utils/strings`._ ```ts type FuzzySearchResult = object; ``` Describes the outcome of a fuzzy search. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `exactMatchFound` | `boolean` | Indicates whether the original query existed in the input as an exact, case-sensitive, non-normalized literal. | | `matches` | `string`[] | Up to three candidate matches ordered by relevance. | ### YAML import: `@varavel/vdl-plugin-sdk/utils/yaml` _Import from `@varavel/vdl-plugin-sdk/utils/yaml`._ ## Functions - [parse](https://vdl-plugin-sdk.varavel.com/llms/api/utils/yaml/functions/parse.md) - [stringify](https://vdl-plugin-sdk.varavel.com/llms/api/utils/yaml/functions/stringify.md) #### Functions ##### parse _Import from `@varavel/vdl-plugin-sdk/utils/yaml`._ ```ts function parse(text): T; ``` Parses a YAML document string into a JavaScript value. ## Type Parameters | Type Parameter | Default type | | :------ | :------ | | `T` | `unknown` | ## Parameters | Parameter | Type | | :------ | :------ | | `text` | `string` | ## Returns `T` ## See Powered by `yaml` (ISC): [https://github.com/eemeli/yaml](https://github.com/eemeli/yaml) ##### stringify _Import from `@varavel/vdl-plugin-sdk/utils/yaml`._ ```ts function stringify(value): string; ``` Serializes a JavaScript value into a YAML document string. ## Parameters | Parameter | Type | | :------ | :------ | | `value` | `unknown` | ## Returns `string` ## See Powered by `yaml` (ISC): [https://github.com/eemeli/yaml](https://github.com/eemeli/yaml) ### TOML import: `@varavel/vdl-plugin-sdk/utils/toml` _Import from `@varavel/vdl-plugin-sdk/utils/toml`._ ## Functions - [parse](https://vdl-plugin-sdk.varavel.com/llms/api/utils/toml/functions/parse.md) - [stringify](https://vdl-plugin-sdk.varavel.com/llms/api/utils/toml/functions/stringify.md) #### Functions ##### parse _Import from `@varavel/vdl-plugin-sdk/utils/toml`._ ```ts function parse(text): T; ``` Parses a TOML document string into a JavaScript object. ## Type Parameters | Type Parameter | Default type | | :------ | :------ | | `T` | `Record`\<`string`, `unknown`\> | ## Parameters | Parameter | Type | | :------ | :------ | | `text` | `string` | ## Returns `T` ## See Powered by `smol-toml` (BSD-3-Clause): [https://github.com/squirrelchat/smol-toml](https://github.com/squirrelchat/smol-toml) ##### stringify _Import from `@varavel/vdl-plugin-sdk/utils/toml`._ ```ts function stringify(value): string; ``` Serializes a JavaScript object into a TOML document string. ## Parameters | Parameter | Type | | :------ | :------ | | `value` | `Record`\<`string`, `unknown`\> | ## Returns `string` ## See Powered by `smol-toml` (BSD-3-Clause): [https://github.com/squirrelchat/smol-toml](https://github.com/squirrelchat/smol-toml) ### Arrays import: `@varavel/vdl-plugin-sdk/utils/arrays` _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ## Functions - [at](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/at.md) - [chunk](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/chunk.md) - [compact](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/compact.md) - [countBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/countBy.md) - [difference](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/difference.md) - [differenceBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/differenceBy.md) - [differenceWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/differenceWith.md) - [drop](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/drop.md) - [dropRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/dropRight.md) - [dropRightWhile](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/dropRightWhile.md) - [dropWhile](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/dropWhile.md) - [flatMap](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/flatMap.md) - [flatMapDeep](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/flatMapDeep.md) - [flatten](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/flatten.md) - [flattenDeep](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/flattenDeep.md) - [groupBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/groupBy.md) - [head](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/head.md) - [initial](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/initial.md) - [intersection](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/intersection.md) - [intersectionBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/intersectionBy.md) - [intersectionWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/intersectionWith.md) - [isSubset](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/isSubset.md) - [isSubsetWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/isSubsetWith.md) - [keyBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/keyBy.md) - [last](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/last.md) - [maxBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/maxBy.md) - [minBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/minBy.md) - [orderBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/orderBy.md) - [partition](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/partition.md) - [sortBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/sortBy.md) - [tail](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/tail.md) - [take](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/take.md) - [takeRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/takeRight.md) - [takeRightWhile](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/takeRightWhile.md) - [takeWhile](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/takeWhile.md) - [toFilled](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/toFilled.md) - [union](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/union.md) - [unionBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/unionBy.md) - [unionWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/unionWith.md) - [uniq](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/uniq.md) - [uniqBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/uniqBy.md) - [uniqWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/uniqWith.md) - [unzip](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/unzip.md) - [unzipWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/unzipWith.md) - [windowed](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/windowed.md) - [without](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/without.md) - [xor](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/xor.md) - [xorBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/xorBy.md) - [xorWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/xorWith.md) - [zip](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/zip.md) - [zipObject](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/zipObject.md) - [zipWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/arrays/functions/zipWith.md) #### Functions ##### at _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function at(arr, indices): T[]; ``` Retrieves elements from an array at the specified indices. This function supports negative indices, which count from the end of the array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to retrieve elements from. | | `indices` | `number`[] | An array of indices specifying the positions of elements to retrieve. | ## Returns `T`[] A new array containing the elements at the specified indices. ## Example ```ts const numbers = [10, 20, 30, 40, 50]; const result = at(numbers, [1, 3, 4]); console.log(result); // [20, 40, 50] ``` ##### chunk _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function chunk(arr, size): T[][]; ``` Splits an array into smaller arrays of a specified length. This function takes an input array and divides it into multiple smaller arrays, each of a specified length. If the input array cannot be evenly divided, the final sub-array will contain the remaining elements. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to be chunked into smaller arrays. | | `size` | `number` | The size of each smaller array. Must be a positive integer. | ## Returns `T`[][] A two-dimensional array where each sub-array has a maximum length of `size`. ## Throws Throws an error if `size` is not a positive integer. ## Examples ```ts // Splits an array of numbers into sub-arrays of length 2 chunk([1, 2, 3, 4, 5], 2); // Returns: [[1, 2], [3, 4], [5]] ``` ```ts // Splits an array of strings into sub-arrays of length 3 chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3); // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']] ``` ##### compact _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function compact(arr): Exclude[]; ``` Removes falsey values (false, null, 0, -0, 0n, '', undefined, NaN) from an array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The input array to remove falsey values. | ## Returns `Exclude`\<`T`, `false` \| `""` \| `0` \| `0n` \| `null` \| `undefined`\>[] - A new array with all falsey values removed. ## Example ```ts compact([0, -0, 0n, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]); Returns: [1, 2, 3, 4, 5] ``` ##### countBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function countBy(arr, mapper): Record; ``` Count the occurrences of each item in an array based on a transformation function. This function takes an array and a transformation function that converts each item in the array to a key. It then counts the occurrences of each transformed item and returns an object with the transformed items as keys and the counts as values. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the items in the input array. | | `K` *extends* `PropertyKey` | The type of keys. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The input array to count occurrences. | | `mapper` | (`item`, `index`, `array`) => `K` | The transformation function that maps each item, its index, and the array to a key. | ## Returns `Record`\<`K`, `number`\> An object containing the transformed items as keys and the counts as values. ## Examples ```ts const array = ['a', 'b', 'c', 'a', 'b', 'a']; const result = countBy(array, x => x); // result will be { a: 3, b: 2, c: 1 } ``` ```ts const array = [1, 2, 3, 4, 5]; const result = countBy(array, item => item % 2 === 0 ? 'even' : 'odd'); // result will be { odd: 3, even: 2 } ``` ```ts // Using index parameter const array = ['a', 'b', 'c', 'd']; const result = countBy(array, (item, index) => index < 2 ? 'first' : 'rest'); // result will be { first: 2, rest: 2 } ``` ##### difference _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function difference(firstArr, secondArr): T[]; ``` Computes the difference between two arrays. This function takes two arrays and returns a new array containing the elements that are present in the first array but not in the second array. It effectively filters out any elements from the first array that also appear in the second array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The array from which to derive the difference. This is the primary array from which elements will be compared and filtered. | | `secondArr` | readonly `T`[] | The array containing elements to be excluded from the first array. Each element in this array will be checked against the first array, and if a match is found, that element will be excluded from the result. | ## Returns `T`[] A new array containing the elements that are present in the first array but not in the second array. ## Example ```ts const array1 = [1, 2, 3, 4, 5]; const array2 = [2, 4]; const result = difference(array1, array2); // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result. ``` ##### differenceBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function differenceBy( firstArr, secondArr, mapper): T[]; ``` Computes the difference between two arrays after mapping their elements through a provided function. This function takes two arrays and a mapper function. It returns a new array containing the elements that are present in the first array but not in the second array, based on the identity calculated by the mapper function. Essentially, it filters out any elements from the first array that, when mapped, match an element in the mapped version of the second array. ## Type Parameters | Type Parameter | | :------ | | `T` | | `U` | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The primary array from which to derive the difference. | | `secondArr` | readonly `U`[] | The array containing elements to be excluded from the first array. | | `mapper` | (`value`) => `unknown` | The function to map the elements of both arrays. This function is applied to each element in both arrays, and the comparison is made based on the mapped values. | ## Returns `T`[] A new array containing the elements from the first array that do not have a corresponding mapped identity in the second array. ## Examples ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [{ id: 2 }, { id: 4 }]; const mapper = item => item.id; const result = differenceBy(array1, array2, mapper); // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result. ``` ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [2, 4]; const mapper = item => (typeof item === 'object' ? item.id : item); const result = differenceBy(array1, array2, mapper); // result will be [{ id: 1 }, { id: 3 }] since 2 is present in both arrays after mapping, and is excluded from the result. ``` ##### differenceWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function differenceWith( firstArr, secondArr, areItemsEqual): T[]; ``` Computes the difference between two arrays based on a custom equality function. This function takes two arrays and a custom comparison function. It returns a new array containing the elements that are present in the first array but not in the second array. The comparison to determine if elements are equal is made using the provided custom function. ## Type Parameters | Type Parameter | | :------ | | `T` | | `U` | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The array from which to get the difference. | | `secondArr` | readonly `U`[] | The array containing elements to exclude from the first array. | | `areItemsEqual` | (`x`, `y`) => `boolean` | A function to determine if two items are equal. | ## Returns `T`[] A new array containing the elements from the first array that do not match any elements in the second array according to the custom equality function. ## Examples ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [{ id: 2 }, { id: 4 }]; const areItemsEqual = (a, b) => a.id === b.id; const result = differenceWith(array1, array2, areItemsEqual); // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result. ``` ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [2, 4]; const areItemsEqual = (a, b) => a.id === b; const result = differenceWith(array1, array2, areItemsEqual); // result will be [{ id: 1 }, { id: 3 }] since the element with id 2 is considered equal to the second array's element and is excluded from the result. ``` ##### drop _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function drop(arr, itemsCount): T[]; ``` Removes a specified number of elements from the beginning of an array and returns the rest. This function takes an array and a number, and returns a new array with the specified number of elements removed from the start. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to drop elements. | | `itemsCount` | `number` | The number of elements to drop from the beginning of the array. | ## Returns `T`[] A new array with the specified number of elements removed from the start. ## Example ```ts const array = [1, 2, 3, 4, 5]; const result = drop(array, 2); // result will be [3, 4, 5] since the first two elements are dropped. ``` ##### dropRight _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function dropRight(arr, itemsCount): T[]; ``` Removes a specified number of elements from the end of an array and returns the rest. This function takes an array and a number, and returns a new array with the specified number of elements removed from the end. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to drop elements. | | `itemsCount` | `number` | The number of elements to drop from the end of the array. | ## Returns `T`[] A new array with the specified number of elements removed from the end. ## Example ```ts const array = [1, 2, 3, 4, 5]; const result = dropRight(array, 2); // result will be [1, 2, 3] since the last two elements are dropped. ``` ##### dropRightWhile _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function dropRightWhile(arr, canContinueDropping): T[]; ``` Removes elements from the end of an array until the predicate returns false. This function iterates over an array from the end and drops elements until the provided predicate function returns false. It then returns a new array with the remaining elements. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to drop elements. | | `canContinueDropping` | (`item`, `index`, `arr`) => `boolean` | A predicate function that determines whether to continue dropping elements. The function is called with each element from the end, and dropping continues as long as it returns true. | ## Returns `T`[] A new array with the elements remaining after the predicate returns false. ## Example ```ts const array = [1, 2, 3, 4, 5]; const result = dropRightWhile(array, x => x > 3); // result will be [1, 2, 3] since elements greater than 3 are dropped from the end. ``` ##### dropWhile _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function dropWhile(arr, canContinueDropping): T[]; ``` Removes elements from the beginning of an array until the predicate returns false. This function iterates over an array and drops elements from the start until the provided predicate function returns false. It then returns a new array with the remaining elements. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to drop elements. | | `canContinueDropping` | (`item`, `index`, `arr`) => `boolean` | A predicate function that determines whether to continue dropping elements. The function is called with each element, and dropping continues as long as it returns true. | ## Returns `T`[] A new array with the elements remaining after the predicate returns false. ## Example ```ts const array = [1, 2, 3, 4, 5]; const result = dropWhile(array, x => x < 3); // result will be [3, 4, 5] since elements less than 3 are dropped. ``` ##### flatMap _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function flatMap( arr, iteratee, depth?): FlatArray[]; ``` Maps each element in the array using the iteratee function and flattens the result up to the specified depth. ## Type Parameters | Type Parameter | Default type | Description | | :------ | :------ | :------ | | `T` | - | The type of elements within the array. | | `U` | - | The type of elements within the returned array from the iteratee function. | | `D` *extends* `number` | `1` | The depth to which the array should be flattened. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to flatten. | | `iteratee` | (`item`, `index`, `array`) => `U` | The function that produces the new array elements. It receives the element, its index, and the array. | | `depth?` | `D` | The depth level specifying how deep a nested array structure should be flattened. Defaults to 1. | ## Returns `FlatArray`\<`U`[], `D`\>[] The new array with the mapped and flattened elements. ## Example ```ts const arr = [1, 2, 3]; flatMap(arr, (item: number) => [item, item]); // [1, 1, 2, 2, 3, 3] flatMap(arr, (item: number) => [[item, item]], 2); // [1, 1, 2, 2, 3, 3] ``` ##### flatMapDeep _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function flatMapDeep(arr, iteratee): ExtractNestedArrayType[]; ``` Recursively maps each element in an array using a provided iteratee function and then deeply flattens the resulting array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements within the array. | | `U` | The type of elements within the returned array from the iteratee function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to flatten. | | `iteratee` | (`item`, `index`, `array`) => `U` | The function that produces the new array elements. It receives the element, its index, and the array. | ## Returns `ExtractNestedArrayType`\<`U`\>[] A new array that has been flattened. ## Example ```ts const result = flatMapDeep([1, 2, 3], n => [[n, n]]); // [1, 1, 2, 2, 3, 3] ``` ##### flatten _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function flatten(arr, depth?): FlatArray[]; ``` Flattens an array up to the specified depth. ## Type Parameters | Type Parameter | Default type | Description | | :------ | :------ | :------ | | `T` | - | The type of elements within the array. | | `D` *extends* `number` | `1` | The depth to which the array should be flattened. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to flatten. | | `depth?` | `D` | The depth level specifying how deep a nested array structure should be flattened. Defaults to 1. | ## Returns `FlatArray`\<`T`[], `D`\>[] A new array that has been flattened. ## Example ```ts const arr = flatten([1, [2, 3], [4, [5, 6]]], 1); // Returns: [1, 2, 3, 4, [5, 6]] const arr = flatten([1, [2, 3], [4, [5, 6]]], 2); // Returns: [1, 2, 3, 4, 5, 6] ``` ##### flattenDeep _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function flattenDeep(arr): ExtractNestedArrayType[]; ``` Flattens all depths of a nested array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements within the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to flatten. | ## Returns `ExtractNestedArrayType`\<`T`\>[] A new array that has been flattened. ## Example ```ts const arr = flattenDeep([1, [2, [3]], [4, [5, 6]]]); // Returns: [1, 2, 3, 4, 5, 6] ``` ##### groupBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function groupBy(arr, getKeyFromItem): Record; ``` Groups the elements of an array based on a provided key-generating function. This function takes an array and a function that generates a key from each element. It returns an object where the keys are the generated keys and the values are arrays of elements that share the same key. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | | `K` *extends* `PropertyKey` | The type of keys. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to group. | | `getKeyFromItem` | (`item`, `index`, `array`) => `K` | A function that generates a key from an element, its index, and the array. | ## Returns `Record`\<`K`, `T`[]\> An object where each key is associated with an array of elements that share that key. ## Examples ```ts const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, { category: 'vegetable', name: 'carrot' } ]; const result = groupBy(array, item => item.category); // result will be: // { // fruit: [ // { category: 'fruit', name: 'apple' }, // { category: 'fruit', name: 'banana' } // ], // vegetable: [ // { category: 'vegetable', name: 'carrot' } // ] // } ``` ```ts // Using index parameter const items = ['a', 'b', 'c', 'd']; const result = groupBy(items, (item, index) => index % 2 === 0 ? 'even' : 'odd'); // result will be: { even: ['a', 'c'], odd: ['b', 'd'] } ``` ##### head _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function head(arr): T; ``` Returns the first element of an array. This function takes an array and returns the first element of the array. If the array is empty, the function returns `undefined`. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`, `T`\] | A non-empty array from which to get the first element. | ### Returns `T` The first element of the array. ### Example ```ts const arr = [1, 2, 3]; const firstElement = head(arr); // firstElement will be 1 ``` ## Call Signature ```ts function head(arr): T | undefined; ``` Returns the first element of an array or `undefined` if the array is empty. This function takes an array and returns the first element of the array. If the array is empty, the function returns `undefined`. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to get the first element. | ### Returns `T` \| `undefined` The first element of the array, or `undefined` if the array is empty. ### Example ```ts const emptyArr: number[] = []; const noElement = head(emptyArr); // noElement will be undefined ``` ##### initial _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function initial(arr): []; ``` Returns an empty array when the input is a tuple containing exactly one element. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the single element. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`\] | A tuple containing exactly one element. | ### Returns \[\] An empty array since there is only one element. ### Example ```ts const array = [100] as const; const result = initial(array); // result will be [] ``` ## Call Signature ```ts function initial(arr): []; ``` Returns an empty array when the input array is empty. ### Parameters | Parameter | Type | | :------ | :------ | | `arr` | readonly \[\] | ### Returns \[\] Always returns an empty array for an empty input. ### Example ```ts const array = [] as const; const result = initial(array); // result will be [] ``` ## Call Signature ```ts function initial(arr): T[]; ``` Returns a new array containing all elements except the last one from a tuple with multiple elements. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The types of the initial elements. | | `U` | The type of the last element in the tuple. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`, `U`\] | A tuple with one or more elements. | ### Returns `T`[] A new array containing all but the last element of the tuple. ### Example ```ts const array = ['apple', 'banana', 'cherry'] as const; const result = initial(array); // result will be ['apple', 'banana'] ``` ## Call Signature ```ts function initial(arr): T[]; ``` Returns a new array containing all elements except the last one from the input array. If the input array is empty or has only one element, the function returns an empty array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The input array. | ### Returns `T`[] A new array containing all but the last element of the input array. ### Example ```ts const arr = [1, 2, 3, 4]; const result = initial(arr); // result will be [1, 2, 3] ``` ##### intersection _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function intersection(firstArr, secondArr): T[]; ``` Returns the intersection of two arrays. This function takes two arrays and returns a new array containing the elements that are present in both arrays. It effectively filters out any elements from the first array that are not found in the second array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The first array to compare. | | `secondArr` | readonly `T`[] | The second array to compare. | ## Returns `T`[] A new array containing the elements that are present in both arrays. ## Example ```ts const array1 = [1, 2, 3, 4, 5]; const array2 = [3, 4, 5, 6, 7]; const result = intersection(array1, array2); // result will be [3, 4, 5] since these elements are in both arrays. ``` ##### intersectionBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function intersectionBy( firstArr, secondArr, mapper): T[]; ``` Returns the intersection of two arrays based on a mapping function. This function takes two arrays and a mapping function. It returns a new array containing the elements from the first array that, when mapped using the provided function, have matching mapped elements in the second array. It effectively filters out any elements from the first array that do not have corresponding mapped values in the second array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `U` | The type of elements in the second array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The first array to compare. | | `secondArr` | readonly `U`[] | The second array to compare. | | `mapper` | (`item`) => `unknown` | A function to map the elements of both arrays for comparison. | ## Returns `T`[] A new array containing the elements from the first array that have corresponding mapped values in the second array. ## Examples ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [{ id: 2 }, { id: 4 }]; const mapper = item => item.id; const result = intersectionBy(array1, array2, mapper); // result will be [{ id: 2 }] since only this element has a matching id in both arrays. ``` ```ts const array1 = [ { id: 1, name: 'jane' }, { id: 2, name: 'amy' }, { id: 3, name: 'michael' }, ]; const array2 = [2, 4]; const mapper = item => (typeof item === 'object' ? item.id : item); const result = intersectionBy(array1, array2, mapper); // result will be [{ id: 2, name: 'amy' }] since only this element has a matching id that is equal to seconds array's element. ``` ##### intersectionWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function intersectionWith( firstArr, secondArr, areItemsEqual): T[]; ``` Returns the intersection of two arrays based on a custom equality function. This function takes two arrays and a custom equality function. It returns a new array containing the elements from the first array that have matching elements in the second array, as determined by the custom equality function. It effectively filters out any elements from the first array that do not have corresponding matches in the second array according to the equality function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `U` | The type of elements in the second array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `firstArr` | readonly `T`[] | The first array to compare. | | `secondArr` | readonly `U`[] | The second array to compare. | | `areItemsEqual` | (`x`, `y`) => `boolean` | A custom function to determine if two elements are equal. This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise. | ## Returns `T`[] A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function. ## Examples ```ts const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]; const array2 = [{ id: 2 }, { id: 4 }]; const areItemsEqual = (a, b) => a.id === b.id; const result = intersectionWith(array1, array2, areItemsEqual); // result will be [{ id: 2 }] since this element has a matching id in both arrays. ``` ```ts const array1 = [ { id: 1, name: 'jane' }, { id: 2, name: 'amy' }, { id: 3, name: 'michael' }, ]; const array2 = [2, 4]; const areItemsEqual = (a, b) => a.id === b; const result = intersectionWith(array1, array2, areItemsEqual); // result will be [{ id: 2, name: 'amy' }] since this element has a matching id that is equal to seconds array's element. ``` ##### isSubset _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function isSubset(superset, subset): boolean; ``` Checks if the `subset` array is entirely contained within the `superset` array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements contained in the arrays. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `superset` | readonly `T`[] | The array that may contain all elements of the subset. | | `subset` | readonly `T`[] | The array to check against the superset. | ## Returns `boolean` - Returns `true` if all elements of the `subset` are present in the `superset`, otherwise returns `false`. ## Examples ```typescript const superset = [1, 2, 3, 4, 5]; const subset = [2, 3, 4]; isSubset(superset, subset); // true ``` ```typescript const superset = ['a', 'b', 'c']; const subset = ['a', 'd']; isSubset(superset, subset); // false ``` ##### isSubsetWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function isSubsetWith( superset, subset, areItemsEqual): boolean; ``` Checks if the `subset` array is entirely contained within the `superset` array based on a custom equality function. This function takes two arrays and a custom comparison function. It returns a boolean indicating whether all elements in the subset array are present in the superset array, as determined by the provided custom equality function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements contained in the arrays. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `superset` | readonly `T`[] | The array that may contain all elements of the subset. | | `subset` | readonly `T`[] | The array to check against the superset. | | `areItemsEqual` | (`x`, `y`) => `boolean` | A function to determine if two items are equal. | ## Returns `boolean` - Returns `true` if all elements of the subset are present in the superset according to the custom equality function, otherwise returns `false`. ## Examples ```typescript const superset = [{ id: 1 }, { id: 2 }, { id: 3 }]; const subset = [{ id: 2 }, { id: 1 }]; const areItemsEqual = (a, b) => a.id === b.id; isSubsetWith(superset, subset, areItemsEqual); // true ``` ```typescript const superset = [{ id: 1 }, { id: 2 }, { id: 3 }]; const subset = [{ id: 4 }]; const areItemsEqual = (a, b) => a.id === b.id; isSubsetWith(superset, subset, areItemsEqual); // false ``` ##### keyBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function keyBy(arr, getKeyFromItem): Record; ``` Maps each element of an array based on a provided key-generating function. This function takes an array and a function that generates a key from each element. It returns an object where the keys are the generated keys and the values are the corresponding elements. If there are multiple elements generating the same key, the last element among them is used as the value. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | | `K` *extends* `PropertyKey` | The type of keys. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array of elements to be mapped. | | `getKeyFromItem` | (`item`, `index`, `array`) => `K` | A function that generates a key from an element, its index, and the array. | ## Returns `Record`\<`K`, `T`\> An object where keys are mapped to each element of an array. ## Examples ```ts const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, { category: 'vegetable', name: 'carrot' } ]; const result = keyBy(array, item => item.category); // result will be: // { // fruit: { category: 'fruit', name: 'banana' }, // vegetable: { category: 'vegetable', name: 'carrot' } // } ``` ```ts // Using index parameter const items = ['a', 'b', 'c']; const result = keyBy(items, (item, index) => index); // result will be: { 0: 'a', 1: 'b', 2: 'c' } ``` ##### last _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function last(arr): T; ``` Returns the last element of an array. This function takes an array and returns the last element of the array. If the array is empty, the function returns `undefined`. Unlike some implementations, this function is optimized for performance by directly accessing the last index of the array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`, `T`\] | The array from which to get the last element. | ### Returns `T` The last element of the array, or `undefined` if the array is empty. ### Example ```ts const arr = [1, 2, 3]; const lastElement = last(arr); // lastElement will be 3 const emptyArr: number[] = []; const noElement = last(emptyArr); // noElement will be undefined ``` ## Call Signature ```ts function last(arr): T | undefined; ``` Returns the last element of an array. This function takes an array and returns the last element of the array. If the array is empty, the function returns `undefined`. Unlike some implementations, this function is optimized for performance by directly accessing the last index of the array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array from which to get the last element. | ### Returns `T` \| `undefined` The last element of the array, or `undefined` if the array is empty. ### Example ```ts const arr = [1, 2, 3]; const lastElement = last(arr); // lastElement will be 3 const emptyArr: number[] = []; const noElement = last(emptyArr); // noElement will be undefined ``` ##### maxBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function maxBy(items, getValue): T; ``` Finds the element in an array that has the maximum value when applying the `getValue` function to each element. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly \[`T`, `T`\] | The nonempty array of elements to search. | | `getValue` | (`element`, `index`, `array`) => `number` | A function that selects a numeric value from each element. | ### Returns `T` The element with the maximum value as determined by the `getValue` function. ### Example ```ts maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } maxBy([], x => x.a); // Returns: undefined maxBy( [ { name: 'john', age: 30 }, { name: 'jane', age: 28 }, { name: 'joe', age: 26 }, ], x => x.age ); // Returns: { name: 'john', age: 30 } ``` ## Call Signature ```ts function maxBy(items, getValue): T | undefined; ``` Finds the element in an array that has the maximum value when applying the `getValue` function to each element. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly `T`[] | The array of elements to search. | | `getValue` | (`element`, `index`, `array`) => `number` | A function that selects a numeric value from each element. | ### Returns `T` \| `undefined` The element with the maximum value as determined by the `getValue` function, or `undefined` if the array is empty. ### Example ```ts maxBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 3 } maxBy([], x => x.a); // Returns: undefined maxBy( [ { name: 'john', age: 30 }, { name: 'jane', age: 28 }, { name: 'joe', age: 26 }, ], x => x.age ); // Returns: { name: 'john', age: 30 } ``` ##### minBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function minBy(items, getValue): T; ``` Finds the element in an array that has the minimum value when applying the `getValue` function to each element. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly \[`T`, `T`\] | The nonempty array of elements to search. | | `getValue` | (`element`, `index`, `array`) => `number` | A function that selects a numeric value from each element. | ### Returns `T` The element with the minimum value as determined by the `getValue` function. ### Example ```ts minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 } minBy([], x => x.a); // Returns: undefined minBy( [ { name: 'john', age: 30 }, { name: 'jane', age: 28 }, { name: 'joe', age: 26 }, ], x => x.age ); // Returns: { name: 'joe', age: 26 } ``` ## Call Signature ```ts function minBy(items, getValue): T | undefined; ``` Finds the element in an array that has the minimum value when applying the `getValue` function to each element. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly `T`[] | The array of elements to search. | | `getValue` | (`element`, `index`, `array`) => `number` | A function that selects a numeric value from each element. | ### Returns `T` \| `undefined` The element with the minimum value as determined by the `getValue` function, or `undefined` if the array is empty. ### Example ```ts minBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: { a: 1 } minBy([], x => x.a); // Returns: undefined minBy( [ { name: 'john', age: 30 }, { name: 'jane', age: 28 }, { name: 'joe', age: 26 }, ], x => x.age ); // Returns: { name: 'joe', age: 26 } ``` ##### orderBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function orderBy( arr, criteria, orders): T[]; ``` Sorts an array of objects based on the given `criteria` and their corresponding order directions. - If you provide keys, it sorts the objects by the values of those keys. - If you provide functions, it sorts based on the values returned by those functions. The function returns the array of objects sorted in corresponding order directions. If two objects have the same value for the current criterion, it uses the next criterion to determine their order. If the number of orders is less than the number of criteria, it uses the last order for the rest of the criteria. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `object` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array of objects to be sorted. | | `criteria` | (((`item`) => `unknown`) \| keyof `T`)[] | The criteria for sorting. This can be an array of object keys or functions that return values used for sorting. | | `orders` | (`"asc"` \| `"desc"`)[] | An array of order directions ('asc' for ascending or 'desc' for descending). | ## Returns `T`[] - The sorted array. ## Example ```ts // Sort an array of objects by 'user' in ascending order and 'age' in descending order. const users = [ { user: 'fred', age: 48 }, { user: 'barney', age: 34 }, { user: 'fred', age: 40 }, { user: 'barney', age: 36 }, ]; const result = orderBy(users, [obj => obj.user, 'age'], ['asc', 'desc']); // result will be: // [ // { user: 'barney', age: 36 }, // { user: 'barney', age: 34 }, // { user: 'fred', age: 48 }, // { user: 'fred', age: 40 }, // ] ``` ##### partition _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function partition(arr, isInTruthy): [U[], Exclude[]]; ``` Splits an array into two groups based on a predicate function. This function takes an array and a predicate function. It returns a tuple of two arrays: the first array contains elements for which the predicate function returns true, and the second array contains elements for which the predicate function returns false. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | | `U` | The type being filtered for. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to partition. | | `isInTruthy` | (`value`, `index`, `array`) => `value is U` | A type guard that determines whether an element should be placed in the truthy array. The function is called with each element of the array and its index. | ### Returns \[`U`[], `Exclude`\<`T`, `U`\>[]\] A tuple containing two arrays: the first array contains elements for which the predicate returned true, and the second array contains elements for which the predicate returned false. ### Example ```ts const array = [1, 2, 3, 4] as const; const isEven = (x: number): x is 2 | 4 => x % 2 === 0; const [even, odd]: [(2 | 4)[], (2 | 4)[]] = partition(array, isEven); // even will be [2, 4], and odd will be [1, 3] ``` ## Call Signature ```ts function partition(arr, isInTruthy): [T[], T[]]; ``` Splits an array into two groups based on a predicate function. This function takes an array and a predicate function. It returns a tuple of two arrays: the first array contains elements for which the predicate function returns true, and the second array contains elements for which the predicate function returns false. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to partition. | | `isInTruthy` | (`value`, `index`, `array`) => `boolean` | A predicate function that determines whether an element should be placed in the truthy array. The function is called with each element of the array and its index. | ### Returns \[`T`[], `T`[]\] A tuple containing two arrays: the first array contains elements for which the predicate returned true, and the second array contains elements for which the predicate returned false. ### Example ```ts const array = [1, 2, 3, 4, 5]; const isEven = x => x % 2 === 0; const [even, odd] = partition(array, isEven); // even will be [2, 4], and odd will be [1, 3, 5] ``` ##### sortBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function sortBy(arr, criteria): T[]; ``` Sorts an array of objects based on the given `criteria`. - If you provide keys, it sorts the objects by the values of those keys. - If you provide functions, it sorts based on the values returned by those functions. The function returns the array of objects sorted in ascending order. If two objects have the same value for the current criterion, it uses the next criterion to determine their order. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `object` | The type of the objects in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array of objects to be sorted. | | `criteria` | (((`item`) => `unknown`) \| keyof `T`)[] | The criteria for sorting. This can be an array of object keys or functions that return values used for sorting. | ## Returns `T`[] - The sorted array. ## Example ```ts const users = [ { user: 'foo', age: 24 }, { user: 'bar', age: 7 }, { user: 'foo', age: 8 }, { user: 'bar', age: 29 }, ]; sortBy(users, ['user', 'age']); sortBy(users, [obj => obj.user, 'age']); // results will be: // [ // { user : 'bar', age: 7 }, // { user : 'bar', age: 29 }, // { user : 'foo', age: 8 }, // { user : 'foo', age: 24 }, // ] ``` ##### tail _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function tail(arr): []; ``` Returns an empty array when the input is a single-element array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the single element in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`\] | The single-element array to process. | ### Returns \[\] An empty array. ### Example ```ts const arr = [1]; const result = tail(arr); // result will be [] ``` ## Call Signature ```ts function tail(arr): []; ``` Returns an empty array when the input is an empty array. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[\] | The empty array to process. | ### Returns \[\] An empty array. ### Example ```ts const arr = []; const result = tail(arr); // result will be [] ``` ## Call Signature ```ts function tail(arr): U[]; ``` Returns a new array with all elements except for the first when the input is a tuple array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the first element in the tuple array. | | `U` | The type of the remaining elements in the tuple array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly \[`T`, `U`\] | The tuple array to process. | ### Returns `U`[] A new array containing all elements of the input array except for the first one. ### Example ```ts const arr = [1, 2, 3]; const result = tail(arr); // result will be [2, 3] ``` ## Call Signature ```ts function tail(arr): T[]; ``` Returns a new array with all elements except for the first. This function takes an array and returns a new array containing all the elements except for the first one. If the input array is empty or has only one element, an empty array is returned. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to get the tail of. | ### Returns `T`[] A new array containing all elements of the input array except for the first one. ### Example ```ts const arr1 = [1, 2, 3]; const result = tail(arr1); // result will be [2, 3] const arr2 = [1]; const result2 = tail(arr2); // result2 will be [] const arr3 = []; const result3 = tail(arr3); // result3 will be [] ``` ##### take _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function take( arr, count?, guard?): T[]; ``` Returns a new array containing the first `count` elements from the input array `arr`. If `count` is greater than the length of `arr`, the entire array is returned. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | Type of elements in the input array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to take elements from. | | `count?` | `number` | The number of elements to take. | | `guard?` | `unknown` | If truthy, ignores `count` and defaults to 1. | ## Returns `T`[] A new array containing the first `count` elements from `arr`. ## Examples ```ts // Returns [1, 2, 3] take([1, 2, 3, 4, 5], 3); ``` ```ts // Returns ['a', 'b'] take(['a', 'b', 'c'], 2); ``` ```ts // Returns [1, 2, 3] take([1, 2, 3], 5); ``` ```ts // Returns [[1], [1], [1]] const arr = [1, 2, 3]; const result = arr.map((v, i, array) => take(array, i, true)); ``` ##### takeRight _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function takeRight( arr, count?, guard?): T[]; ``` Returns a new array containing the last `count` elements from the input array `arr`. If `count` is greater than the length of `arr`, the entire array is returned. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to take elements from. | | `count?` | `number` | The number of elements to take. | | `guard?` | `unknown` | - | ## Returns `T`[] A new array containing the last `count` elements from `arr`. ## Examples ```ts // Returns [4, 5] takeRight([1, 2, 3, 4, 5], 2); ``` ```ts // Returns ['b', 'c'] takeRight(['a', 'b', 'c'], 2); ``` ```ts // Returns [1, 2, 3] takeRight([1, 2, 3], 5); ``` ##### takeRightWhile _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function takeRightWhile(arr, shouldContinueTaking): T[]; ``` Takes elements from the end of the array while the predicate function returns `true`. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | Type of elements in the input array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to take elements from. | | `shouldContinueTaking` | (`item`, `index`, `array`) => `boolean` | The function invoked per element with the item, its index, and the array. | ## Returns `T`[] A new array containing the elements taken from the end while the predicate returns `true`. ## Examples ```ts // Returns [3, 2, 1] takeRightWhile([5, 4, 3, 2, 1], n => n < 4); ``` ```ts // Returns [] takeRightWhile([1, 2, 3], n => n > 3); ``` ```ts // Using index parameter takeRightWhile([10, 20, 30, 40], (x, index) => index > 1); // Returns: [30, 40] ``` ##### takeWhile _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function takeWhile(arr, shouldContinueTaking): T[]; ``` Returns a new array containing the leading elements of the provided array that satisfy the provided predicate function. It stops taking elements as soon as an element does not satisfy the predicate. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to process. | | `shouldContinueTaking` | (`element`, `index`, `array`) => `boolean` | The predicate function that is called with each element, its index, and the array. Elements are included in the result as long as this function returns true. | ## Returns `T`[] A new array containing the leading elements that satisfy the predicate. ## Examples ```ts // Returns [1, 2] takeWhile([1, 2, 3, 4], x => x < 3); ``` ```ts // Returns [] takeWhile([1, 2, 3, 4], x => x > 3); ``` ```ts // Using index parameter takeWhile([10, 20, 30, 40], (x, index) => index < 2); // Returns: [10, 20] ``` ##### toFilled _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function toFilled(arr, value): (T | U)[]; ``` Creates a new array filled with the specified value from the start position up to, but not including, the end position. This function does not mutate the original array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the original array. | | `U` | The type of the value to fill the new array with. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to base the new array on. | | `value` | `U` | The value to fill the new array with. | ### Returns (`T` \| `U`)[] The new array with the filled values. ### Example ```ts const array = [1, 2, 3, 4, 5]; let result = toFilled(array, '*', 2); console.log(result); // [1, 2, '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', 1, 4); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*'); console.log(result); // ['*', '*', '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', -4, -1); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] ``` ## Call Signature ```ts function toFilled( arr, value, start?): (T | U)[]; ``` Creates a new array filled with the specified value from the start position up to, but not including, the end position. This function does not mutate the original array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the original array. | | `U` | The type of the value to fill the new array with. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to base the new array on. | | `value` | `U` | The value to fill the new array with. | | `start?` | `number` | The start position. Defaults to 0. | ### Returns (`T` \| `U`)[] The new array with the filled values. ### Example ```ts const array = [1, 2, 3, 4, 5]; let result = toFilled(array, '*', 2); console.log(result); // [1, 2, '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', 1, 4); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*'); console.log(result); // ['*', '*', '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', -4, -1); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] ``` ## Call Signature ```ts function toFilled( arr, value, start?, end?): (T | U)[]; ``` Creates a new array filled with the specified value from the start position up to, but not including, the end position. This function does not mutate the original array. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the original array. | | `U` | The type of the value to fill the new array with. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to base the new array on. | | `value` | `U` | The value to fill the new array with. | | `start?` | `number` | The start position. Defaults to 0. | | `end?` | `number` | The end position. Defaults to the array's length. | ### Returns (`T` \| `U`)[] The new array with the filled values. ### Example ```ts const array = [1, 2, 3, 4, 5]; let result = toFilled(array, '*', 2); console.log(result); // [1, 2, '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', 1, 4); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*'); console.log(result); // ['*', '*', '*', '*', '*'] console.log(array); // [1, 2, 3, 4, 5] result = toFilled(array, '*', -4, -1); console.log(result); // [1, '*', '*', '*', 5] console.log(array); // [1, 2, 3, 4, 5] ``` ##### union _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function union(arr1, arr2): T[]; ``` Creates an array of unique values from all given arrays. This function takes two arrays, merges them into a single array, and returns a new array containing only the unique values from the merged array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to merge and filter for unique values. | | `arr2` | readonly `T`[] | The second array to merge and filter for unique values. | ## Returns `T`[] A new array of unique values. ## Example ```ts const array1 = [1, 2, 3]; const array2 = [3, 4, 5]; const result = union(array1, array2); // result will be [1, 2, 3, 4, 5] ``` ##### unionBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function unionBy( arr1, arr2, mapper): T[]; ``` Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | | `U` | The type of mapped elements. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array. | | `arr2` | readonly `T`[] | The second array. | | `mapper` | (`item`) => `U` | The function to map array elements to comparison values. | ## Returns `T`[] A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function. ## Examples ```ts // Custom mapping function for numbers (modulo comparison) const moduloMapper = (x) => x % 3; unionBy([1, 2, 3], [4, 5, 6], moduloMapper); // Returns [1, 2, 3] ``` ```ts // Custom mapping function for objects with an 'id' property const idMapper = (obj) => obj.id; unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper); // Returns [{ id: 1 }, { id: 2 }, { id: 3 }] ``` ##### unionWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function unionWith( arr1, arr2, areItemsEqual): T[]; ``` Creates an array of unique values from two given arrays based on a custom equality function. This function takes two arrays and a custom equality function, merges the arrays, and returns a new array containing only the unique values as determined by the custom equality function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to merge and filter for unique values. | | `arr2` | readonly `T`[] | The second array to merge and filter for unique values. | | `areItemsEqual` | (`item1`, `item2`) => `boolean` | A custom function to determine if two elements are equal. It takes two arguments and returns `true` if the elements are considered equal, and `false` otherwise. | ## Returns `T`[] A new array of unique values based on the custom equality function. ## Example ```ts const array1 = [{ id: 1 }, { id: 2 }]; const array2 = [{ id: 2 }, { id: 3 }]; const areItemsEqual = (a, b) => a.id === b.id; const result = unionWith(array1, array2, areItemsEqual); // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays ``` ##### uniq _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function uniq(arr): T[]; ``` Creates a duplicate-free version of an array. This function takes an array and returns a new array containing only the unique values from the original array, preserving the order of first occurrence. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to process. | ## Returns `T`[] A new array with only unique values from the original array. ## Example ```ts const array = [1, 2, 2, 3, 4, 4, 5]; const result = uniq(array); // result will be [1, 2, 3, 4, 5] ``` ##### uniqBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function uniqBy(arr, mapper): T[]; ``` Returns a new array containing only the unique elements from the original array, based on the values returned by the mapper function. When duplicates are found, the first occurrence is kept and the rest are discarded. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | | `U` | The type of mapped elements. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to process. | | `mapper` | (`item`, `index`, `array`) => `U` | The function used to convert the array elements. | ## Returns `T`[] A new array containing only the unique elements from the original array, based on the values returned by the mapper function. ## Examples ```ts uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor); // [1.2, 2.1, 3.2, 5.7, 7.19] ``` ```ts const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, { category: 'vegetable', name: 'carrot' }, ]; uniqBy(array, item => item.category).length // 2 ``` ``` ##### uniqWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function uniqWith(arr, areItemsEqual): T[]; ``` Returns a new array containing only the unique elements from the original array, based on the values returned by the comparator function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The array to process. | | `areItemsEqual` | (`item1`, `item2`) => `boolean` | The function used to compare the array elements. | ## Returns `T`[] A new array containing only the unique elements from the original array, based on the values returned by the comparator function. ## Example ```ts uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => Math.abs(a - b) < 1); // [1.2, 3.2, 5.7, 7.19] ``` ##### unzip _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function unzip(zipped): Unzip; ``` Gathers elements in the same position in an internal array from a grouped array of elements and returns them as a new array. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `unknown`[] | The type of elements in the nested array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `zipped` | readonly \[`...T[]`\][] | The nested array to unzip. | ## Returns `Unzip`\<`T`\> A new array of unzipped elements. ## Example ```ts const zipped = [['a', true, 1],['b', false, 2]]; const result = unzip(zipped); // result will be [['a', 'b'], [true, false], [1, 2]] ``` ##### unzipWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function unzipWith(target, iteratee): R[]; ``` Unzips an array of arrays, applying an `iteratee` function to regrouped elements. ## Type Parameters | Type Parameter | | :------ | | `T` | | `R` | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `target` | readonly `T`[][] | The nested array to unzip. This is an array of arrays, where each inner array contains elements to be unzipped. | | `iteratee` | (...`args`) => `R` | A function to transform the unzipped elements. | ## Returns `R`[] A new array of unzipped and transformed elements. ## Example ```ts const nestedArray = [[1, 2], [3, 4], [5, 6]]; const result = unzipWith(nestedArray, (item, item2, item3) => item + item2 + item3); // result will be [9, 12] ``` ##### windowed _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function windowed( arr, size, step?, options?): T[][]; ``` Creates an array of sub-arrays (windows) from the input array, each of the specified size. The windows can overlap depending on the step size provided. By default, only full windows are included in the result, and any leftover elements that can't form a full window are ignored. If the `partialWindows` option is set to true in the options object, the function will also include partial windows at the end of the result. Partial windows are smaller sub-arrays created when there aren't enough elements left in the input array to form a full window. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr` | readonly `T`[] | The input array to create windows from. | | `size` | `number` | The size of each window. Must be a positive integer. | | `step?` | `number` | The step size between the start of each window. Must be a positive integer. | | `options?` | `WindowedOptions` | Options object to configure the behavior of the function. | ## Returns `T`[][] An array of windows (sub-arrays) created from the input array. ## Throws If the size or step is not a positive integer. ## Examples ```ts windowed([1, 2, 3, 4], 2); // => [[1, 2], [2, 3], [3, 4]] ``` ```ts windowed([1, 2, 3, 4, 5, 6], 3, 2); // => [[1, 2, 3], [3, 4, 5]] ``` ```ts windowed([1, 2, 3, 4, 5, 6], 3, 2, { partialWindows: true }); // => [[1, 2, 3], [3, 4, 5], [5, 6]] ``` ##### without _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function without(array, ...values): T[]; ``` Creates an array that excludes all specified values. It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero). ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `array` | readonly `T`[] | The array to filter. | | ...`values` | `T`[] | The values to exclude. | ## Returns `T`[] A new array without the specified values. ## Examples ```ts // Removes the specified values from the array without([1, 2, 3, 4, 5], 2, 4); // Returns: [1, 3, 5] ``` ```ts // Removes specified string values from the array without(['a', 'b', 'c', 'a'], 'a'); // Returns: ['b', 'c'] ``` ##### xor _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function xor(arr1, arr2): T[]; ``` Computes the symmetric difference between two arrays. The symmetric difference is the set of elements which are in either of the arrays, but not in their intersection. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array. | | `arr2` | readonly `T`[] | The second array. | ## Returns `T`[] An array containing the elements that are present in either `arr1` or `arr2` but not in both. ## Examples ```ts // Returns [1, 2, 5, 6] xor([1, 2, 3, 4], [3, 4, 5, 6]); ``` ```ts // Returns ['a', 'c'] xor(['a', 'b'], ['b', 'c']); ``` ##### xorBy _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function xorBy( arr1, arr2, mapper): T[]; ``` Computes the symmetric difference between two arrays using a custom mapping function. The symmetric difference is the set of elements which are in either of the arrays, but not in their intersection, determined by the result of the mapping function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | Type of elements in the input arrays. | | `U` | Type of the values returned by the mapping function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array. | | `arr2` | readonly `T`[] | The second array. | | `mapper` | (`item`) => `U` | The function to map array elements to comparison values. | ## Returns `T`[] An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the values returned by the mapping function. ## Example ```ts // Custom mapping function for objects with an 'id' property const idMapper = obj => obj.id; xorBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper); // Returns [{ id: 1 }, { id: 3 }] ``` ##### xorWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function xorWith( arr1, arr2, areElementsEqual): T[]; ``` Computes the symmetric difference between two arrays using a custom equality function. The symmetric difference is the set of elements which are in either of the arrays, but not in their intersection. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | Type of elements in the input arrays. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array. | | `arr2` | readonly `T`[] | The second array. | | `areElementsEqual` | (`item1`, `item2`) => `boolean` | The custom equality function to compare elements. | ## Returns `T`[] An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function. ## Example ```ts // Custom equality function for objects with an 'id' property const areObjectsEqual = (a, b) => a.id === b.id; xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual); // Returns [{ id: 1 }, { id: 3 }] ``` ##### zip _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function zip(arr1): [T][]; ``` Combines multiple arrays into a single array of tuples. This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | ### Returns \[`T`\][] A new array of tuples containing the corresponding elements from the input arrays. ### Example ```ts const arr1 = [1, 2, 3]; const result = zip(arr1); // result will be [[1], [2], [3]] ``` ## Call Signature ```ts function zip(arr1, arr2): [T, U][]; ``` Combines multiple arrays into a single array of tuples. This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements. ### Type Parameters | Type Parameter | | :------ | | `T` | | `U` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | ### Returns \[`T`, `U`\][] A new array of tuples containing the corresponding elements from the input arrays. ### Example ```ts const arr1 = [1, 2, 3]; const arr2 = ['a', 'b', 'c']; const result = zip(arr1, arr2); // result will be [[1, 'a'], [2, 'b'], [3, 'c']] ``` ## Call Signature ```ts function zip( arr1, arr2, arr3): [T, U, V][]; ``` Combines multiple arrays into a single array of tuples. This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements. ### Type Parameters | Type Parameter | | :------ | | `T` | | `U` | | `V` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | | `arr3` | readonly `V`[] | The third array to zip. | ### Returns \[`T`, `U`, `V`\][] A new array of tuples containing the corresponding elements from the input arrays. ### Example ```ts const arr1 = [1, 2, 3]; const arr2 = ['a', 'b', 'c']; const arr3 = [true, false]; const result = zip(arr1, arr2, arr3); // result will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]] ``` ## Call Signature ```ts function zip( arr1, arr2, arr3, arr4): [T, U, V, W][]; ``` Combines multiple arrays into a single array of tuples. This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements. ### Type Parameters | Type Parameter | | :------ | | `T` | | `U` | | `V` | | `W` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | | `arr3` | readonly `V`[] | The third array to zip. | | `arr4` | readonly `W`[] | The fourth array to zip. | ### Returns \[`T`, `U`, `V`, `W`\][] A new array of tuples containing the corresponding elements from the input arrays. ### Example ```ts const arr1 = [1, 2, 3]; const arr2 = ['a', 'b', 'c']; const arr3 = [true, false]; const arr4 = [null, null, null]; const result = zip(arr1, arr2, arr3, arr4); // result will be [[1, 'a', true, null], [2, 'b', false, null], [3, 'c', undefined, null]] ``` ## Call Signature ```ts function zip(...arrs): T[][]; ``` Combines multiple arrays into a single array of tuples. This function takes multiple arrays and returns a new array where each element is a tuple containing the corresponding elements from the input arrays. If the input arrays are of different lengths, the resulting array will have the length of the longest input array, with undefined values for missing elements. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | ...`arrs` | readonly `T`[][] | The arrays to zip together. | ### Returns `T`[][] A new array of tuples containing the corresponding elements from the input arrays. ### Example ```ts const arr1 = [1, 2, 3]; const arr2 = ['a', 'b', 'c']; const arr3 = [true, false]; const result = zip(arr1, arr2, arr3); // result will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]] ``` ##### zipObject _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ ```ts function zipObject(keys, values): Record; ``` Combines two arrays, one of property names and one of corresponding values, into a single object. This function takes two arrays: one containing property names and another containing corresponding values. It returns a new object where the property names from the first array are keys, and the corresponding elements from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `P` *extends* `PropertyKey` | The type of elements in the array. | | `V` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `keys` | readonly `P`[] | An array of property names. | | `values` | readonly `V`[] | An array of values corresponding to the property names. | ## Returns `Record`\<`P`, `V`\> - A new object composed of the given property names and values. ## Example ```ts const keys = ['a', 'b', 'c']; const values = [1, 2, 3]; const result = zipObject(keys, values); // result will be { a: 1, b: 2, c: 3 } const keys2 = ['a', 'b', 'c']; const values2 = [1, 2]; const result2 = zipObject(keys2, values2); // result2 will be { a: 1, b: 2, c: undefined } const keys2 = ['a', 'b']; const values2 = [1, 2, 3]; const result2 = zipObject(keys2, values2); // result2 will be { a: 1, b: 2 } ``` ##### zipWith _Import from `@varavel/vdl-plugin-sdk/utils/arrays`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function zipWith(arr1, combine): R[]; ``` Combines multiple arrays into a single array using a custom combiner function. This function takes multiple arrays and a combiner function, and returns a new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `R` | The type of elements in the resulting array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `combine` | (`item`, `index`) => `R` | The combiner function that takes corresponding elements from each array, their index, and returns a single value. | ### Returns `R`[] A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays. ### Examples ```ts // Example usage with two arrays: const arr1 = [1, 2, 3]; const arr2 = [4, 5, 6]; const result = zipWith(arr1, arr2, (a, b) => a + b); // result will be [5, 7, 9] ``` ```ts // Example usage with three arrays: const arr1 = [1, 2]; const arr2 = [3, 4]; const arr3 = [5, 6]; const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`); // result will be [`135`, `246`] ``` ## Call Signature ```ts function zipWith( arr1, arr2, combine): R[]; ``` Combines two arrays into a single array using a custom combiner function. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `U` | The type of elements in the second array. | | `R` | The type of elements in the resulting array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | | `combine` | (`item1`, `item2`, `index`) => `R` | The combiner function that takes corresponding elements from each array, their index, and returns a single value. | ### Returns `R`[] A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays. ## Call Signature ```ts function zipWith( arr1, arr2, arr3, combine): R[]; ``` Combines three arrays into a single array using a custom combiner function. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `U` | The type of elements in the second array. | | `V` | The type of elements in the third array. | | `R` | The type of elements in the resulting array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | | `arr3` | readonly `V`[] | The third array to zip. | | `combine` | (`item1`, `item2`, `item3`, `index`) => `R` | The combiner function that takes corresponding elements from each array, their index, and returns a single value. | ### Returns `R`[] A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays. ## Call Signature ```ts function zipWith( arr1, arr2, arr3, arr4, combine): R[]; ``` Combines four arrays into a single array using a custom combiner function. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the first array. | | `U` | The type of elements in the second array. | | `V` | The type of elements in the third array. | | `W` | The type of elements in the fourth array. | | `R` | The type of elements in the resulting array. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `arr1` | readonly `T`[] | The first array to zip. | | `arr2` | readonly `U`[] | The second array to zip. | | `arr3` | readonly `V`[] | The third array to zip. | | `arr4` | readonly `W`[] | The fourth array to zip. | | `combine` | (`item1`, `item2`, `item3`, `item4`, `index`) => `R` | The combiner function that takes corresponding elements from each array, their index, and returns a single value. | ### Returns `R`[] A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays. ### Functions import: `@varavel/vdl-plugin-sdk/utils/functions` _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ## Functions - [after](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/after.md) - [ary](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/ary.md) - [before](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/before.md) - [curry](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/curry.md) - [curryRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/curryRight.md) - [flow](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/flow.md) - [flowRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/flowRight.md) - [identity](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/identity.md) - [memoize](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/memoize.md) - [negate](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/negate.md) - [noop](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/noop.md) - [once](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/once.md) - [partial](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/partial.md) - [partialRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/partialRight.md) - [rest](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/rest.md) - [spread](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/spread.md) - [unary](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/functions/unary.md) ## Namespaces - [partial](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/namespaces/partial/index.md) - [partialRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/functions/namespaces/partialRight/index.md) #### Functions ##### after _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function after(n, func): (...args) => ReturnType | undefined; ``` Creates a function that only executes starting from the `n`-th call. The provided function will be invoked starting from the `n`-th call. This is particularly useful for scenarios involving events or asynchronous operations where an action should occur only after a certain number of invocations. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function to be invoked. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `n` | `number` | The number of calls required for `func` to execute. | | `func` | `F` | The function to be invoked. | ## Returns - A new function that: - Tracks the number of calls. - Invokes `func` starting from the `n`-th call. - Returns `undefined` if fewer than `n` calls have been made. (...`args`) => `ReturnType`\<`F`\> \| `undefined` ## Throws - Throws an error if `n` is negative. ## Example ```ts const afterFn = after(3, () => { console.log("called") }); // Will not log anything. afterFn() // Will not log anything. afterFn() // Will log 'called'. afterFn() ``` ##### ary _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function ary(func, n): (...args) => ReturnType; ``` Creates a function that invokes func, with up to n arguments, ignoring any additional arguments. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to cap arguments for. | | `n` | `number` | The arity cap. | ## Returns Returns the new capped function. (...`args`) => `ReturnType`\<`F`\> ## Example ```ts function fn(a: number, b: number, c: number) { return Array.from(arguments); } ary(fn, 0)(1, 2, 3) // [] ary(fn, 1)(1, 2, 3) // [1] ary(fn, 2)(1, 2, 3) // [1, 2] ary(fn, 3)(1, 2, 3) // [1, 2, 3] ``` ##### before _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function before(n, func): (...args) => ReturnType | undefined; ``` Creates a function that limits the number of times the given function (`func`) can be called. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function to be invoked. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `n` | `number` | The number of times the returned function is allowed to call `func` before stopping. - If `n` is 0, `func` will never be called. - If `n` is a positive integer, `func` will be called up to `n-1` times. | | `func` | `F` | The function to be called with the limit applied. | ## Returns - A new function that: - Tracks the number of calls. - Invokes `func` until the `n-1`-th call. - Returns `undefined` if the number of calls reaches or exceeds `n`, stopping further calls. (...`args`) => `ReturnType`\<`F`\> \| `undefined` ## Throws - Throw an error if `n` is negative. ## Example ```ts const beforeFn = before(3, () => { console.log("called"); }) // Will log 'called'. beforeFn(); // Will log 'called'. beforeFn(); // Will not log anything. beforeFn(); ``` ##### curry _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function curry(func): () => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | () => `R` | The function to curry. | ### Returns A curried function. () => `R` ### Example ```ts function noArgFunc() { return 42; } const curriedNoArgFunc = curry(noArgFunc); console.log(curriedNoArgFunc()); // 42 ``` ## Call Signature ```ts function curry(func): (p) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `P` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p`) => `R` | The function to curry. | ### Returns A curried function. (`p`) => `R` ### Example ```ts function oneArgFunc(a: number) { return a * 2; } const curriedOneArgFunc = curry(oneArgFunc); console.log(curriedOneArgFunc(5)); // 10 ``` ## Call Signature ```ts function curry(func): (p1) => (p2) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`) => `R` | The function to curry. | ### Returns A curried function. (`p1`) => (`p2`) => `R` ### Example ```ts function twoArgFunc(a: number, b: number) { return a + b; } const curriedTwoArgFunc = curry(twoArgFunc); const add5 = curriedTwoArgFunc(5); console.log(add5(10)); // 15 ``` ## Call Signature ```ts function curry(func): (p1) => (p2) => (p3) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`) => `R` | The function to curry. | ### Returns A curried function. (`p1`) => (`p2`) => (`p3`) => `R` ### Example ```ts function threeArgFunc(a: number, b: number, c: number) { return a + b + c; } const curriedThreeArgFunc = curry(threeArgFunc); const add1 = curriedThreeArgFunc(1); const add3 = add1(2); console.log(add3(3)); // 6 ``` ## Call Signature ```ts function curry(func): (p1) => (p2) => (p3) => (p4) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `P4` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`, `p4`) => `R` | The function to curry. | ### Returns A curried function. (`p1`) => (`p2`) => (`p3`) => (`p4`) => `R` ### Example ```ts function fourArgFunc(a: number, b: number, c: number, d: number) { return a + b + c + d; } const curriedFourArgFunc = curry(fourArgFunc); const add1 = curriedFourArgFunc(1); const add3 = add1(2); const add6 = add3(3); console.log(add6(4)); // 10 ``` ## Call Signature ```ts function curry(func): (p1) => (p2) => (p3) => (p4) => (p5) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `P4` | | `P5` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`, `p4`, `p5`) => `R` | The function to curry. | ### Returns A curried function. (`p1`) => (`p2`) => (`p3`) => (`p4`) => (`p5`) => `R` ### Example ```ts function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) { return a + b + c + d + e; } const curriedFiveArgFunc = curry(fiveArgFunc); const add1 = curriedFiveArgFunc(1); const add3 = add1(2); const add6 = add3(3); const add10 = add6(4); console.log(add10(5)); // 15 ``` ## Call Signature ```ts function curry(func): (...args) => any; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (...`args`) => `any` | The function to curry. | ### Returns A curried function that can be called with a single argument at a time. (...`args`) => `any` ### Example ```ts function sum(a: number, b: number, c: number) { return a + b + c; } const curriedSum = curry(sum); // The parameter `a` should be given the value `10`. const add10 = curriedSum(10); // The parameter `b` should be given the value `15`. const add25 = add10(15); // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value. const result = add25(5); ``` ##### curryRight _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function curryRight(func): () => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | () => `R` | The function to curry. | ### Returns A curried function. () => `R` ### Example ```ts function noArgFunc() { return 42; } const curriedNoArgFunc = curryRight(noArgFunc); console.log(curriedNoArgFunc()); // 42 ``` ## Call Signature ```ts function curryRight(func): (p) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `P` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p`) => `R` | The function to curry. | ### Returns A curried function. (`p`) => `R` ### Example ```ts function oneArgFunc(a: number) { return a * 2; } const curriedOneArgFunc = curryRight(oneArgFunc); console.log(curriedOneArgFunc(5)); // 10 ``` ## Call Signature ```ts function curryRight(func): (p2) => (p1) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`) => `R` | The function to curry. | ### Returns A curried function. (`p2`) => (`p1`) => `R` ### Example ```ts function twoArgFunc(a: number, b: number) { return [a, b]; } const curriedTwoArgFunc = curryRight(twoArgFunc); const func = curriedTwoArgFunc(1); console.log(func(2)); // [2, 1] ``` ## Call Signature ```ts function curryRight(func): (p3) => (p2) => (p1) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`) => `R` | The function to curry. | ### Returns A curried function. (`p3`) => (`p2`) => (`p1`) => `R` ### Example ```ts function threeArgFunc(a: number, b: number, c: number) { return [a, b, c]; } const curriedThreeArgFunc = curryRight(threeArgFunc); const func = curriedThreeArgFunc(1); const func2 = func(2); console.log(func2(3)); // [3, 2, 1] ``` ## Call Signature ```ts function curryRight(func): (p4) => (p3) => (p2) => (p1) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `P4` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`, `p4`) => `R` | The function to curry. | ### Returns A curried function. (`p4`) => (`p3`) => (`p2`) => (`p1`) => `R` ### Example ```ts function fourArgFunc(a: number, b: number, c: number, d: number) { return [a, b, c, d]; } const curriedFourArgFunc = curryRight(fourArgFunc); const func = curriedFourArgFunc(1); const func2 = func(2); const func3 = func2(3); console.log(func3(4)); // [4, 3, 2, 1] ``` ## Call Signature ```ts function curryRight(func): (p5) => (p4) => (p3) => (p2) => (p1) => R; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Type Parameters | Type Parameter | | :------ | | `P1` | | `P2` | | `P3` | | `P4` | | `P5` | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`p1`, `p2`, `p3`, `p4`, `p5`) => `R` | The function to curry. | ### Returns A curried function. (`p5`) => (`p4`) => (`p3`) => (`p2`) => (`p1`) => `R` ### Example ```ts function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) { return [a, b, c, d, e]; } const curriedFiveArgFunc = curryRight(fiveArgFunc); const func = curriedFiveArgFunc(1); const func2 = func(2); const func3 = func2(3); const func4 = func3(4); console.log(func4(5)); // [5, 4, 3, 2, 1] ``` ## Call Signature ```ts function curryRight(func): (...args) => any; ``` Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments. Unlike `curry`, this function curries the function from right to left. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (...`args`) => `any` | The function to curry. | ### Returns A curried function. (...`args`) => `any` ### Example ```ts function sum(a: number, b: number, c: number) { return a + b + c; } const curriedSum = curryRight(sum); // The parameter `c` should be given the value `10`. const add10 = curriedSum(10); // The parameter `b` should be given the value `15`. const add25 = add10(15); // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value. const result = add25(5); // 30 ``` ##### flow _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function flow(f): () => R; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f` | () => `R` | The function to invoke. | ### Returns Returns the new composite function. () => `R` ### Example ```ts function noArgFunc() { return 42; } const combined = flow(noArgFunc); console.log(combined()); // 42 ``` ## Call Signature ```ts function flow(f1): (...args) => R; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R` ### Example ```ts function oneArgFunc(a: number) { return a * 2; } const combined = flow(oneArgFunc); console.log(combined(5)); // 10 ``` ## Call Signature ```ts function flow(f1, f2): (...args) => R2; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R1` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R2` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const combined = flow(add, square); console.log(combined(1, 2)); // 9 ``` ## Call Signature ```ts function flow( f1, f2, f3): (...args) => R3; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R1` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f3` | (`a`) => `R3` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R3` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const combined = flow(add, square, double); console.log(combined(1, 2)); // 18 ``` ## Call Signature ```ts function flow( f1, f2, f3, f4): (...args) => R4; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | | `R4` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R1` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f3` | (`a`) => `R3` | The function to invoke. | | `f4` | (`a`) => `R4` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R4` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const toStr = (n: number) => n.toString(); const combined = flow(add, square, double, toStr); console.log(combined(1, 2)); // '18' ``` ## Call Signature ```ts function flow( f1, f2, f3, f4, f5): (...args) => R5; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | | `R4` | | `R5` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R1` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f3` | (`a`) => `R3` | The function to invoke. | | `f4` | (`a`) => `R4` | The function to invoke. | | `f5` | (`a`) => `R5` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R5` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const toStr = (n: number) => n.toString(); const split = (s: string) => s.split(''); const combined = flow(add, square, double, toStr, split); console.log(combined(1, 2)); // ['1', '8'] ``` ## Call Signature ```ts function flow(...funcs): (...args) => any; ``` Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | ...`funcs` | (...`args`) => `any`[] | The functions to invoke. | ### Returns Returns the new composite function. (...`args`) => `any` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const combined = flow(add, square); console.log(combined(1, 2)); // 9 ``` ##### flowRight _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function flowRight(f): () => R; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f` | () => `R` | The function to invoke. | ### Returns Returns the new composite function. () => `R` ### Example ```ts function noArgFunc() { return 42; } const combined = flowRight(noArgFunc); console.log(combined()); // 42 ``` ## Call Signature ```ts function flowRight(f1): (...args) => R; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f1` | (...`args`) => `R` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R` ### Example ```ts function oneArgFunc(a: number) { return a * 2; } const combined = flowRight(oneArgFunc); console.log(combined(5)); // 10 ``` ## Call Signature ```ts function flowRight(f2, f1): (...args) => R2; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f2` | (`a`) => `R2` | The function to invoke. | | `f1` | (...`args`) => `R1` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R2` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const combined = flowRight(square, add); console.log(combined(1, 2)); // 9 ``` ## Call Signature ```ts function flowRight( f3, f2, f1): (...args) => R3; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f3` | (`a`) => `R3` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f1` | (...`args`) => `R1` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R3` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const combined = flowRight(double, square, add); console.log(combined(1, 2)); // 18 ``` ## Call Signature ```ts function flowRight( f4, f3, f2, f1): (...args) => R4; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | | `R4` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f4` | (`a`) => `R4` | The function to invoke. | | `f3` | (`a`) => `R3` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f1` | (...`args`) => `R1` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R4` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const toStr = (n: number) => n.toString(); const combined = flowRight(toStr, double, square, add); console.log(combined(1, 2)); // '18' ``` ## Call Signature ```ts function flowRight( f5, f4, f3, f2, f1): (...args) => R5; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Type Parameters | Type Parameter | | :------ | | `A` *extends* `any`[] | | `R1` | | `R2` | | `R3` | | `R4` | | `R5` | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `f5` | (`a`) => `R5` | The function to invoke. | | `f4` | (`a`) => `R4` | The function to invoke. | | `f3` | (`a`) => `R3` | The function to invoke. | | `f2` | (`a`) => `R2` | The function to invoke. | | `f1` | (...`args`) => `R1` | The function to invoke. | ### Returns Returns the new composite function. (...`args`) => `R5` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const double = (n: number) => n * 2; const toStr = (n: number) => n.toString(); const split = (s: string) => s.split(''); const combined = flowRight(split, toStr, double, square, add); console.log(combined(1, 2)); // ['1', '8'] ``` ## Call Signature ```ts function flowRight(...funcs): (...args) => any; ``` Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function. The `this` context of the returned function is also passed to the functions provided as parameters. This method is like `flow` except that it creates a function that invokes the given functions from right to left. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | ...`funcs` | (...`args`) => `any`[] | The functions to invoke. | ### Returns Returns the new composite function. (...`args`) => `any` ### Example ```ts const add = (x: number, y: number) => x + y; const square = (n: number) => n * n; const combined = flowRight(square, add); console.log(combined(1, 2)); // 9 ``` ##### identity _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function identity(x): T; ``` Returns the input value unchanged. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the input value. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `T` | The value to be returned. | ## Returns `T` The input value. ## Examples ```ts // Returns 5 identity(5); ``` ```ts // Returns 'hello' identity('hello'); ``` ```ts // Returns { key: 'value' } identity({ key: 'value' }); ``` ##### memoize _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function memoize(fn, options?): F & object; ``` Creates a memoized version of the provided function. The memoized function caches results based on the argument it receives, so if the same argument is passed again, it returns the cached result instead of recomputing it. This function works with functions that take zero or just one argument. If your function originally takes multiple arguments, you should refactor it to take a single object or array that combines those arguments. If the argument is not primitive (e.g., arrays or objects), provide a `getCacheKey` function to generate a unique cache key for proper caching. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function to be memoized. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `fn` | `F` | The function to be memoized. It should accept a single argument and return a value. | | `options?` | \{ `cache?`: `MemoizeCache`\<`any`, `ReturnType`\<`F`\>\>; `getCacheKey?`: (`args`) => `unknown`; \} | Optional configuration for the memoization. | | `options.cache?` | `MemoizeCache`\<`any`, `ReturnType`\<`F`\>\> | The cache object used to store results. Defaults to a new `Map`. | | `options.getCacheKey?` | (`args`) => `unknown` | An optional function to generate a unique cache key for each argument. | ## Returns `F` & `object` The memoized function with an additional `cache` property that exposes the internal cache. ## Examples ```ts // Example using the default cache const add = (x: number) => x + 10; const memoizedAdd = memoize(add); console.log(memoizedAdd(5)); // 15 console.log(memoizedAdd(5)); // 15 (cached result) console.log(memoizedAdd.cache.size); // 1 ``` ```ts // Example using a custom resolver const sum = (arr: number[]) => arr.reduce((x, y) => x + y, 0); const memoizedSum = memoize(sum, { getCacheKey: (arr: number[]) => arr.join(',') }); console.log(memoizedSum([1, 2])); // 3 console.log(memoizedSum([1, 2])); // 3 (cached result) console.log(memoizedSum.cache.size); // 1 ``` ```ts // Example using a custom cache implementation class CustomCache implements MemoizeCache { private cache = new Map(); set(key: K, value: T): void { this.cache.set(key, value); } get(key: K): T | undefined { return this.cache.get(key); } has(key: K): boolean { return this.cache.has(key); } delete(key: K): boolean { return this.cache.delete(key); } clear(): void { this.cache.clear(); } get size(): number { return this.cache.size; } } const customCache = new CustomCache(); const memoizedSumWithCustomCache = memoize(sum, { cache: customCache }); console.log(memoizedSumWithCustomCache([1, 2])); // 3 console.log(memoizedSumWithCustomCache([1, 2])); // 3 (cached result) console.log(memoizedAddWithCustomCache.cache.size); // 1 ``` ##### negate _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function negate(func): F; ``` Creates a function that negates the result of the predicate function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `boolean` | The type of the function to negate. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to negate. | ## Returns `F` The new negated function, which negates the boolean result of `func`. ## Example ```ts const array = [1, 2, 3, 4, 5, 6]; const isEven = (n: number) => n % 2 === 0; const result = array.filter(negate(isEven)); // result will be [1, 3, 5] ``` ##### noop _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function noop(): void; ``` A no-operation function that does nothing. This can be used as a placeholder or default function. ## Returns `void` This function does not return anything. ## Example ```ts noop(); // Does nothing ``` ##### once _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function once(func): F; ``` Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to restrict. | ## Returns `F` Returns the new restricted function. ## Example ```ts const initialize = once(createApplication); initialize(); initialize(); // => `createApplication` is invoked once ``` ##### partial _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function partial(func, arg1): () => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | ### Returns A new function that takes no arguments and returns the result of the original function. () => `R` ### Example ```ts const addOne = (x: number) => x + 1; const addOneToFive = partial(addOne, 5); console.log(addOneToFive()); // => 6 ``` ## Call Signature ```ts function partial(func, arg1): (arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | ### Returns A new function that takes the second argument and returns the result of the original function. (`arg2`) => `R` ### Example ```ts const multiply = (x: number, y: number) => x * y; const double = partial(multiply, 2); console.log(double(5)); // => 10 ``` ## Call Signature ```ts function partial( func, placeholder, arg2): (arg1) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply. | | `placeholder` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | `T2` | The second argument to apply. | ### Returns A new function that takes the first argument and returns the result of the original function. (`arg1`) => `R` ### Example ```ts const greet = (greeting: string, name: string) => `${greeting}, ${name}!`; const greetWithHello = partial(greet, partial.placeholder, 'John'); console.log(greetWithHello('Hello')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial(func, arg1): (arg2, arg3) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | ### Returns A new function that takes the second and third arguments and returns the result of the original function. (`arg2`, `arg3`) => `R` ### Example ```ts const sumThree = (a: number, b: number, c: number) => a + b + c; const addFive = partial(sumThree, 5); console.log(addFive(3, 2)); // => 10 ``` ## Call Signature ```ts function partial( func, arg1, arg2): (arg1, arg3) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | `T2` | The second argument to apply. | ### Returns A new function that takes the first and third arguments and returns the result of the original function. (`arg1`, `arg3`) => `R` ### Example ```ts const greet = (greeting: string, name: string) => `${greeting}, ${name}!`; const greetWithPlaceholder = partial(greet, partial.placeholder, 'John'); console.log(greetWithPlaceholder('Hello')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3): (arg1, arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the first and second arguments and returns the result of the original function. (`arg1`, `arg2`) => `R` ### Example ```ts const multiply = (x: number, y: number, z: number) => x * y * z; const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2); console.log(multiplyWithPlaceholders(3, 4)); // => 24 ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3): (arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the second argument and returns the result of the original function. (`arg2`) => `R` ### Example ```ts const greet = (greeting: string, name: string) => `${greeting}, ${name}!`; const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder); console.log(greetWithPlaceholder('John')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial( func, plc1, arg2, arg3): (arg1) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply. | | `plc1` | *typeof* `placeholderSymbol` | - | | `arg2` | `T2` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the second argument and returns the result of the original function. (`arg1`) => `R` ### Example ```ts const greet = (greeting: string, name: string) => `${greeting}, ${name}!`; const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder); console.log(greetWithPlaceholder('John')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial(func, arg1): (arg2, arg3, arg4) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | ### Returns A new function that takes the second argument and returns the result of the original function. (`arg2`, `arg3`, `arg4`) => `R` ### Example ```ts const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w; const double = partial(multiply, 2); console.log(double(5, 4, 3)); // => 120 ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg1, arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the first and second arguments and returns the result of the original function. (`arg1`, `arg2`) => `R` ### Example ```ts const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w; const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3); console.log(multiplyWithPlaceholders(4, 5)); // => 120 ``` ## Call Signature ```ts function partial( func, arg1, arg2): (arg3, arg4) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | `T2` | The second argument to apply. | ### Returns A new function that takes the third and fourth arguments and returns the result of the original function. (`arg3`, `arg4`) => `R` ### Example ```ts const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d; const addOneAndTwo = partial(sumFour, 1, 2); console.log(addOneAndTwo(3, 4)); // => 10 ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3): (arg2, arg4) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the second and fourth arguments and returns the result of the original function. (`arg2`, `arg4`) => `R` ### Example ```ts const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`; const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder, '!'); console.log(greetWithPlaceholder('John')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3): (arg1, arg4) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the first and third arguments and returns the result of the original function. (`arg1`, `arg4`) => `R` ### Example ```ts const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w; const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3); console.log(multiplyWithPlaceholder(4)); // => 24 ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg1, arg3) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the first and third arguments and returns the result of the original function. (`arg1`, `arg3`) => `R` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg1, arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the first and second arguments and returns the result of the original function. (`arg1`, `arg2`) => `R` ### Example ```ts const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w; const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3); console.log(multiplyWithPlaceholders(4, 5)); // => 120 ``` ## Call Signature ```ts function partial( func, arg1, arg2, arg3): (arg4) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the fourth argument and returns the result of the original function. (`arg4`) => `R` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg3) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the third argument and returns the result of the original function. (`arg3`) => `R` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg2) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to apply. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the second argument and returns the result of the original function. (`arg2`) => `R` ## Call Signature ```ts function partial( func, arg1, arg2, arg3, arg4): (arg1) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply. | | `arg1` | *typeof* `placeholderSymbol` | The placeholder for the first argument. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | `T3` | The third argument to apply. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the first argument and returns the result of the original function. (`arg1`) => `R` ## Call Signature ```ts function partial(func): (...args) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `TS` *extends* `any`[] | The types of the arguments. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (...`args`) => `R` | The function to partially apply. | ### Returns A new function that takes the same arguments as the original function. (...`args`) => `R` ### Example ```ts const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0); const addFive = partial(add, 5); console.log(addFive(1, 2, 3)); // => 11 ``` ## Call Signature ```ts function partial(func, arg1): (...args) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `TS` *extends* `any`[] | The types of the arguments. | | `T1` | The type of the first argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, ...`args`) => `R` | The function to partially apply. | | `arg1` | `T1` | The first argument to apply. | ### Returns A new function that takes the remaining arguments and returns the result of the original function. (...`args`) => `R` ### Example ```ts const greet = (greeting: string, ...names: string[]) => `${greeting}, ${names.join(', ')}!`; const greetHello = partial(greet, 'Hello'); console.log(greetHello('Alice', 'Bob')); // => 'Hello, Alice, Bob!' ``` ## Call Signature ```ts function partial( func, t1, arg2): (...args) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `TS` *extends* `any`[] | The types of the arguments. | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, ...`args`) => `R` | The function to partially apply. | | `t1` | `T1` | - | | `arg2` | `T2` | The second argument to apply. | ### Returns A new function that takes the remaining arguments and returns the result of the original function. (...`args`) => `R` ### Example ```ts const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`; const greetWithHello = partial(greet, 'Hello', '!'); console.log(greetWithHello('John')); // => 'Hello, John!' ``` ## Call Signature ```ts function partial( func, t1, arg2, arg3): (...args) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `TS` *extends* `any`[] | The types of the arguments. | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`t1`, `arg2`, `arg3`, ...`args`) => `R` | The function to partially apply. | | `t1` | `T1` | The first argument to apply. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | `T3` | The third argument to apply. | ### Returns A new function that takes the remaining arguments and returns the result of the original function. (...`args`) => `R` ### Example ```ts const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`; const greetWithHello = partial(greet, 'Hello', 'John', '!'); console.log(greetWithHello()); // => 'Hello, John!' ``` ## Call Signature ```ts function partial( func, t1, arg2, arg3, arg4): (...args) => R; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `TS` *extends* `any`[] | The types of the arguments. | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`t1`, `arg2`, `arg3`, `arg4`, ...`args`) => `R` | The function to partially apply. | | `t1` | `T1` | The first argument to apply. | | `arg2` | `T2` | The second argument to apply. | | `arg3` | `T3` | The third argument to apply. | | `arg4` | `T4` | The fourth argument to apply. | ### Returns A new function that takes the remaining arguments and returns the result of the original function. (...`args`) => `R` ### Example ```ts const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`; const greetWithHello = partial(greet, 'Hello', 'John', '!'); console.log(greetWithHello()); // => 'Hello, John!' ``` ## Call Signature ```ts function partial(func, ...partialArgs): (...args) => ReturnType; ``` Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding. The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function to partially apply. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to partially apply. | | ...`partialArgs` | `any`[] | The arguments to be partially applied. | ### Returns A new function that takes the remaining arguments and returns the result of the original function. (...`args`) => `ReturnType`\<`F`\> ### Example ```ts const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0); const addFive = partial(add, 5); console.log(addFive(1, 2, 3)); // => 11 ``` ##### partialRight _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function partialRight(func): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | () => `R` | The function to invoke. | ### Returns Returns the new function. () => `R` ### Example ```ts const getValue = () => 42; const getValueFunc = partialRight(getValue); console.log(getValueFunc()); // => 42 ``` ## Call Signature ```ts function partialRight(func, arg1): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | ### Returns Returns the new partially applied function. () => `R` ### Example ```ts const addOne = (num: number) => num + 1; const addOneFunc = partialRight(addOne, 1); console.log(addOneFunc()); // => 2 ``` ## Call Signature ```ts function partialRight(func): (arg1) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`) => `R` | The function to partially apply arguments to. | ### Returns Returns the new partially applied function. (`arg1`) => `R` ### Example ```ts const multiplyBy = (factor: number) => (num: number) => num * factor; const double = partialRight(multiplyBy(2)); console.log(double(5)); // => 10 ``` ## Call Signature ```ts function partialRight(func, arg1): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | ### Returns Returns the new partially applied function. () => `R` ### Example ```ts const greet = (name: string) => `Hello, ${name}!`; const greetJohn = partialRight(greet, 'John'); console.log(greetJohn()); // => 'Hello, John!' ``` ## Call Signature ```ts function partialRight(func): (arg1, arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply arguments to. | ### Returns Returns the new partially applied function. (`arg1`, `arg2`) => `R` ### Example ```ts const subtract = (a: number, b: number) => a - b; const subtractFive = partialRight(subtract); console.log(subtractFive(10, 5)); // => 5 ``` ## Call Signature ```ts function partialRight( func, arg1, arg2): (arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | ### Returns Returns the new partially applied function. (`arg2`) => `R` ### Example ```ts const concat = (a: string, b: string) => a + b; const concatWithHello = partialRight(concat, 'Hello', partialRight.placeholder); console.log(concatWithHello(' World!')); // => 'Hello World!' ``` ## Call Signature ```ts function partialRight(func, arg2): (arg1) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | ### Returns Returns the new partially applied function. (`arg1`) => `R` ### Example ```ts const divide = (a: number, b: number) => a / b; const divideByTwo = partialRight(divide, 2); console.log(divideByTwo(10)); // => 5 ``` ## Call Signature ```ts function partialRight( func, arg1, arg2): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | ### Returns Returns the new partially applied function. () => `R` ### Example ```ts const multiply = (a: number, b: number) => a * b; const multiplyByThreeAndFour = partialRight(multiply, 3, 4); console.log(multiplyByThreeAndFour()); // => 12 ``` ## Call Signature ```ts function partialRight(func): (arg1, arg2, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | ### Returns Returns the new partially applied function. (`arg1`, `arg2`, `arg3`) => `R` ### Example ```ts const sumThree = (a: number, b: number, c: number) => a + b + c; const sumWithFive = partialRight(sumThree); console.log(sumWithFive(1, 2, 5)); // => 8 ``` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3): (arg2, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | ### Returns Returns the new partially applied function. (`arg2`, `arg3`) => `R` ### Example ```ts const formatDate = (day: number, month: number, year: number) => `${day}/${month}/${year}`; const formatDateWithDay = partialRight(formatDate, 1, partialRight.placeholder, partialRight.placeholder); console.log(formatDateWithDay(12, 2023)); // => '1/12/2023' ``` ## Call Signature ```ts function partialRight( func, arg2, arg3): (arg1, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | ### Returns Returns the new partially applied function. (`arg1`, `arg3`) => `R` ### Example ```ts const createUser = (name: string, age: number, country: string) => `${name}, ${age} years old from ${country}`; const createUserFromUSA = partialRight(createUser, 'USA', partialRight.placeholder); console.log(createUserFromUSA('John', 30)); // => 'John, 30 years old from USA' ``` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3): (arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | ### Returns Returns the new partially applied function. (`arg3`) => `R` ### Example ```ts const logMessage = (level: string, message: string, timestamp: string) => `[${level}] ${message} at ${timestamp}`; const logError = partialRight(logMessage, 'ERROR', '2023-10-01'); console.log(logError('Something went wrong!')); // => '[ERROR] Something went wrong! at 2023-10-01' ``` ## Call Signature ```ts function partialRight(func, arg3): (arg1, arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg3` | `T3` | The third argument to be partially applied. | ### Returns Returns the new partially applied function. (`arg1`, `arg2`) => `R` ### Example ```ts const calculateArea = (length: number, width: number) => length * width; const calculateAreaWithWidth = partialRight(calculateArea, 5); console.log(calculateAreaWithWidth(10)); // => 50 ``` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3): (arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to be partially applied. | ### Returns Returns the new partially applied function. (`arg2`) => `R` ### Example ```ts const formatCurrency = (amount: number, currency: string) => `${amount} ${currency}`; const formatUSD = partialRight(formatCurrency, 100, partialRight.placeholder); console.log(formatUSD('USD')); // => '100 USD' ``` ## Call Signature ```ts function partialRight( func, arg2, arg3): (arg1) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | `T3` | The third argument to be partially applied. | ### Returns Returns the new partially applied function. (`arg1`) => `R` ### Example ```ts const createProfile = (name: string, age: number, country: string) => `${name}, ${age} from ${country}`; const createProfileFromCanada = partialRight(createProfile, 'Canada', 'John'); console.log(createProfileFromCanada(30)); // => 'John, 30 from Canada' ``` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | - | | `T2` | - | | `T3` | - | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`) => `R` | The function to invoke. | | `arg1` | `T1` | - | | `arg2` | `T2` | - | | `arg3` | `T3` | - | ### Returns Returns the new function. () => `R` ### Example ```ts const getValue = () => 42; const getValueFunc = partialRight(getValue); console.log(getValueFunc()); // => 42 ``` ## Call Signature ```ts function partialRight(func): (arg1, arg2, arg3, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | ### Returns Returns a new function that takes four arguments. (`arg1`, `arg2`, `arg3`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg2, arg3, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the second, third, and fourth arguments. (`arg2`, `arg3`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg2, arg3, arg4): (arg1, arg3, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the first, third, and fourth arguments. (`arg1`, `arg3`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg3, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the third and fourth arguments. (`arg3`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg3, arg4): (arg1, arg2, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the first, second, and fourth arguments. (`arg1`, `arg2`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg2, arg4) => R; ``` Creates a function that invokes `func` with the first argument, a placeholder for the second argument, This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the second and fourth arguments. (`arg2`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg2, arg3, arg4): (arg1, arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the first and fourth arguments. (`arg1`, `arg4`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg4) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | *typeof* `placeholderSymbol` | The placeholder for the fourth argument. | ### Returns Returns a new function that takes the fourth argument. (`arg4`) => `R` ## Call Signature ```ts function partialRight(func, arg4): (arg1, arg2, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the first, second, and third arguments. (`arg1`, `arg2`, `arg3`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg2, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the second and third arguments. (`arg2`, `arg3`) => `R` ## Call Signature ```ts function partialRight( func, arg2, arg3, arg4): (arg1, arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the first and third arguments. (`arg1`, `arg3`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg3) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | *typeof* `placeholderSymbol` | The placeholder for the third argument. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the third argument. (`arg3`) => `R` ## Call Signature ```ts function partialRight( func, arg3, arg4): (arg1, arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the first and second arguments. (`arg1`, `arg2`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): (arg2) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | *typeof* `placeholderSymbol` | The placeholder for the second argument. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the second argument. (`arg2`) => `R` ## Call Signature ```ts function partialRight( func, arg2, arg3, arg4): (arg1) => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns a new function that takes the first argument. (`arg1`) => `R` ## Call Signature ```ts function partialRight( func, arg1, arg2, arg3, arg4): () => R; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Type Parameters | Type Parameter | Description | | :------ | :------ | | `T1` | The type of the first argument. | | `T2` | The type of the second argument. | | `T3` | The type of the third argument. | | `T4` | The type of the fourth argument. | | `R` | The return type of the function. | ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (`arg1`, `arg2`, `arg3`, `arg4`) => `R` | The function to partially apply arguments to. | | `arg1` | `T1` | The first argument to be partially applied. | | `arg2` | `T2` | The second argument to be partially applied. | | `arg3` | `T3` | The third argument to be partially applied. | | `arg4` | `T4` | The fourth argument to be partially applied. | ### Returns Returns the new partially applied function. () => `R` ### Example ```ts const concatenate = (a: string, b: string, c: string, d: string) => a + b + c + d; const concatenateHelloWorld = partialRight(concatenate, 'Hello', ' ', 'World', '!'); console.log(concatenateHelloWorld()); // => 'Hello World!' ``` ## Call Signature ```ts function partialRight(func, ...args): (...args) => any; ``` This method is like `partial` except that partially applied arguments are appended to the arguments it receives. The partialRight.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments. Note: This method doesn't set the `length` property of partially applied functions. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | (...`args`) => `any` | The function to partially apply arguments to. | | ...`args` | `any`[] | The arguments to be partially applied. | ### Returns Returns the new partially applied function. (...`args`) => `any` ### Example ```ts const log = (...messages: string[]) => console.log(...messages); const logError = partialRight(log, 'Error:'); logError('Something went wrong!'); // => 'Error: Something went wrong!' ``` ##### rest _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function rest(func, startIndex?): (...args) => ReturnType; ``` Creates a function that transforms the arguments of the provided function `func`. The transformed arguments are passed to `func` such that the arguments starting from a specified index are grouped into an array, while the previous arguments are passed as individual elements. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function being transformed. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function whose arguments are to be transformed. | | `startIndex?` | `number` | The index from which to start grouping the remaining arguments into an array. Defaults to `func.length - 1`, grouping all arguments after the last parameter. | ## Returns A new function that, when called, returns the result of calling `func` with the transformed arguments. The transformed arguments are: - The first `start` arguments as individual elements. - The remaining arguments from index `start` onward grouped into an array. (...`args`) => `ReturnType`\<`F`\> ## Example ```ts function fn(a, b, c) { return [a, b, c]; } // Using default start index (func.length - 1, which is 2 in this case) const transformedFn = rest(fn); console.log(transformedFn(1, 2, 3, 4)); // [1, 2, [3, 4]] // Using start index 1 const transformedFnWithStart = rest(fn, 1); console.log(transformedFnWithStart(1, 2, 3, 4)); // [1, [2, 3, 4]] // With fewer arguments than the start index console.log(transformedFn(1)); // [1, undefined, []] ``` ##### spread _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function spread(func): (argsArr) => ReturnType; ``` Creates a new function that spreads elements of an array argument into individual arguments for the original function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | A function type with any number of parameters and any return type. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to be transformed. It can be any function with any number of arguments. | ## Returns - A new function that takes an array of arguments and returns the result of calling the original function with those arguments. (`argsArr`) => `ReturnType`\<`F`\> ## Example ```ts function add(a, b) { return a + b; } const spreadAdd = spread(add); console.log(spreadAdd([1, 2])); // Output: 3 ``` ##### unary _Import from `@varavel/vdl-plugin-sdk/utils/functions`._ ```ts function unary(func): (...args) => ReturnType; ``` Creates a function that accepts up to one argument, ignoring any additional arguments. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `F` *extends* (...`args`) => `any` | The type of the function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `func` | `F` | The function to cap arguments for. | ## Returns Returns the new capped function. (...`args`) => `ReturnType`\<`F`\> ## Example ```ts function fn(a, b, c) { console.log(arguments); } unary(fn)(1, 2, 3); // [Arguments] { '0': 1 } ``` ### Maps import: `@varavel/vdl-plugin-sdk/utils/maps` _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ## Functions - [every](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/every.md) - [filter](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/filter.md) - [findKey](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/findKey.md) - [findValue](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/findValue.md) - [hasValue](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/hasValue.md) - [mapKeys](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/mapKeys.md) - [mapValues](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/mapValues.md) - [reduce](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/reduce.md) - [some](https://vdl-plugin-sdk.varavel.com/llms/api/utils/maps/functions/some.md) #### Functions ##### every _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function every(map, doesMatch): boolean; ``` Tests whether all entries in a Map satisfy the provided predicate function. This function iterates through all entries of the Map and checks if the predicate function returns true for every entry. It returns true if the predicate is satisfied for all entries, and false otherwise. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to test. | | `doesMatch` | (`value`, `key`, `map`) => `boolean` | A predicate function that tests each entry. | ## Returns `boolean` true if all entries satisfy the predicate, false otherwise. ## Example ```ts const map = new Map([ ['a', 10], ['b', 20], ['c', 30] ]); const result = every(map, (value) => value > 5); // result will be: true const result2 = every(map, (value) => value > 15); // result2 will be: false ``` ##### filter _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function filter(map, callback): Map; ``` Filters a Map based on a predicate function. This function takes a Map and a predicate function, and returns a new Map containing only the entries for which the predicate function returns true. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to filter. | | `callback` | (`value`, `key`, `map`) => `boolean` | A predicate function that tests each entry. | ## Returns `Map`\<`K`, `V`\> A new Map containing only the entries that satisfy the predicate. ## Example ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3], ['d', 4] ]); const result = filter(map, (value) => value > 2); // result will be: // Map(2) { // 'c' => 3, // 'd' => 4 // } ``` ##### findKey _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function findKey(map, doesMatch): K | undefined; ``` Finds the first key in a Map for which the predicate function returns true. This function iterates through the entries of the Map and returns the key of the first entry for which the predicate function returns true. If no entry satisfies the predicate, it returns undefined. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to search. | | `doesMatch` | (`value`, `key`, `map`) => `boolean` | A predicate function that tests each entry. | ## Returns `K` \| `undefined` The key of the first entry that satisfies the predicate, or undefined if none found. ## Example ```ts const map = new Map([ ['apple', { color: 'red', quantity: 10 }], ['banana', { color: 'yellow', quantity: 5 }], ['grape', { color: 'purple', quantity: 15 }] ]); const result = findKey(map, (value) => value.quantity > 10); // result will be: 'grape' ``` ##### findValue _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function findValue(map, doesMatch): V | undefined; ``` Finds the first value in a Map for which the predicate function returns true. This function iterates through the entries of the Map and returns the value of the first entry for which the predicate function returns true. If no entry satisfies the predicate, it returns undefined. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to search. | | `doesMatch` | (`value`, `key`, `map`) => `boolean` | A predicate function that tests each entry. | ## Returns `V` \| `undefined` The value of the first entry that satisfies the predicate, or undefined if none found. ## Example ```ts const map = new Map([ ['apple', { color: 'red', quantity: 10 }], ['banana', { color: 'yellow', quantity: 5 }], ['grape', { color: 'purple', quantity: 15 }] ]); const result = findValue(map, (value) => value.quantity > 10); // result will be: { color: 'purple', quantity: 15 } ``` ##### hasValue _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function hasValue(map, searchElement): boolean; ``` Checks if a Map contains a specific value. This function iterates through all values in the Map and checks if any value is equal to the search element using SameValueZero comparison (similar to Array.prototype.includes). This means that NaN is considered equal to NaN. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to search. | | `searchElement` | `V` | The value to search for. | ## Returns `boolean` true if the Map contains the value, false otherwise. ## Example ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3] ]); const result = hasValue(map, 2); // result will be: true const result2 = hasValue(map, 5); // result2 will be: false ``` ##### mapKeys _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function mapKeys(map, getNewKey): Map; ``` Creates a new Map with the same values but with keys transformed by the provided function. This function takes a Map and a function that generates a new key from each value-key pair. It returns a new Map where the keys are the result of applying the function to each entry, while the values remain the same. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to transform. | | `getNewKey` | (`value`, `key`, `object`) => `K` | A function that generates a new key from a value-key pair. | ## Returns `Map`\<`K`, `V`\> A new Map with transformed keys and the same values. ## Example ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3] ]); const result = mapKeys(map, (value, key) => key.toUpperCase()); // result will be: // Map(3) { // 'A' => 1, // 'B' => 2, // 'C' => 3 // } ``` ##### mapValues _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function mapValues(map, getNewValue): Map; ``` Creates a new Map with the same keys but with values transformed by the provided function. This function takes a Map and a function that generates a new value from each value-key pair. It returns a new Map where the values are the result of applying the function to each entry, while the keys remain the same. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | | `R` | - | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to transform. | | `getNewValue` | (`value`, `key`, `object`) => `R` | A function that generates a new value from a value-key pair. | ## Returns `Map`\<`K`, `R`\> A new Map with the same keys and transformed values. ## Example ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3] ]); const result = mapValues(map, (value) => value * 2); // result will be: // Map(3) { // 'a' => 2, // 'b' => 4, // 'c' => 6 // } ``` ##### reduce _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function reduce( map, callback, initialValue?): A; ``` Reduces a Map to a single value by iterating through its entries and applying a callback function. This function iterates through all entries of the Map and applies the callback function to each entry, accumulating the result. If an initial value is provided, it is used as the starting accumulator value. If no initial value is provided and the Map is empty, a TypeError is thrown. ## Type Parameters | Type Parameter | Default type | Description | | :------ | :------ | :------ | | `K` | - | The type of keys in the Map. | | `V` | - | The type of values in the Map. | | `A` | `V` | - | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to reduce. | | `callback` | (`accumulator`, `value`, `key`, `map`) => `A` | A function that processes each entry and updates the accumulator. | | `initialValue?` | `A` | The initial value for the accumulator. If not provided, the first value in the Map is used. | ## Returns `A` The final accumulated value. ## Throws If the Map is empty and no initial value is provided. ## Examples ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3] ]); const result = reduce(map, (acc, value) => acc + value, 0); // result will be: 6 ``` ```ts const map = new Map([ ['a', 10], ['b', 20] ]); const result = reduce(map, (acc, value) => acc + value); // result will be: 30 (starts with first value 10) ``` ##### some _Import from `@varavel/vdl-plugin-sdk/utils/maps`._ ```ts function some(map, doesMatch): boolean; ``` Tests whether at least one entry in a Map satisfies the provided predicate function. This function iterates through the entries of the Map and checks if the predicate function returns true for at least one entry. It returns true if any entry satisfies the predicate, and false otherwise. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` | The type of keys in the Map. | | `V` | The type of values in the Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `map` | `Map`\<`K`, `V`\> | The Map to test. | | `doesMatch` | (`value`, `key`, `map`) => `boolean` | A predicate function that tests each entry. | ## Returns `boolean` true if at least one entry satisfies the predicate, false otherwise. ## Example ```ts const map = new Map([ ['a', 1], ['b', 2], ['c', 3] ]); const result = some(map, (value) => value > 2); // result will be: true const result2 = some(map, (value) => value > 5); // result2 will be: false ``` ### Math import: `@varavel/vdl-plugin-sdk/utils/math` _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ## Functions - [clamp](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/clamp.md) - [inRange](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/inRange.md) - [mean](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/mean.md) - [meanBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/meanBy.md) - [median](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/median.md) - [medianBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/medianBy.md) - [range](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/range.md) - [rangeRight](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/rangeRight.md) - [round](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/round.md) - [sum](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/sum.md) - [sumBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/math/functions/sumBy.md) #### Functions ##### clamp _Import from `@varavel/vdl-plugin-sdk/utils/math`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function clamp(value, maximum): number; ``` Clamps a number within the inclusive upper bound. This function takes a number and a maximum bound, and returns the number clamped within the specified upper bound. If only one bound is provided, it returns the minimum of the value and the bound. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | The number to clamp. | | `maximum` | `number` | The maximum bound to clamp the number. | ### Returns `number` The clamped number within the specified upper bound. ### Example ```ts const result1 = clamp(10, 5); // result1 will be 5, as 10 is clamped to the bound 5 ``` ## Call Signature ```ts function clamp( value, minimum, maximum): number; ``` Clamps a number within the inclusive lower and upper bounds. This function takes a number and two bounds, and returns the number clamped within the specified bounds. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | The number to clamp. | | `minimum` | `number` | The minimum bound to clamp the number. | | `maximum` | `number` | The maximum bound to clamp the number. | ### Returns `number` The clamped number within the specified bounds. ### Example ```ts const result2 = clamp(10, 5, 15); // result2 will be 10, as it is within the bounds 5 and 15 const result3 = clamp(2, 5, 15); // result3 will be 5, as 2 is clamped to the lower bound 5 const result4 = clamp(20, 5, 15); // result4 will be 15, as 20 is clamped to the upper bound 15 ``` ##### inRange _Import from `@varavel/vdl-plugin-sdk/utils/math`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function inRange(value, maximum): boolean; ``` Checks if the value is less than the maximum. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | The value to check. | | `maximum` | `number` | The upper bound of the range (exclusive). | ### Returns `boolean` `true` if the value is less than the maximum, otherwise `false`. ### Example ```ts const result = inRange(3, 5); // result will be true. const result2 = inRange(5, 5); // result2 will be false. ``` ## Call Signature ```ts function inRange( value, minimum, maximum): boolean; ``` Checks if the value is within the range defined by minimum (inclusive) and maximum (exclusive). ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | The value to check. | | `minimum` | `number` | The lower bound of the range (inclusive). | | `maximum` | `number` | The upper bound of the range (exclusive). | ### Returns `boolean` `true` if the value is within the specified range, otherwise `false`. ### Example ```ts const result = inRange(3, 2, 5); // result will be true. const result2 = inRange(1, 2, 5); // result2 will be false. ``` ##### mean _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function mean(nums): number; ``` Calculates the average of an array of numbers. If the array is empty, this function returns `NaN`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `nums` | readonly `number`[] | An array of numbers to calculate the average. | ## Returns `number` The average of all the numbers in the array. ## Example ```ts const numbers = [1, 2, 3, 4, 5]; const result = mean(numbers); // result will be 3 ``` ##### meanBy _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function meanBy(items, getValue): number; ``` Calculates the average of an array of numbers when applying the `getValue` function to each element. If the array is empty, this function returns `NaN`. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly `T`[] | An array to calculate the average. | | `getValue` | (`element`) => `number` | A function that selects a numeric value from each element. | ## Returns `number` The average of all the numbers as determined by the `getValue` function. ## Example ```ts meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2 meanBy([], x => x.a); // Returns: NaN ``` ##### median _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function median(nums): number; ``` Calculates the median of an array of numbers. The median is the middle value of a sorted array. If the array has an odd number of elements, the median is the middle value. If the array has an even number of elements, it returns the average of the two middle values. If the array is empty, this function returns `NaN`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `nums` | readonly `number`[] | An array of numbers to calculate the median. | ## Returns `number` The median of all the numbers in the array. ## Examples ```ts const arrayWithOddNumberOfElements = [1, 2, 3, 4, 5]; const result = median(arrayWithOddNumberOfElements); // result will be 3 ``` ```ts const arrayWithEvenNumberOfElements = [1, 2, 3, 4]; const result = median(arrayWithEvenNumberOfElements); // result will be 2.5 ``` ##### medianBy _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function medianBy(items, getValue): number; ``` Calculates the median of an array of elements when applying the `getValue` function to each element. The median is the middle value of a sorted array. If the array has an odd number of elements, the median is the middle value. If the array has an even number of elements, it returns the average of the two middle values. If the array is empty, this function returns `NaN`. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly `T`[] | An array to calculate the median. | | `getValue` | (`element`) => `number` | A function that selects a numeric value from each element. | ## Returns `number` The median of all the numbers as determined by the `getValue` function. ## Example ```ts medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }], x => x.a); // Returns: 3 medianBy([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], x => x.a); // Returns: 2.5 medianBy([], x => x.a); // Returns: NaN ``` ##### range _Import from `@varavel/vdl-plugin-sdk/utils/math`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function range(end): number[]; ``` Returns an array of numbers from `0` (inclusive) to `end` (exclusive), incrementing by `1`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `end` | `number` | The end number of the range (exclusive). | ### Returns `number`[] An array of numbers from `0` (inclusive) to `end` (exclusive) with a step of `1`. ### Example ```ts // Returns [0, 1, 2, 3] range(4); ``` ## Call Signature ```ts function range(start, end): number[]; ``` Returns an array of numbers from `start` (inclusive) to `end` (exclusive), incrementing by `1`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `start` | `number` | The starting number of the range (inclusive). | | `end` | `number` | The end number of the range (exclusive). | ### Returns `number`[] An array of numbers from `start` (inclusive) to `end` (exclusive) with a step of `1`. ### Example ```ts // Returns [1, 2, 3] range(1, 4); ``` ## Call Signature ```ts function range( start, end, step): number[]; ``` Returns an array of numbers from `start` (inclusive) to `end` (exclusive), incrementing by `step`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `start` | `number` | The starting number of the range (inclusive). | | `end` | `number` | The end number of the range (exclusive). | | `step` | `number` | The step value for the range. | ### Returns `number`[] An array of numbers from `start` (inclusive) to `end` (exclusive) with the specified `step`. ### Example ```ts // Returns [0, 5, 10, 15] range(0, 20, 5); ``` ##### rangeRight _Import from `@varavel/vdl-plugin-sdk/utils/math`._ Utility functions re-exported from `es-toolkit` (MIT License). See https://github.com/toss/es-toolkit for more details. ## Call Signature ```ts function rangeRight(end): number[]; ``` Returns an array of numbers from `end` (exclusive) to `0` (inclusive), decrementing by `1`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `end` | `number` | The end number of the range (exclusive). | ### Returns `number`[] An array of numbers from `end` (exclusive) to `0` (inclusive) with a step of `1`. ### Example ```ts // Returns [3, 2, 1, 0] rangeRight(4); ``` ## Call Signature ```ts function rangeRight(start, end): number[]; ``` Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `1`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `start` | `number` | The starting number of the range (inclusive). | | `end` | `number` | The end number of the range (exclusive). | ### Returns `number`[] An array of numbers from `end` (exclusive) to `start` (inclusive) with a step of `1`. ### Example ```ts // Returns [3, 2, 1] rangeRight(1, 4); ``` ## Call Signature ```ts function rangeRight( start, end, step): number[]; ``` Returns an array of numbers from `end` (exclusive) to `start` (inclusive), decrementing by `step`. ### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `start` | `number` | The starting number of the range (inclusive). | | `end` | `number` | The end number of the range (exclusive). | | `step` | `number` | The step value for the range. | ### Returns `number`[] An array of numbers from `end` (exclusive) to `start` (inclusive) with the specified `step`. ### Example ```ts // Returns [15, 10, 5, 0] rangeRight(0, 20, 5); ``` ##### round _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function round(value, precision?): number; ``` Rounds a number to a specified precision. This function takes a number and an optional precision value, and returns the number rounded to the specified number of decimal places. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | The number to round. | | `precision?` | `number` | The number of decimal places to round to. Defaults to 0. | ## Returns `number` The rounded number. ## Throws Throws an error if `Precision` is not integer. ## Example ```ts const result1 = round(1.2345); // result1 will be 1 const result2 = round(1.2345, 2); // result2 will be 1.23 const result3 = round(1.2345, 3); // result3 will be 1.235 const result4 = round(1.2345, 3.1); // This will throw an error ``` ##### sum _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function sum(nums): number; ``` Calculates the sum of an array of numbers. This function takes an array of numbers and returns the sum of all the elements in the array. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `nums` | readonly `number`[] | An array of numbers to be summed. | ## Returns `number` The sum of all the numbers in the array. ## Example ```ts const numbers = [1, 2, 3, 4, 5]; const result = sum(numbers); // result will be 15 ``` ##### sumBy _Import from `@varavel/vdl-plugin-sdk/utils/math`._ ```ts function sumBy(items, getValue): number; ``` Calculates the sum of an array of numbers when applying the `getValue` function to each element. If the array is empty, this function returns `0`. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the array. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | readonly `T`[] | An array to calculate the sum. | | `getValue` | (`element`, `index`) => `number` | A function that selects a numeric value from each element. It receives the element and its zero‑based index in the array. | ## Returns `number` The sum of all the numbers as determined by the `getValue` function. ## Example ```ts sumBy([{ a: 1 }, { a: 2 }, { a: 3 }], (x, i) => x.a * i); // Returns: 8 sumBy([], () => 1); // Returns: 0 ``` ### Markdown import: `@varavel/vdl-plugin-sdk/utils/markdown` _Import from `@varavel/vdl-plugin-sdk/utils/markdown`._ ## Functions - [firstParagraph](https://vdl-plugin-sdk.varavel.com/llms/api/utils/markdown/functions/firstParagraph.md) - [title](https://vdl-plugin-sdk.varavel.com/llms/api/utils/markdown/functions/title.md) - [wrapCode](https://vdl-plugin-sdk.varavel.com/llms/api/utils/markdown/functions/wrapCode.md) #### Functions ##### firstParagraph _Import from `@varavel/vdl-plugin-sdk/utils/markdown`._ ```ts function firstParagraph(content): string | undefined; ``` Returns the first paragraph-like content line from a Markdown document. This helper is useful for generating short descriptions, summaries, preview snippets, or metadata fields from longer Markdown content without parsing the full document structure. Blank lines are ignored, heading lines are skipped, and the first remaining content line is returned in trimmed form. If the document does not contain paragraph content, the function returns `undefined`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `content` | `string` | Markdown document content to inspect. | ## Returns `string` \| `undefined` The first non-heading content line, or `undefined` when absent. ## Example ```ts firstParagraph("# Changelog\n\nAdds new RPC helpers."); // "Adds new RPC helpers." ``` ##### title _Import from `@varavel/vdl-plugin-sdk/utils/markdown`._ ```ts function title(content): string; ``` Extracts the first Markdown heading from a document. This helper is intended for lightweight metadata discovery when a full Markdown parser would be unnecessary. It returns the text content of the first heading-like line found in the document and provides a stable fallback when no heading is present. The function is well suited for generators that need a document title for filenames, navigation labels, page metadata, or content indexes. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `content` | `string` | Markdown document content to inspect. | ## Returns `string` The first heading text, or `"Untitled"` when no heading is found. ## Examples ```ts title("# API Reference\n\nGenerated docs"); // "API Reference" ``` ```ts title("No heading here"); // "Untitled" ``` ##### wrapCode _Import from `@varavel/vdl-plugin-sdk/utils/markdown`._ ```ts function wrapCode(code, lang?): string; ``` Wraps source text in a fenced Markdown code block. This helper is intended for generators that emit documentation examples, snippets, or inline reference material and need a reliable way to format code as Markdown without repeating string templates throughout the codebase. When a language is provided, it becomes the fence info string so downstream renderers can apply syntax highlighting. Backticks inside the code content are escaped so generated blocks remain safe to embed inside surrounding Markdown. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `code` | `string` | `undefined` | Code or text content to place inside the fenced block. | | `lang` | `string` | `""` | Optional language identifier for syntax highlighting. | ## Returns `string` A complete fenced Markdown code block. ## Example ```ts wrapCode("const answer = 42;", "ts"); // "```ts\nconst answer = 42;\n```" ``` ### Objects import: `@varavel/vdl-plugin-sdk/utils/objects` _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ## Functions - [clone](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/clone.md) - [cloneDeep](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/cloneDeep.md) - [findKey](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/findKey.md) - [flattenObject](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/flattenObject.md) - [invert](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/invert.md) - [mapKeys](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/mapKeys.md) - [mapValues](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/mapValues.md) - [merge](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/merge.md) - [mergeWith](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/mergeWith.md) - [omit](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/omit.md) - [omitBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/omitBy.md) - [pick](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/pick.md) - [pickBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/pickBy.md) - [toMerged](https://vdl-plugin-sdk.varavel.com/llms/api/utils/objects/functions/toMerged.md) #### Functions ##### clone _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function clone(obj): T; ``` Creates a shallow clone of the given object. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to clone. | ## Returns `T` - A shallow clone of the given object. ## Examples ```ts // Clone a primitive values const num = 29; const clonedNum = clone(num); console.log(clonedNum); // 29 console.log(clonedNum === num); // true ``` ```ts // Clone an array const arr = [1, 2, 3]; const clonedArr = clone(arr); console.log(clonedArr); // [1, 2, 3] console.log(clonedArr === arr); // false ``` ```ts // Clone an object const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; const clonedObj = clone(obj); console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } console.log(clonedObj === obj); // false ``` ##### cloneDeep _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function cloneDeep(obj): T; ``` Creates a deep clone of the given object. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of the object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to clone. | ## Returns `T` - A deep clone of the given object. ## Examples ```ts // Clone a primitive values const num = 29; const clonedNum = cloneDeep(num); console.log(clonedNum); // 29 console.log(clonedNum === num); // true ``` ```ts // Clone an array const arr = [1, 2, 3]; const clonedArr = cloneDeep(arr); console.log(clonedArr); // [1, 2, 3] console.log(clonedArr === arr); // false ``` ```ts // Clone an array with nested objects const arr = [1, { a: 1 }, [1, 2, 3]]; const clonedArr = cloneDeep(arr); arr[1].a = 2; console.log(arr); // [1, { a: 2 }, [1, 2, 3]] console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]] console.log(clonedArr === arr); // false ``` ```ts // Clone an object const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] }; const clonedObj = cloneDeep(obj); console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] } console.log(clonedObj === obj); // false ``` ```ts // Clone an object with nested objects const obj = { a: 1, b: { c: 1 } }; const clonedObj = cloneDeep(obj); obj.b.c = 2; console.log(obj); // { a: 1, b: { c: 2 } } console.log(clonedObj); // { a: 1, b: { c: 1 } } console.log(clonedObj === obj); // false ``` ##### findKey _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function findKey(obj, predicate): keyof T | undefined; ``` Finds the key of the first element in the object that satisfies the provided testing function. ## Type Parameters | Type Parameter | | :------ | | `T` *extends* `Record`\<`any`, `any`\> | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to search. | | `predicate` | (`value`, `key`, `obj`) => `boolean` | The function to execute on each value in the object. It takes three arguments: - value: The current value being processed in the object. - key: The key of the current value being processed in the object. - obj: The object that findKey was called upon. | ## Returns keyof `T` \| `undefined` The key of the first element in the object that passes the test, or undefined if no element passes. ## Example ```ts const users = { 'barney': { 'age': 36, 'active': true }, 'fred': { 'age': 40, 'active': false }, 'pebbles': { 'age': 1, 'active': true } }; findKey(users, function(o) { return o.age < 40; }); => 'barney' ``` ##### flattenObject _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function flattenObject(object, __namedParameters?): Record; ``` Flattens a nested object into a single level object with delimiter-separated keys. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `object` | `object` | The object to flatten. | | `__namedParameters?` | `FlattenObjectOptions` | - | ## Returns `Record`\<`string`, `any`\> - The flattened object. ## Example ```ts const nestedObject = { a: { b: { c: 1 } }, d: [2, 3] }; const flattened = flattenObject(nestedObject); console.log(flattened); // Output: // { // 'a.b.c': 1, // 'd.0': 2, // 'd.1': 3 // } ``` ##### invert _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function invert(obj): Record; ``` Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa. This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values, the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping of the input object's key-value pairs. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `K` *extends* `PropertyKey` | Type of the keys in the input object (string, number, symbol) | | `V` *extends* `PropertyKey` | Type of the values in the input object (string, number, symbol) | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `Record`\<`K`, `V`\> | The input object whose keys and values are to be inverted | ## Returns `Record`\<`V`, `K`\> - A new object with keys and values inverted ## Example ```ts invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' } invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' } invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' } invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' } ``` ##### mapKeys _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function mapKeys(object, getNewKey): Record; ``` Creates a new object with the same values as the given object, but with keys generated by running each own enumerable property of the object through the iteratee function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`PropertyKey`, `any`\> | The type of the object. | | `K` *extends* `PropertyKey` | The type of the new keys generated by the iteratee function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `object` | `T` | The object to iterate over. | | `getNewKey` | (`value`, `key`, `object`) => `K` | The function invoked per own enumerable property. | ## Returns `Record`\<`K`, `T`\[keyof `T`\]\> - Returns the new mapped object. ## Example ```ts // Example usage: const obj = { a: 1, b: 2 }; const result = mapKeys(obj, (value, key) => key + value); console.log(result); // { a1: 1, b2: 2 } ``` ##### mapValues _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function mapValues(object, getNewValue): Record; ``` Creates a new object with the same keys as the given object, but with values generated by running each own enumerable property of the object through the iteratee function. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `object` | The type of the object. | | `K` *extends* `string` \| `number` \| `symbol` | The type of the keys in the object. | | `V` | The type of the new values generated by the iteratee function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `object` | `T` | The object to iterate over. | | `getNewValue` | (`value`, `key`, `object`) => `V` | The function invoked per own enumerable property. | ## Returns `Record`\<`K`, `V`\> - Returns the new mapped object. ## Example ```ts // Example usage: const obj = { a: 1, b: 2 }; const result = mapValues(obj, (value) => value * 2); console.log(result); // { a: 2, b: 4 } ``` ##### merge _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function merge(target, source): T & S; ``` Merges the properties of the source object into the target object. This function performs a deep merge, meaning nested objects and arrays are merged recursively. If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged. If a property in the source object is undefined, it will not overwrite a defined property in the target object. Note that this function mutates the target object. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the target object. | | `S` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the source object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `target` | `T` | The target object into which the source object properties will be merged. This object is modified in place. | | `source` | `S` | The source object whose properties will be merged into the target object. | ## Returns `T` & `S` The updated target object with properties from the source object merged in. ## Examples ```ts const target = { a: 1, b: { x: 1, y: 2 } }; const source = { b: { y: 3, z: 4 }, c: 5 }; const result = merge(target, source); console.log(result); // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 } ``` ```ts const target = { a: [1, 2], b: { x: 1 } }; const source = { a: [3], b: { y: 2 } }; const result = merge(target, source); console.log(result); // Output: { a: [3, 2], b: { x: 1, y: 2 } } ``` ```ts const target = { a: null }; const source = { a: [1, 2, 3] }; const result = merge(target, source); console.log(result); // Output: { a: [1, 2, 3] } ``` ##### mergeWith _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function mergeWith( target, source, merge): T & S; ``` Merges the properties of the source object into the target object. You can provide a custom `merge` function to control how properties are merged. It should return the value to be set in the target object. If it returns `undefined`, a default deep merge will be applied for arrays and objects: - If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged. - If a property in the source object is undefined, it will not overwrite a defined property in the target object. Note that this function mutates the target object. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the target object. | | `S` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the source object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `target` | `T` | The target object into which the source object properties will be merged. This object is modified in place. | | `source` | `S` | The source object whose properties will be merged into the target object. | | `merge` | (`targetValue`, `sourceValue`, `key`, `target`, `source`) => `any` | A custom merge function that defines how properties should be combined. It receives the following arguments: - `targetValue`: The current value of the property in the target object. - `sourceValue`: The value of the property in the source object. - `key`: The key of the property being merged. - `target`: The target object. - `source`: The source object. | ## Returns `T` & `S` The updated target object with properties from the source object merged in. ## Examples ```ts const target = { a: 1, b: 2 }; const source = { b: 3, c: 4 }; mergeWith(target, source, (targetValue, sourceValue) => { if (typeof targetValue === 'number' && typeof sourceValue === 'number') { return targetValue + sourceValue; } }); // Returns { a: 1, b: 5, c: 4 } ``` ```ts const target = { a: [1], b: [2] }; const source = { a: [3], b: [4] }; const result = mergeWith(target, source, (objValue, srcValue) => { if (Array.isArray(objValue)) { return objValue.concat(srcValue); } }); expect(result).toEqual({ a: [1, 3], b: [2, 4] }); ``` ##### omit _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function omit(obj, keys): Omit; ``` Creates a new object with specified keys omitted. This function takes an object and an array of keys, and returns a new object that excludes the properties corresponding to the specified keys. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`string`, `any`\> | The type of object. | | `K` *extends* `string` \| `number` \| `symbol` | The type of keys in object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to omit keys from. | | `keys` | readonly `K`[] | An array of keys to be omitted from the object. | ## Returns `Omit`\<`T`, `K`\> A new object with the specified keys omitted. ## Example ```ts const obj = { a: 1, b: 2, c: 3 }; const result = omit(obj, ['b', 'c']); // result will be { a: 1 } ``` ##### omitBy _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function omitBy(obj, shouldOmit): Partial; ``` Creates a new object composed of the properties that do not satisfy the predicate function. This function takes an object and a predicate function, and returns a new object that includes only the properties for which the predicate function returns false. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`string`, `any`\> | The type of object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to omit properties from. | | `shouldOmit` | (`value`, `key`) => `boolean` | A predicate function that determines whether a property should be omitted. It takes the property's key and value as arguments and returns `true` if the property should be omitted, and `false` otherwise. | ## Returns `Partial`\<`T`\> A new object with the properties that do not satisfy the predicate function. ## Example ```ts const obj = { a: 1, b: 'omit', c: 3 }; const shouldOmit = (value) => typeof value === 'string'; const result = omitBy(obj, shouldOmit); // result will be { a: 1, c: 3 } ``` ##### pick _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function pick(obj, keys): Pick; ``` Creates a new object composed of the picked object properties. This function takes an object and an array of keys, and returns a new object that includes only the properties corresponding to the specified keys. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`string`, `any`\> | The type of object. | | `K` *extends* `string` \| `number` \| `symbol` | The type of keys in object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to pick keys from. | | `keys` | readonly `K`[] | An array of keys to be picked from the object. | ## Returns `Pick`\<`T`, `K`\> A new object with the specified keys picked. ## Example ```ts const obj = { a: 1, b: 2, c: 3 }; const result = pick(obj, ['a', 'c']); // result will be { a: 1, c: 3 } ``` ##### pickBy _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function pickBy(obj, shouldPick): Partial; ``` Creates a new object composed of the properties that satisfy the predicate function. This function takes an object and a predicate function, and returns a new object that includes only the properties for which the predicate function returns true. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`string`, `any`\> | The type of object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `obj` | `T` | The object to pick properties from. | | `shouldPick` | (`value`, `key`) => `boolean` | A predicate function that determines whether a property should be picked. It takes the property's key and value as arguments and returns `true` if the property should be picked, and `false` otherwise. | ## Returns `Partial`\<`T`\> A new object with the properties that satisfy the predicate function. ## Example ```ts const obj = { a: 1, b: 'pick', c: 3 }; const shouldPick = (value) => typeof value === 'string'; const result = pickBy(obj, shouldPick); // result will be { b: 'pick' } ``` ##### toMerged _Import from `@varavel/vdl-plugin-sdk/utils/objects`._ ```ts function toMerged(target, source): T & S; ``` Merges the properties of the source object into a deep clone of the target object. Unlike `merge`, This function does not modify the original target object. This function performs a deep merge, meaning nested objects and arrays are merged recursively. - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged. - If a property in the source object is undefined, it will not overwrite a defined property in the target object. Note that this function does not mutate the target object. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the target object. | | `S` *extends* `Record`\<`PropertyKey`, `any`\> | Type of the source object. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `target` | `T` | The target object to be cloned and merged into. This object is not modified directly. | | `source` | `S` | The source object whose properties will be merged into the cloned target object. | ## Returns `T` & `S` A new object with properties from the source object merged into a deep clone of the target object. ## Examples ```ts const target = { a: 1, b: { x: 1, y: 2 } }; const source = { b: { y: 3, z: 4 }, c: 5 }; const result = toMerged(target, source); console.log(result); // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 } ``` ```ts const target = { a: [1, 2], b: { x: 1 } }; const source = { a: [3], b: { y: 2 } }; const result = toMerged(target, source); console.log(result); // Output: { a: [3, 2], b: { x: 1, y: 2 } } ``` ```ts const target = { a: null }; const source = { a: [1, 2, 3] }; const result = toMerged(target, source); console.log(result); // Output: { a: [1, 2, 3] } ``` ### Sets import: `@varavel/vdl-plugin-sdk/utils/sets` _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ## Functions - [countBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/countBy.md) - [every](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/every.md) - [filter](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/filter.md) - [find](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/find.md) - [keyBy](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/keyBy.md) - [map](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/map.md) - [reduce](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/reduce.md) - [some](https://vdl-plugin-sdk.varavel.com/llms/api/utils/sets/functions/some.md) #### Functions ##### countBy _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function countBy(set, mapper): Map; ``` Counts the occurrences of items in a Set based on a transformation function. This function takes a Set and a function that generates a key from each value. It returns a Map with the generated keys and their counts as values. The count is incremented for each element for which the transformation produces the same key. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | | `K` | The type of keys produced by the transformation function. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to count occurrences from. | | `mapper` | (`value`, `value2`, `set`) => `K` | The function to produce a key for counting. | ## Returns `Map`\<`K`, `number`\> A Map containing the mapped keys and their counts. ## Examples ```ts const set = new Set([1, 2, 3, 4, 5]); const result = countBy(set, (value) => value % 2 === 0 ? 'even' : 'odd'); // result will be Map(2) { 'odd' => 3, 'even' => 2 } ``` ```ts const set = new Set(['apple', 'banana', 'cherry']); const result = countBy(set, (value) => value.length); // result will be Map(2) { 5 => 1, 6 => 2 } ``` ##### every _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function every(set, doesMatch): boolean; ``` Tests whether all elements in a Set satisfy the provided predicate function. This function iterates through all elements of the Set and checks if the predicate function returns true for every element. It returns true if the predicate is satisfied for all elements, and false otherwise. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to test. | | `doesMatch` | (`value`, `value2`, `set`) => `boolean` | A predicate function that tests each element. | ## Returns `boolean` true if all elements satisfy the predicate, false otherwise. ## Example ```ts const set = new Set([10, 20, 30]); const result = every(set, (value) => value > 5); // result will be: true const result2 = every(set, (value) => value > 15); // result2 will be: false ``` ##### filter _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function filter(set, callback): Set; ``` Filters a Set based on a predicate function. This function takes a Set and a predicate function, and returns a new Set containing only the elements for which the predicate function returns true. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to filter. | | `callback` | (`value`, `value2`, `set`) => `boolean` | A predicate function that tests each element. | ## Returns `Set`\<`T`\> A new Set containing only the elements that satisfy the predicate. ## Example ```ts const set = new Set([1, 2, 3, 4, 5]); const result = filter(set, (value) => value > 2); // result will be: // Set(3) { 3, 4, 5 } ``` ##### find _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function find(set, doesMatch): T | undefined; ``` Finds the first element in a Set for which the predicate function returns true. This function iterates through the elements of the Set and returns the first element for which the predicate function returns true. If no element satisfies the predicate, it returns undefined. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to search. | | `doesMatch` | (`value`, `value2`, `set`) => `boolean` | A predicate function that tests each element. | ## Returns `T` \| `undefined` The first element that satisfies the predicate, or undefined if none found. ## Example ```ts const set = new Set([ { name: 'apple', quantity: 10 }, { name: 'banana', quantity: 5 }, { name: 'grape', quantity: 15 } ]); const result = find(set, (value) => value.quantity > 10); // result will be: { name: 'grape', quantity: 15 } ``` ##### keyBy _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function keyBy(set, getKeyFromValue): Map; ``` Maps each element of a Set based on a provided key-generating function. This function takes a Set and a function that generates a key from each value. It returns a new Map where the keys are generated by the key function and the values are the corresponding values from the original set. If multiple elements produce the same key, the last value encountered will be used. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | | `K` | The type of keys to produce in the returned Map. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The set of elements to be mapped. | | `getKeyFromValue` | (`value`, `value2`, `set`) => `K` | A function that generates a key from a value. | ## Returns `Map`\<`K`, `T`\> A Map where the generated keys are mapped to each element's value. ## Example ```ts const set = new Set([ { type: 'fruit', name: 'apple' }, { type: 'fruit', name: 'banana' }, { type: 'vegetable', name: 'carrot' } ]); const result = keyBy(set, item => item.type); // result will be: // Map(2) { // 'fruit' => { type: 'fruit', name: 'banana' }, // 'vegetable' => { type: 'vegetable', name: 'carrot' } // } ``` ##### map _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function map(set, getNewValue): Set; ``` Creates a new Set with elements transformed by the provided function. This function takes a Set and a function that generates a new value from each element. It returns a new Set where the elements are the result of applying the function to each element. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the input Set. | | `U` | The type of elements in the output Set. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to transform. | | `getNewValue` | (`value`, `value2`, `set`) => `U` | A function that generates a new value from an element. | ## Returns `Set`\<`U`\> A new Set with transformed elements. ## Example ```ts const set = new Set([1, 2, 3]); const result = map(set, (value) => value * 2); // result will be: // Set(3) { 2, 4, 6 } ``` ##### reduce _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function reduce( set, callback, initialValue?): A; ``` Reduces a Set to a single value by iterating through its elements and applying a callback function. This function iterates through all elements of the Set and applies the callback function to each element, accumulating the result. If an initial value is provided, it is used as the starting accumulator value. If no initial value is provided and the Set is empty, a TypeError is thrown. ## Type Parameters | Type Parameter | Default type | Description | | :------ | :------ | :------ | | `T` | - | The type of elements in the Set. | | `A` | `T` | The type of the accumulator. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to reduce. | | `callback` | (`accumulator`, `value`, `value2`, `set`) => `A` | A function that processes each element and updates the accumulator. | | `initialValue?` | `A` | The initial value for the accumulator. If not provided, the first element in the Set is used. | ## Returns `A` The final accumulated value. ## Throws If the Set is empty and no initial value is provided. ## Examples ```ts const set = new Set([1, 2, 3]); const result = reduce(set, (acc, value) => acc + value, 0); // result will be: 6 ``` ```ts const set = new Set([10, 20]); const result = reduce(set, (acc, value) => acc + value); // result will be: 30 (starts with first value 10) ``` ##### some _Import from `@varavel/vdl-plugin-sdk/utils/sets`._ ```ts function some(set, doesMatch): boolean; ``` Tests whether at least one element in a Set satisfies the provided predicate function. This function iterates through the elements of the Set and checks if the predicate function returns true for at least one element. It returns true if any element satisfies the predicate, and false otherwise. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of elements in the Set. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `set` | `Set`\<`T`\> | The Set to test. | | `doesMatch` | (`value`, `value2`, `set`) => `boolean` | A predicate function that tests each element. | ## Returns `boolean` true if at least one element satisfies the predicate, false otherwise. ## Example ```ts const set = new Set([1, 2, 3]); const result = some(set, (value) => value > 2); // result will be: true const result2 = some(set, (value) => value > 5); // result2 will be: false ``` ### Paths import: `@varavel/vdl-plugin-sdk/utils/paths` _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ## Functions - [basename](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/basename.md) - [dirname](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/dirname.md) - [extname](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/extname.md) - [filename](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/filename.md) - [isAbsolute](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/isAbsolute.md) - [join](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/join.md) - [normalize](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/normalize.md) - [relative](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/relative.md) - [resolve](https://vdl-plugin-sdk.varavel.com/llms/api/utils/paths/functions/resolve.md) #### Functions ##### basename _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function basename(path, extension?): string; ``` Returns the last path segment, optionally removing a known extension suffix. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to inspect. | | `extension?` | `string` | Optional extension suffix to remove from the result. | ## Returns `string` The basename of `path`. ## Example ```ts basename("generated/models/user.ts"); // returns "user.ts" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### dirname _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function dirname(path): string; ``` Returns the parent directory portion of a path. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to inspect. | ## Returns `string` The directory name portion of `path`. ## Example ```ts dirname("generated/models/user.ts"); // returns "generated/models" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### extname _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function extname(path): string; ``` Returns the file extension of a path, including the leading dot. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to inspect. | ## Returns `string` The extension portion of `path`, or an empty string when none exists. ## Example ```ts extname("generated/models/user.ts"); // returns ".ts" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### filename _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function filename(path): string | undefined; ``` Returns the filename without its extension. This is useful for deriving stable artifact names without manually stripping directory segments or extensions. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to inspect. | ## Returns `string` \| `undefined` The filename without its extension, or `undefined` when it cannot be derived. ## Example ```ts filename("generated/models/user.ts"); // returns "user" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### isAbsolute _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function isAbsolute(path): boolean; ``` Checks whether a path is absolute. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to inspect. | ## Returns `boolean` `true` when `path` is absolute, otherwise `false`. ## Example ```ts isAbsolute("/generated/models/user.ts"); // returns true ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### join _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function join(...parts): string; ``` Joins path segments using deterministic forward-slash normalization. This is a thin wrapper around `pathe.join`, which keeps behavior consistent across platforms and normalizes path separators to `/`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | ...`parts` | `string`[] | Path segments to join. | ## Returns `string` The normalized joined path. ## Example ```ts join("generated", "models", "user.ts"); // returns "generated/models/user.ts" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### normalize _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function normalize(path): string; ``` Normalizes a path by collapsing redundant separators and dot segments. This is helpful when plugin code receives mixed Windows and POSIX-style path input and needs a single predictable format. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `path` | `string` | Path to normalize. | ## Returns `string` The normalized path using `/` separators. ## Example ```ts normalize("generated\\models/../types/user.ts"); // returns "generated/types/user.ts" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### relative _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function relative(from, to): string; ``` Computes the relative path from one location to another. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `from` | `string` | Starting path. | | `to` | `string` | Destination path. | ## Returns `string` The normalized relative path from `from` to `to`. ## Example ```ts relative("generated/models", "generated/types/user.ts"); // returns "../types/user.ts" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ##### resolve _Import from `@varavel/vdl-plugin-sdk/utils/paths`._ ```ts function resolve(...parts): string; ``` Resolves one or more path segments into a normalized absolute or rooted path. This is useful when plugin code needs stable path resolution without relying on platform-specific separators. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | ...`parts` | `string`[] | Path segments to resolve. | ## Returns `string` The resolved normalized path. ## Example ```ts resolve("/workspace/plugin", "src", "../dist/index.js"); // returns "/workspace/plugin/dist/index.js" ``` ## See Powered by `pathe` (MIT License): [https://github.com/unjs/pathe](https://github.com/unjs/pathe) ### Crypto import: `@varavel/vdl-plugin-sdk/utils/crypto` _Import from `@varavel/vdl-plugin-sdk/utils/crypto`._ ## Functions - [fingerprint](https://vdl-plugin-sdk.varavel.com/llms/api/utils/crypto/functions/fingerprint.md) - [hash](https://vdl-plugin-sdk.varavel.com/llms/api/utils/crypto/functions/hash.md) #### Functions ##### fingerprint _Import from `@varavel/vdl-plugin-sdk/utils/crypto`._ ```ts function fingerprint(input): string; ``` Generates a short, stable, and URL-friendly 8-character hexadecimal string from any JavaScript value. This helper is ideal for creating "pretty" identifiers, such as asset filenames, CSS class names, or unique URL slugs, where brevity and readability are prioritized over cryptographic strength. Unlike the `hash` function, this returns a fixed-length string consisting only of hexadecimal characters ([0-9a-f]). WARNING: This helper is not intended for password hashing or other security-sensitive cryptographic workflows. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | `unknown` | Any JavaScript value to fingerprint (strings, numbers, objects, etc). | ## Returns `string` A short 8-character hexadecimal string. ## Example ```ts fingerprint({ foo: "bar", baz: "qux" }); // returns a short deterministic string such as "20665513" ``` ##### hash _Import from `@varavel/vdl-plugin-sdk/utils/crypto`._ ```ts function hash(input): string; ``` Hashes any JavaScript value into a deterministic string. The value is serialized first and then hashed, which makes this helper useful for cache keys, content fingerprints, and change detection inside plugins. WARNING: This helper is not intended for password hashing or other security-sensitive cryptographic workflows. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `input` | `unknown` | Any JavaScript value to hash (strings, numbers, objects, etc). | ## Returns `string` A stable hash string for the provided input. ## Example ```ts hash({ foo: "bar", baz: "qux" }); // returns a deterministic hash string such as "9nMwOfcM8M06tjTZT0Uu68tWDaJQ_rmW6b9nZ1VRoAg" ``` ## See Powered by `ohash` (MIT): [https://github.com/unjs/ohash](https://github.com/unjs/ohash) ### Predicates import: `@varavel/vdl-plugin-sdk/utils/predicates` _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ## Functions - [isBoolean](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isBoolean.md) - [isDate](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isDate.md) - [isEmptyObject](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isEmptyObject.md) - [isEqual](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isEqual.md) - [isError](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isError.md) - [isFunction](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isFunction.md) - [isJSON](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isJSON.md) - [isJSONValue](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isJSONValue.md) - [isMap](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isMap.md) - [isNil](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isNil.md) - [isNotNil](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isNotNil.md) - [isNull](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isNull.md) - [isNumber](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isNumber.md) - [isPlainObject](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isPlainObject.md) - [isPrimitive](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isPrimitive.md) - [isRegExp](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isRegExp.md) - [isSet](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isSet.md) - [isString](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isString.md) - [isUndefined](https://vdl-plugin-sdk.varavel.com/llms/api/utils/predicates/functions/isUndefined.md) #### Functions ##### isBoolean _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isBoolean(x): x is boolean; ``` Checks if the given value is boolean. This function tests whether the provided value is strictly `boolean`. It returns `true` if the value is `boolean`, and `false` otherwise. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `unknown` | The Value to test if it is boolean. | ## Returns `x is boolean` True if the value is boolean, false otherwise. ## Example ```ts const value1 = true; const value2 = 0; const value3 = 'abc'; console.log(isBoolean(value1)); // true console.log(isBoolean(value2)); // false console.log(isBoolean(value3)); // false ``` ##### isDate _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isDate(value): value is Date; ``` Checks if `value` is a Date object. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is Date` Returns `true` if `value` is a Date object, `false` otherwise. ## Example ```ts const value1 = new Date(); const value2 = '2024-01-01'; console.log(isDate(value1)); // true console.log(isDate(value2)); // false ``` ##### isEmptyObject _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isEmptyObject(value): value is Record; ``` Checks if a value is an empty plain object. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is Record` - True if the value is an empty plain object, otherwise false. ## Example ```ts isEmptyObject({}); // true isEmptyObject({ a: 1 }); // false isEmptyObject([]); // false isEmptyObject(null); // false ``` ##### isEqual _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isEqual(a, b): boolean; ``` Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `a` | `any` | The first value to compare. | | `b` | `any` | The second value to compare. | ## Returns `boolean` `true` if the values are equal, otherwise `false`. ## Example ```ts isEqual(1, 1); // true isEqual({ a: 1 }, { a: 1 }); // true isEqual(/abc/g, /abc/g); // true isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true isEqual([1, 2, 3], [1, 2, 3]); // true ``` ##### isError _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isError(value): value is Error; ``` Checks if `value` is an Error object. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is Error` Returns `true` if `value` is an Error object, `false` otherwise. ## Example ```typescript console.log(isError(new Error())); // true console.log(isError('Error')); // false console.log(isError({ name: 'Error', message: '' })); // false ``` ##### isFunction _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isFunction(value): value is (args: any[]) => any; ``` Checks if `value` is a function. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `any` | The value to check. | ## Returns `value is (args: any[]) => any` Returns `true` if `value` is a function, else `false`. ## Example ```ts isFunction(Array.prototype.slice); // true isFunction(async function () {}); // true isFunction(function* () {}); // true isFunction(Proxy); // true isFunction(Int8Array); // true ``` ##### isJSON _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isJSON(value): value is string; ``` Checks if a given value is a valid JSON string. A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON specifications, valid JSON can represent: - Objects (with string keys and valid JSON values) - Arrays (containing valid JSON values) - Strings - Numbers - Booleans - null String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered valid JSON and will return true. This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is string` Returns `true` if `value` is a valid JSON string, else `false`. ## Example ```ts isJSON('{"name":"John","age":30}'); // true isJSON('[1,2,3]'); // true isJSON('true'); // true isJSON('invalid json'); // false isJSON({ name: 'John' }); // false (not a string) isJSON(null); // false (not a string) ``` ##### isJSONValue _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isJSONValue(value): value is string | number | boolean | any[] | Record | null; ``` Checks if a given value is a valid JSON value. A valid JSON value can be: - null - a JSON object (an object with string keys and valid JSON values) - a JSON array (an array of valid JSON values) - a string - a number - a boolean ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns value is string \| number \| boolean \| any\[\] \| Record\ \| null - True if the value is a valid JSON value, otherwise false. ## Example ```ts console.log(isJSONValue(null)); // true console.log(isJSONValue({ key: "value" })); // true console.log(isJSONValue([1, 2, 3])); // true console.log(isJSONValue("Hello")); // true console.log(isJSONValue(42)); // true console.log(isJSONValue(true)); // true console.log(isJSONValue(undefined)); // false console.log(isJSONValue(() => {})); // false ``` ##### isMap _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isMap(value): value is Map; ``` Checks if a given value is `Map`. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Map`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check if it is a `Map`. | ## Returns `value is Map` Returns `true` if `value` is a `Map`, else `false`. ## Example ```ts const value1 = new Map(); const value2 = new Set(); const value3 = new WeakMap(); console.log(isMap(value1)); // true console.log(isMap(value2)); // false console.log(isMap(value3)); // false ``` ##### isNil _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isNil(x): x is null | undefined; ``` Checks if a given value is null or undefined. This function tests whether the provided value is either `null` or `undefined`. It returns `true` if the value is `null` or `undefined`, and `false` otherwise. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `unknown` | The value to test for null or undefined. | ## Returns x is null \| undefined `true` if the value is null or undefined, `false` otherwise. ## Example ```ts const value1 = null; const value2 = undefined; const value3 = 42; const result1 = isNil(value1); // true const result2 = isNil(value2); // true const result3 = isNil(value3); // false ``` ##### isNotNil _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isNotNil(x): x is T; ``` Checks if the given value is not null nor undefined. The main use of this function is to be used with TypeScript as a type predicate. ## Type Parameters | Type Parameter | Description | | :------ | :------ | | `T` | The type of value. | ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `T` \| `null` \| `undefined` | The value to test if it is not null nor undefined. | ## Returns `x is T` True if the value is not null nor undefined, false otherwise. ## Example ```ts // Here the type of `arr` is (number | undefined)[] const arr = [1, undefined, 3]; // Here the type of `result` is number[] const result = arr.filter(isNotNil); // result will be [1, 3] ``` ##### isNull _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isNull(x): x is null; ``` Checks if the given value is null. This function tests whether the provided value is strictly equal to `null`. It returns `true` if the value is `null`, and `false` otherwise. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `unknown` | The value to test if it is null. | ## Returns `x is null` True if the value is null, false otherwise. ## Example ```ts const value1 = null; const value2 = undefined; const value3 = 42; console.log(isNull(value1)); // true console.log(isNull(value2)); // false console.log(isNull(value3)); // false ``` ##### isNumber _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isNumber(x): x is number; ``` Checks if the given value is a number. This function tests whether the provided value is strictly a `number`. It returns `true` if the value is a `number`, and `false` otherwise. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `unknown` | The value to test if it is a number. | ## Returns `x is number` True if the value is a number, false otherwise. ## Example ```ts const value1 = 123; const value2 = 'abc'; const value3 = true; console.log(isNumber(value1)); // true console.log(isNumber(value2)); // false console.log(isNumber(value3)); // false ``` ##### isPlainObject _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isPlainObject(value): value is Record; ``` Checks if a given value is a plain object. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is Record` - True if the value is a plain object, otherwise false. ## Example ```typescript // ✅👇 True isPlainObject({ }); // ✅ isPlainObject({ key: 'value' }); // ✅ isPlainObject({ key: new Date() }); // ✅ isPlainObject(new Object()); // ✅ isPlainObject(Object.create(null)); // ✅ isPlainObject({ nested: { key: true} }); // ✅ isPlainObject(new Proxy({}, {})); // ✅ isPlainObject({ [Symbol('tag')]: 'A' }); // ✅ // ✅👇 (cross-realms, node context, workers, ...) const runInNewContext = await import('node:vm').then( (mod) => mod.runInNewContext ); isPlainObject(runInNewContext('({})')); // ✅ // ❌👇 False class Test { }; isPlainObject(new Test()) // ❌ isPlainObject(10); // ❌ isPlainObject(null); // ❌ isPlainObject('hello'); // ❌ isPlainObject([]); // ❌ isPlainObject(new Date()); // ❌ isPlainObject(new Uint8Array([1])); // ❌ isPlainObject(Buffer.from('ABC')); // ❌ isPlainObject(Promise.resolve({})); // ❌ isPlainObject(Object.create({})); // ❌ isPlainObject(new (class Cls {})); // ❌ isPlainObject(globalThis); // ❌, ``` ##### isPrimitive _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isPrimitive(value): value is string | number | bigint | boolean | symbol | null | undefined; ``` Checks whether a value is a JavaScript primitive. JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns value is string \| number \| bigint \| boolean \| symbol \| null \| undefined Returns true if `value` is a primitive, false otherwise. ## Example ```ts isPrimitive(null); // true isPrimitive(undefined); // true isPrimitive('123'); // true isPrimitive(false); // true isPrimitive(true); // true isPrimitive(Symbol('a')); // true isPrimitive(123n); // true isPrimitive({}); // false isPrimitive(new Date()); // false isPrimitive(new Map()); // false isPrimitive(new Set()); // false isPrimitive([1, 2, 3]); // false ``` ##### isRegExp _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isRegExp(value): value is RegExp; ``` Checks if `value` is a RegExp. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check. | ## Returns `value is RegExp` Returns `true` if `value` is a RegExp, `false` otherwise. ## Example ```ts const value1 = /abc/; const value2 = '/abc/'; console.log(isRegExp(value1)); // true console.log(isRegExp(value2)); // false ``` ##### isSet _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isSet(value): value is Set; ``` Checks if a given value is `Set`. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Set`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check if it is a `Set`. | ## Returns `value is Set` Returns `true` if `value` is a `Set`, else `false`. ## Example ```ts const value1 = new Set(); const value2 = new Map(); const value3 = new WeakSet(); console.log(isSet(value1)); // true console.log(isSet(value2)); // false console.log(isSet(value3)); // false ``` ##### isString _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isString(value): value is string; ``` Checks if a given value is string. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `unknown` | The value to check if it is string. | ## Returns `value is string` Returns `true` if `value` is a string, else `false`. ## Example ```ts const value1 = 'abc'; const value2 = 123; const value3 = true; console.log(isString(value1)); // true console.log(isString(value2)); // false console.log(isString(value3)); // false ``` ##### isUndefined _Import from `@varavel/vdl-plugin-sdk/utils/predicates`._ ```ts function isUndefined(x): x is undefined; ``` Checks if the given value is undefined. This function tests whether the provided value is strictly equal to `undefined`. It returns `true` if the value is `undefined`, and `false` otherwise. This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `x` | `any` | The value to test if it is undefined. | ## Returns `x is undefined` true if the value is undefined, false otherwise. ## Example ```ts const value1 = undefined; const value2 = null; const value3 = 42; console.log(isUndefined(value1)); // true console.log(isUndefined(value2)); // false console.log(isUndefined(value3)); // false ``` ### Codegen import: `@varavel/vdl-plugin-sdk/utils/codegen` _Import from `@varavel/vdl-plugin-sdk/utils/codegen`._ ## Functions - [generateVdl](https://vdl-plugin-sdk.varavel.com/llms/api/utils/codegen/functions/generateVdl.md) ## Type Aliases - [GenerateVdlNode](https://vdl-plugin-sdk.varavel.com/llms/api/utils/codegen/type-aliases/GenerateVdlNode.md) - [GenerateVdlOptions](https://vdl-plugin-sdk.varavel.com/llms/api/utils/codegen/type-aliases/GenerateVdlOptions.md) #### Functions ##### generateVdl _Import from `@varavel/vdl-plugin-sdk/utils/codegen`._ ```ts function generateVdl(node, options?): string; ``` Reconstructs canonical VDL source code from a normalized IR node. Schema generation sorts top-level nodes by it's source position so the emitted document remains close to the original traversal order even though the IR is stored in separate collections. When no position information is available, the code is generated following the IR collection order (docs -\> types -\> enums -\> constants) and the original order of nodes within each collection. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `node` | [`GenerateVdlNode`](https://vdl-plugin-sdk.varavel.com/llms/api/utils/codegen/type-aliases/GenerateVdlNode.md) | Schema or top-level IR node to render. | | `options` | [`GenerateVdlOptions`](https://vdl-plugin-sdk.varavel.com/llms/api/utils/codegen/type-aliases/GenerateVdlOptions.md) | Optional rendering configuration. | ## Returns `string` Valid VDL source for the provided node. #### Type Aliases ##### GenerateVdlNode _Import from `@varavel/vdl-plugin-sdk/utils/codegen`._ ```ts type GenerateVdlNode = | Partial | ConstantDef | EnumDef | TypeDef | TopLevelDoc; ``` Supported VDL IR nodes that can be re-rendered into canonical VDL source. The emitted text is a best-effort reconstruction from normalized IR. It does not restore source features that are intentionally lost during analysis, such as comments, includes, spreads, or reference-based constant values. ##### GenerateVdlOptions _Import from `@varavel/vdl-plugin-sdk/utils/codegen`._ ```ts type GenerateVdlOptions = object; ``` Configures optional behaviors for VDL source reconstruction. ## Properties | Property | Type | Description | | :------ | :------ | :------ | | `docstrings?` | `"preserve"` \| `"strip"` \| `"strip-top-level"` | Controls how docstrings are emitted in the generated VDL source. - `"preserve"` (default): emits all available docstrings. - `"strip"`: omits all docstrings from output. - `"strip-top-level"`: omits only docstrings attached to top-level nodes. | ## Testing import: `@varavel/vdl-plugin-sdk/testing` _Import from `@varavel/vdl-plugin-sdk/testing`._ Build realistic plugin input and IR fixtures for tests with the `irb` helpers. ## Functions - [annotation](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/annotation.md) - [arrayLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/arrayLiteral.md) - [arrayType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/arrayType.md) - [boolLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/boolLiteral.md) - [constantDef](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/constantDef.md) - [enumDef](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/enumDef.md) - [enumMember](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/enumMember.md) - [enumType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/enumType.md) - [field](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/field.md) - [floatLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/floatLiteral.md) - [intLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/intLiteral.md) - [mapType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/mapType.md) - [namedType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/namedType.md) - [objectLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/objectLiteral.md) - [objectType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/objectType.md) - [pluginInput](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/pluginInput.md) - [position](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/position.md) - [primitiveType](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/primitiveType.md) - [schema](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/schema.md) - [stringLiteral](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/stringLiteral.md) - [typeDef](https://vdl-plugin-sdk.varavel.com/llms/api/testing/functions/typeDef.md) ### Functions #### annotation _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function annotation(name, argument?): Annotation; ``` Creates an `Annotation` with the given name and an optional literal argument. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Annotation name without the `@` prefix. | | `argument?` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Optional literal argument attached to the annotation. | ## Returns [`Annotation`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Annotation.md) An `Annotation` with a default position. ## Example ```ts annotation("minLength", intLiteral(3)); // returns an annotation named "minLength" with an int literal argument ``` #### arrayLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function arrayLiteral(items): LiteralValue; ``` Creates an array `LiteralValue` from a list of literal items. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `items` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md)[] | Literal items to include. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) An array literal node. ## Example ```ts arrayLiteral([stringLiteral("a"), stringLiteral("b")]); // returns a LiteralValue with kind "array" ``` #### arrayType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function arrayType(type, dims?): TypeRef; ``` Creates an array `TypeRef` wrapping the given element type. ## Parameters | Parameter | Type | Default value | Description | | :------ | :------ | :------ | :------ | | `type` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | `undefined` | Element type stored inside the array. | | `dims` | `number` | `1` | Number of array dimensions (defaults to 1). | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) An array `TypeRef`. ## Example ```ts arrayType(primitiveType("string"), 2); // returns a two-dimensional array TypeRef ``` #### boolLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function boolLiteral(value): LiteralValue; ``` Creates a boolean `LiteralValue`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `boolean` | Boolean value to store. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) A boolean literal node. ## Example ```ts boolLiteral(true); // returns a LiteralValue with kind "bool" ``` #### constantDef _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function constantDef( name, value, overrides?): ConstantDef; ``` Creates a `ConstantDef` with the given name and literal value. Pass `overrides` to set `annotations` or `doc`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Constant name. | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Constant literal value. | | `overrides` | `Partial`\<`Omit`\<[`ConstantDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md), `"position"` \| `"name"` \| `"annotations"` \| `"value"`\>\> & `object` | Optional constant overrides. | ## Returns [`ConstantDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/ConstantDef.md) A `ConstantDef` with defaults applied. ## Example ```ts constantDef("ApiVersion", stringLiteral("v1")); // returns a constant definition named "ApiVersion" ``` #### enumDef _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function enumDef( name, enumValueType, members, overrides?): EnumDef; ``` Creates an `EnumDef` with the given name, value type, and members. Pass `overrides` to set `annotations` or `doc`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Enum name. | | `enumValueType` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Underlying enum storage type. | | `members` | [`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md)[] | Enum members. | | `overrides` | `Partial`\<`Omit`\<[`EnumDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md), `"position"` \| `"name"` \| `"annotations"` \| `"enumType"` \| `"members"`\>\> & `object` | Optional enum overrides. | ## Returns [`EnumDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumDef.md) An `EnumDef` with defaults applied. ## Example ```ts enumDef("Role", "string", [ enumMember("ADMIN", stringLiteral("admin")), ]); // returns an enum definition named "Role" ``` #### enumMember _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function enumMember( name, value, overrides?): EnumMember; ``` Creates an `EnumMember` with the given name and literal value. Pass `overrides` to set `annotations` or `doc`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Enum member name. | | `value` | [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) | Enum member literal value. | | `overrides` | `Partial`\<`Omit`\<[`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md), `"position"` \| `"name"` \| `"annotations"` \| `"value"`\>\> & `object` | Optional member overrides. | ## Returns [`EnumMember`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumMember.md) An `EnumMember` with defaults applied. ## Example ```ts enumMember("ADMIN", stringLiteral("admin")); // returns an enum member named "ADMIN" ``` #### enumType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function enumType(name, enumType): TypeRef; ``` Creates a `TypeRef` that references a named enum type. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Referenced enum name. | | `enumType` | [`EnumValueType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/EnumValueType.md) | Underlying enum storage type. | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) An enum type reference. ## Example ```ts enumType("Role", "string"); // returns a TypeRef with kind "enum" ``` #### field _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function field( name, typeRef, overrides?): Field; ``` Creates a `Field` with the given name and type. Pass `overrides` to set `optional`, `annotations`, or `doc`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Field name. | | `typeRef` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Field type reference. | | `overrides` | `Partial`\<`Omit`\<[`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md), `"position"` \| `"name"` \| `"annotations"` \| `"optional"` \| `"typeRef"`\>\> & `object` | Optional field overrides. | ## Returns [`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md) A `Field` with defaults applied. ## Example ```ts field("id", primitiveType("string"), { optional: true }); // returns a Field named "id" marked as optional ``` #### floatLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function floatLiteral(value): LiteralValue; ``` Creates a float `LiteralValue`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | Floating-point value to store. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) A float literal node. ## Example ```ts floatLiteral(3.14); // returns a LiteralValue with kind "float" ``` #### intLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function intLiteral(value): LiteralValue; ``` Creates an integer `LiteralValue`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `number` | Integer value to store. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) An integer literal node. ## Example ```ts intLiteral(42); // returns a LiteralValue with kind "int" ``` #### mapType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function mapType(type): TypeRef; ``` Creates a map `TypeRef` whose value type is `type`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `type` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Value type stored in the map. | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) A map `TypeRef`. ## Example ```ts mapType(namedType("User")); // returns a TypeRef with kind "map" ``` #### namedType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function namedType(name): TypeRef; ``` Creates a `TypeRef` that references a named user-defined type. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Referenced type name. | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) A named type reference. ## Example ```ts namedType("User"); // returns a TypeRef with kind "type" ``` #### objectLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function objectLiteral(entries): LiteralValue; ``` Creates an object `LiteralValue` from a plain key/value record. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `entries` | `Record`\<`string`, [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md)\> | Object entries keyed by property name. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) An object literal node. ## Example ```ts objectLiteral({ enabled: boolLiteral(true) }); // returns a LiteralValue with kind "object" ``` #### objectType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function objectType(fields): TypeRef; ``` Creates an inline object `TypeRef` with the given fields. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `fields` | [`Field`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Field.md)[] | Inline object fields. | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) An object `TypeRef`. ## Example ```ts objectType([field("id", primitiveType("string"))]); // returns a TypeRef with kind "object" ``` #### pluginInput _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function pluginInput(overrides?): PluginInput; ``` Creates a `PluginInput` with a default version, empty options, and an empty schema. Pass `overrides` to customize any field. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `overrides` | `Partial`\<[`PluginInput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md)\> | Plugin input fields to override. | ## Returns [`PluginInput`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PluginInput.md) A ready-to-use `PluginInput` for tests. ## Example ```ts pluginInput({ options: { prefix: "Api" }, }); // returns a PluginInput with default version and schema ``` #### position _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function position(overrides?): Position; ``` Creates a `Position` with sensible defaults. Pass `overrides` to customize specific fields. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `overrides` | `Partial`\<[`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md)\> | Position fields to override. | ## Returns [`Position`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/Position.md) A fully populated `Position`. ## Example ```ts position({ file: "user.vdl", line: 10 }); // returns { file: "user.vdl", line: 10, column: 1 } ``` #### primitiveType _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function primitiveType(name): TypeRef; ``` Creates a primitive `TypeRef` (e.g. `string`, `int`, `bool`). ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | [`PrimitiveType`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/PrimitiveType.md) | Primitive type name. | ## Returns [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) A primitive `TypeRef`. ## Example ```ts primitiveType("string"); // returns a TypeRef with kind "primitive" ``` #### schema _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function schema(overrides?): IrSchema; ``` Creates an `IrSchema` with empty collections. Pass `overrides` to populate `constants`, `enums`, `types`, or `docs`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `overrides` | `Partial`\<[`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md)\> | Schema fields to override. | ## Returns [`IrSchema`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/IrSchema.md) An `IrSchema` with sensible defaults. ## Example ```ts schema({ types: [typeDef("UserId", primitiveType("string"))], }); // returns a schema containing one typedef ``` #### stringLiteral _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function stringLiteral(value): LiteralValue; ``` Creates a string `LiteralValue`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `value` | `string` | String content to store. | ## Returns [`LiteralValue`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/LiteralValue.md) A string literal node. ## Example ```ts stringLiteral("hello"); // returns a LiteralValue with kind "string" ``` #### typeDef _Import from `@varavel/vdl-plugin-sdk/testing`._ ```ts function typeDef( name, typeRef, overrides?): TypeDef; ``` Creates a `TypeDef` with the given name and underlying type. Pass `overrides` to set `annotations` or `doc`. ## Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | `name` | `string` | Type definition name. | | `typeRef` | [`TypeRef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeRef.md) | Underlying type reference. | | `overrides` | `Partial`\<`Omit`\<[`TypeDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md), `"position"` \| `"name"` \| `"annotations"` \| `"typeRef"`\>\> & `object` | Optional typedef overrides. | ## Returns [`TypeDef`](https://vdl-plugin-sdk.varavel.com/llms/api/core/type-aliases/TypeDef.md) A `TypeDef` with defaults applied. ## Example ```ts typeDef("UserId", primitiveType("string")); // returns a typedef named "UserId" ```