Skip to main content
Home

Built and signed on GitHub Actions

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a week ago (1.39.7)
function ary
ary(
func: (...args: any[]) => any,
n?: number,
): (...args: any[]) => any

Creates a function that invokes func, with up to n arguments, ignoring any additional arguments. If n is not provided, it defaults to the function's length.

Examples

function fn(a: number, b: number, c: number) { return Array.from(arguments); }

// Cap at 2 arguments const capped = ary(fn, 2); capped(1, 2, 3); // [1, 2]

// Default to function length const defaultCap = ary(fn); defaultCap(1, 2, 3); // [1, 2, 3]

Parameters

func: (...args: any[]) => any
  • The function to cap arguments for.
optional
n: number
  • The arity cap. Defaults to func.length.

Return Type

(...args: any[]) => any

Returns the new capped function.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";
or

Import directly with a jsr specifier

import { ary } from "jsr:@es-toolkit/es-toolkit/compat";

Add Package

pnpm i jsr:@es-toolkit/es-toolkit
or (using pnpm 10.8 or older)
pnpm dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";

Add Package

yarn add jsr:@es-toolkit/es-toolkit
or (using Yarn 4.8 or older)
yarn dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";

Add Package

vlt install jsr:@es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";

Add Package

npx jsr add @es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";

Add Package

bunx jsr add @es-toolkit/es-toolkit

Import symbol

import { ary } from "@es-toolkit/es-toolkit/compat";