Skip to content

feat[Queue]: add Queue to es-toolkit/util - #2150

Merged
raon0211 merged 4 commits into
mainfrom
feat/queue
Oct 23, 2026
Merged

raon0211 merged 4 commits into
mainfrom
feat/queue

Conversation

@raon0211

@raon0211 raon0211 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds Queue, a FIFO queue where enqueue and dequeue run in constant time. Taking items off the front with Array.prototype.shift gets slower as the array grows.

Changes

  • Add Queue to es-toolkit/util with enqueue, dequeue, peek, clear, and a size getter.
  • Make Queue iterable with Symbol.iterator, going from front to back without removing items.
  • Add tests, benchmarks, a bundle size test, and docs in all four languages.

Benchmark results

10,000 items enqueued, then dequeued until empty:

name                     hz     mean
es-toolkit/Queue  13,407.96   0.0746
yocto-queue        9,353.56   0.1069
Array#push/shift   1,749.43   0.5716

es-toolkit/Queue  1.43x faster than yocto-queue
                  7.66x faster than Array#push/shift

Iterating over 10,000 items:

name                    hz     mean
es-toolkit/Queue  6,877.78   0.1454
yocto-queue       6,401.15   0.1562

es-toolkit/Queue  1.07x faster than yocto-queue

Bundle size

Minified, in bytes:

Library Size
es-toolkit 458
yocto-queue 543

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Oct 23, 2026 1:56am UTC

Request Review

T3 Code Service User and others added 2 commits October 23, 2026 01:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-queue

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raon0211
raon0211 marked this pull request as ready for review October 23, 2026 01:52
@raon0211
raon0211 requested a review from dayongkr as a code owner October 23, 2026 01:52
@raon0211
raon0211 merged commit 07fd8f9 into main Oct 23, 2026
11 of 12 checks passed
raon0211 pushed a commit that referenced this pull request Oct 23, 2026
`Queue` (#2150) has no runnable `@example`, so the Node check in the
browser-compat workflow failed with "1 exports have no test case", which
then left the WebKit lane waiting on a fixture that was never built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raon0211 added a commit that referenced this pull request Oct 23, 2026
* feat(compat): support Node.js 6+ in es-toolkit/compat

es-toolkit/compat exists to migrate lodash code, which often still runs in old
environments. Make it work on Node.js 6 as published, with no transpilation and
no polyfills, and keep it that way.

- Restrict src/compat/** to ES2015 syntax and built-ins: rewrite optional
  chaining, nullish coalescing, object spread, Object.hasOwn, Object.values,
  Array#flat/flatMap/at/findLast(Index), String#matchAll/trimStart/trimEnd.
- words: fall back to lodash's ES5 word patterns when the engine cannot compile
  the Unicode-property regex, so camelCase and friends work on Node.js 6.
- truncate: drop the named capture group (Node.js 10+ only).
- isNative: use the internal globalThis shim instead of the bare global.
- cloneDeepWith: give compat its own implementation instead of delegating to
  the main library's, which relies on structuredClone.
- Fix the few main-library files compat imports (groupBy, pull, remove,
  isEqualWith, clone, deburr, trimStart, trimEnd, debounce) and stop invokeMap
  from importing the whole predicate barrel.
- ESLint: es-x + eslint-plugin-compat with a Node.js 6 target on src/compat.
- CI: new compat-node6 job runs the built package on a real Node.js 6
  (entry points + every compat @example case) on every change.
- Docs: Node.js support section in browser-support (en/ko/ja/zh_hans).

* test: update bundle size snapshots

* fix(trimStart, trimEnd): drop the whitespace regex flagged by CodeQL

`str.replace(/\s+$/, '')` is quadratic on inputs with a long run of
whitespace followed by a non-whitespace character. Scan from the edges
with a per-character `\s` test instead, which is linear and still
ES2015-compatible. The compat variants delegate to the main
implementations instead of carrying their own regex.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(compat/groupBy): avoid Object.hasOwn for Node.js 6

compat's groupBy has its own implementation since #2122, so the main-library
groupBy is no longer in compat's dependency graph. Revert it to main and drop
Object.hasOwn from compat's groupBy instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: update bundle size snapshots

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* build: upgrade tsdown and lower published code to ES2019 syntax

Lowering `?.` and `??` at build time lets the source keep using them
while `es-toolkit/compat` still loads on ES2015 engines such as Node.js 6.
Oxc cannot lower individual syntax features yet
(oxc-project/oxc#15373), so the whole output
targets ES2019.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(compat): keep the main library untouched for Node.js 6 support

- Revert the main-library changes; compat now has ES2015 copies of the
  pieces it needs (`basePull`, `baseIsEqualWith`, `baseClone`, and local
  `remove`/`trimStart`/`trimEnd` implementations), plus its own `isEqual`.
- Allow `?.` and `??` in compat again, since the build lowers them.
- Add `hasOwn` and `objectValues` helpers instead of repeating
  `hasOwnProperty.call` and `Object.keys(...).map(...)`.
- Merge `legacyWords` into `compat/_internal/words.ts`.
- Use array spread in `cloneDeepWith`'s `copyProperties`; `concat` made
  deep clones of objects 8-21% slower than before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: move compat environment support to its own page

Add a "Browser & Node.js Support" page under /compat in all four
languages, and link to it from the main Browser Support page instead of
merging the content there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(browser-compat): add a manual case for Queue

`Queue` (#2150) has no runnable `@example`, so the Node check in the
browser-compat workflow failed with "1 exports have no test case", which
then left the WebKit lane waiting on a fixture that was never built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(compat/words): always split words with lodash's patterns

The Unicode-property pattern only approximated lodash and still disagreed
on inputs such as `ПриветМир`, `foo©bar`, `foo™bar`, `DžDž`, and
mathematical letters, while lodash's own patterns match lodash exactly
and already run on every engine, including Node.js 6. Using them
everywhere removes the second implementation, makes non-ASCII input about
1.5x faster, and shrinks compat `camelCase` from 4,410 to 3,448 bytes.

* docs: name es-toolkit/compat in the environment support link

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: T3 Code Service User <t3code@raonserver-t3code.Maxio>

This branch was successfully deployed

1 active deployment
Preview — e54764e6 Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant